1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2014 Canonical
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.
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.
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/>.
16
""" Autopilot tests for the webapp_container package """
21
from autopilot.testcase import AutopilotTestCase
22
from autopilot.platform import model
24
from ubuntuuitoolkit import emulators as toolkit_emulators
25
from webapp_container.tests import fake_servers
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'
31
INSTALLED_BROWSER_CONTAINER_PATH_NAME = subprocess.check_output(
32
['which', 'webapp-container']).strip()
33
except subprocess.CalledProcessError:
36
LOCAL_BROWSER_CONTAINER_PATH_NAME = "%s/%s" % (BASE_FILE_PATH,
37
CONTAINER_EXEC_REL_PATH)
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
46
def launch_webcontainer_app(self, args):
47
if model() != 'Desktop':
49
'--desktop_file_hint=/usr/share/applications/'
50
'webbrowser-app.desktop')
52
self.app = self.launch_test_application(
53
self.get_webcontainer_app_path(),
55
emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
59
def get_webcontainer_proxy(self):
62
def get_webcontainer_window(self):
63
return self.app.select_single(objectName="webappContainer")
65
def get_webcontainer_webview(self):
66
return self.app.select_single(objectName="webappBrowserView")
68
def get_webcontainer_panel(self):
69
return self.app.select_single(objectName="panel")
72
class WebappContainerTestCaseWithLocalContentBase(WebappContainerTestCaseBase):
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
79
def launch_webcontainer_app_with_local_http_server(self, args, path='/'):
80
self.url = self.base_url + path
82
self.launch_webcontainer_app(args)