1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 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
from __future__ import absolute_import
13
from testtools.matchers import Equals, GreaterThan, NotEquals
14
from autopilot.matchers import Eventually
16
from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase
18
LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../data')
19
INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/data'
21
class InstalledWebappsTestCaseBase(WebappsTestCaseBaseWithLocalHttpContentBase):
23
super(InstalledWebappsTestCaseBase, self).setUp()
25
def get_webapp_install_folder(self):
26
if os.path.exists(LOCAL_HTML_TEST_FILE):
27
return os.path.abspath(LOCAL_HTML_TEST_FILE)
28
return INSTALLED_HTML_TEST_FILE
30
def test_normalWebappFound(self):
31
self.launch_with_webapp('Normal', self.get_webapp_install_folder())
33
self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
36
var contentElement = document.getElementById('content');
37
return contentElement.innerHTML;
39
self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))
41
def test_webappWithUAOverrideFound(self):
42
self.launch_with_webapp('AlteredUAWebapp', self.get_webapp_install_folder(), True)
43
self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override")))
45
def test_webappFoundWithSpecialWebappPropertiesFile(self):
46
self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder')
48
self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
51
var contentElement = document.getElementById('content');
52
return contentElement.innerHTML;
54
self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))
56
def test_webappPropertiesFileWithUA(self):
57
self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder', True)
58
self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override")))