~ubuntu-branches/ubuntu/vivid/unity-webapps-qml/vivid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Alexandre Abreu
  • Date: 2014-07-18 17:40:27 UTC
  • mfrom: (1.1.35)
  • Revision ID: package-import@ubuntu.com-20140718174027-ib7s8vyk5gzpla4u
Tags: 0.1+14.10.20140718.1-0ubuntu1
[ Alexandre Abreu ]
Add bidirectional callback support between js <-> qml,

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 2013 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
from __future__ import absolute_import
 
9
 
 
10
import time
 
11
import os
 
12
 
 
13
from testtools.matchers import Equals, GreaterThan, NotEquals
 
14
from autopilot.matchers import Eventually
 
15
 
 
16
from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase
 
17
 
 
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'
 
20
 
 
21
class InstalledWebappsTestCaseBase(WebappsTestCaseBaseWithLocalHttpContentBase):
 
22
    def setUp(self):
 
23
        super(InstalledWebappsTestCaseBase, self).setUp()
 
24
 
 
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
 
29
 
 
30
    def test_normalWebappFound(self):
 
31
        self.launch_with_webapp('Normal', self.get_webapp_install_folder())
 
32
 
 
33
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
34
 
 
35
        expression = """
 
36
            var contentElement = document.getElementById('content');
 
37
            return contentElement.innerHTML;
 
38
        """
 
39
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))
 
40
 
 
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")))
 
44
 
 
45
    def test_webappFoundWithSpecialWebappPropertiesFile(self):
 
46
        self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder')
 
47
 
 
48
        self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))
 
49
 
 
50
        expression = """
 
51
            var contentElement = document.getElementById('content');
 
52
            return contentElement.innerHTML;
 
53
        """
 
54
        self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))
 
55
 
 
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")))
 
59