~abreu-alexandre/unity-webapps-qml/location-specific-homepage

« back to all changes in this revision

Viewing changes to tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py

  • Committer: CI bot
  • Author(s): Alexandre Abreu
  • Date: 2014-11-22 00:47:15 UTC
  • mfrom: (135.1.1 latest)
  • Revision ID: ps-jenkins@lists.canonical.com-20141122004715-r8ae4r6ih5ktx280
Port qml bindings to oxide Fixes: #1374100

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
from __future__ import absolute_import
9
9
 
10
 
import time
11
10
import os
12
11
 
13
 
from testtools.matchers import Equals, GreaterThan, NotEquals
 
12
from testtools.matchers import Equals
14
13
from autopilot.matchers import Eventually
15
14
 
16
15
from unity_webapps_qml.tests import UnityWebappsTestCaseBase
17
16
 
 
17
LOCAL_HTML_TEST_FILE = "{}/{}".format(
 
18
    os.path.dirname(os.path.realpath(__file__)),
 
19
    '../../html/test_webapps_api_injected.html')
 
20
 
 
21
INSTALLED_HTML_TEST_FILE = \
 
22
    '/usr/share/unity-webapps-qml/' \
 
23
    'autopilot-tests/html/test_webapps_api_injected.html'
 
24
 
 
25
 
18
26
class UnityWebappsApiInjectedTestCaseBase(UnityWebappsTestCaseBase):
19
 
    LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_api_injected.html')
20
 
 
21
 
    INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_api_injected.html'
22
 
 
23
27
    def get_html_test_file(self):
24
 
        if os.path.exists(self.LOCAL_HTML_TEST_FILE):
25
 
            return os.path.abspath(self.LOCAL_HTML_TEST_FILE)
26
 
        return self.INSTALLED_HTML_TEST_FILE
 
28
        if os.path.exists(LOCAL_HTML_TEST_FILE):
 
29
            return os.path.abspath(LOCAL_HTML_TEST_FILE)
 
30
        return INSTALLED_HTML_TEST_FILE
27
31
 
28
32
    def setUp(self):
29
33
        super(UnityWebappsApiInjectedTestCaseBase, self).setUp()
30
34
        self.launch_with_html_filepath(self.get_html_test_file())
31
35
 
32
36
    def test_getUnityObjectFound(self):
33
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null'), Eventually(Equals(True)))
 
37
        self.assertThat(
 
38
            lambda: self.eval_expression_in_page_unsafe(
 
39
                'return window.external.getUnityObject("1.0") != null'),
 
40
            Eventually(Equals(True)))
34
41
 
35
42
    def test_actionsApiFound(self):
36
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
43
        self.assertThat(
 
44
            lambda: self.eval_expression_in_page_unsafe(
 
45
                'return window.external.getUnityObject("1.0") != null;'),
 
46
            Eventually(Equals(True)))
37
47
 
38
48
        expression = """
39
49
            var unity = window.external.getUnityObject("1.0");
40
 
            return unity.addAction != null && unity.clearActions != null && unity.clearAction != null;
 
50
            return unity.addAction != null &&
 
51
                   unity.clearActions != null &&
 
52
                   unity.clearAction != null;
41
53
        """
42
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))
 
54
        self.assertThat(
 
55
            lambda: self.eval_expression_in_page_unsafe(expression),
 
56
            Eventually(Equals(True)))
43
57
 
44
58
    def test_notificationApiFound(self):
45
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
59
        self.assertThat(
 
60
            lambda: self.eval_expression_in_page_unsafe(
 
61
                'return window.external.getUnityObject("1.0") != null;'),
 
62
            Eventually(Equals(True)))
46
63
 
47
64
        expression = """
48
65
            var unity = window.external.getUnityObject("1.0");
49
 
            return unity.Notification != null && unity.Notification.showNotification != null;
 
66
            return unity.Notification != null &&
 
67
                   unity.Notification.showNotification != null;
50
68
        """
51
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))
 
69
        self.assertThat(
 
70
            lambda: self.eval_expression_in_page_unsafe(expression),
 
71
            Eventually(Equals(True)))
52
72
 
53
73
    def test_messagingIndicatorApiFound(self):
54
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
74
        self.assertThat(
 
75
            lambda: self.eval_expression_in_page_unsafe(
 
76
                'return window.external.getUnityObject("1.0") != null;'),
 
77
            Eventually(Equals(True)))
55
78
 
56
79
        expression = """
57
80
            var unity = window.external.getUnityObject("1.0");
61
84
                unity.MessagingIndicator.clearIndicators != null &&
62
85
                unity.MessagingIndicator.showIndicator != null;
63
86
        """
64
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))
 
87
        self.assertThat(
 
88
            lambda: self.eval_expression_in_page_unsafe(expression),
 
89
            Eventually(Equals(True)))
65
90
 
66
91
    def test_ubuntuReadyEventSent(self):
67
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
92
        self.assertThat(
 
93
            lambda: self.eval_expression_in_page_unsafe(
 
94
                'return window.external.getUnityObject("1.0") != null;'),
 
95
            Eventually(Equals(True)))
68
96
 
69
97
        expression = """
70
 
            var api_ready_count = window.localStorage['ubuntu-webapps-api-ready-key'];
 
98
            var api_ready_count =
 
99
                window.localStorage['ubuntu-webapps-api-ready-key'];
71
100
            return api_ready_count != null && api_ready_count > 0;
72
101
        """
73
 
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))
74
 
 
75
 
 
 
102
        self.assertThat(
 
103
            lambda: self.eval_expression_in_page_unsafe(expression),
 
104
            Eventually(Equals(True)))