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
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 UnityWebappsTestCaseBase
18
LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch.html')
19
INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch.html'
21
LOCAL_JS_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch_api.js')
22
INSTALLED_JS_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch_api.js'
24
LOCAL_QML_BACKEND_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../qml/test_webapps_callback_dispatch_api.qml')
25
INSTALLED_QML_BACKEND_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/qml/test_webapps_callback_dispatch_api.qml'
27
class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase):
29
super(WebappsCallbackDispatchTestCaseBase, self).setUp()
30
self.launch_with_html_filepath(
31
self.get_html_test_file(),
32
['--clientApiFileUrl=file://' + self.get_js_test_file(),
33
'--apiBackendQmlFileUrl=file://' + self.get_qml_test_file()])
35
def get_html_test_file(self):
36
if os.path.exists(LOCAL_HTML_TEST_FILE):
37
return os.path.abspath(LOCAL_HTML_TEST_FILE)
38
return INSTALLED_HTML_TEST_FILE
40
def get_js_test_file(self):
41
if os.path.exists(LOCAL_JS_TEST_FILE):
42
return os.path.abspath(LOCAL_JS_TEST_FILE)
43
return INSTALLED_JS_TEST_FILE
45
def get_qml_test_file(self):
46
print LOCAL_QML_BACKEND_TEST_FILE
47
if os.path.exists(LOCAL_QML_BACKEND_TEST_FILE):
48
return os.path.abspath(LOCAL_QML_BACKEND_TEST_FILE)
49
return INSTALLED_QML_BACKEND_TEST_FILE
51
def test_bidirectionalCallback(self):
53
lambda: self.eval_expression_in_page_unsafe(
54
'return window.external.getUnityObject("1.0") != null;'),
55
Eventually(Equals(True)))
58
lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').innerHTML;"),
59
Eventually(Equals('callback-loop-count-reached')))