~abreu-alexandre/webbrowser-app/fix-popup-url-redirection

« back to all changes in this revision

Viewing changes to tests/autopilot/webapp_container/tests/__init__.py

Add a basic set of integration tests for the webapp container 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2014 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License version 3, as published
 
6
# by the Free Software Foundation.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
""" Autopilot tests for the webapp_container package """
 
17
 
 
18
import os
 
19
import subprocess
 
20
 
 
21
from autopilot.testcase import AutopilotTestCase
 
22
from autopilot.platform import model
 
23
 
 
24
from ubuntuuitoolkit import emulators as toolkit_emulators
 
25
from webapp_container.tests import fake_servers
 
26
 
 
27
BASE_FILE_PATH = os.path.dirname(os.path.realpath(__file__))
 
28
CONTAINER_EXEC_REL_PATH = '../../../../src/app/webcontainer/webapp-container'
 
29
INSTALLED_BROWSER_CONTAINER_PATH_NAME = 'webapp-container'
 
30
try:
 
31
    INSTALLED_BROWSER_CONTAINER_PATH_NAME = subprocess.check_output(
 
32
        ['which', 'webapp-container']).strip()
 
33
except subprocess.CalledProcessError:
 
34
    pass
 
35
 
 
36
LOCAL_BROWSER_CONTAINER_PATH_NAME = "%s/%s" % (BASE_FILE_PATH,
 
37
                                               CONTAINER_EXEC_REL_PATH)
 
38
 
 
39
 
 
40
class WebappContainerTestCaseBase(AutopilotTestCase):
 
41
    def get_webcontainer_app_path(self):
 
42
        if os.path.exists(LOCAL_BROWSER_CONTAINER_PATH_NAME):
 
43
            return LOCAL_BROWSER_CONTAINER_PATH_NAME
 
44
        return INSTALLED_BROWSER_CONTAINER_PATH_NAME
 
45
 
 
46
    def launch_webcontainer_app(self, args):
 
47
        if model() != 'Desktop':
 
48
            args.append(
 
49
                '--desktop_file_hint=/usr/share/applications/'
 
50
                'webbrowser-app.desktop')
 
51
        try:
 
52
            self.app = self.launch_test_application(
 
53
                self.get_webcontainer_app_path(),
 
54
                *args,
 
55
                emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
 
56
        except:
 
57
            self.app = None
 
58
 
 
59
    def get_webcontainer_proxy(self):
 
60
        return self.app
 
61
 
 
62
    def get_webcontainer_window(self):
 
63
        return self.app.select_single(objectName="webappContainer")
 
64
 
 
65
    def get_webcontainer_webview(self):
 
66
        return self.app.select_single(objectName="webappBrowserView")
 
67
 
 
68
    def get_webcontainer_panel(self):
 
69
        return self.app.select_single(objectName="panel")
 
70
 
 
71
 
 
72
class WebappContainerTestCaseWithLocalContentBase(WebappContainerTestCaseBase):
 
73
    def setUp(self):
 
74
        super(WebappContainerTestCaseWithLocalContentBase, self).setUp()
 
75
        self.http_server = fake_servers.WebappContainerContentHttpServer()
 
76
        self.addCleanup(self.http_server.shutdown)
 
77
        self.base_url = "http://localhost:%d" % self.http_server.port
 
78
 
 
79
    def launch_webcontainer_app_with_local_http_server(self, args, path='/'):
 
80
        self.url = self.base_url + path
 
81
        args.append(self.url)
 
82
        self.launch_webcontainer_app(args)