~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_callbackDispatch.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 2014 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 UnityWebappsTestCaseBase
 
17
 
 
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'
 
20
 
 
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'
 
23
 
 
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'
 
26
 
 
27
class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase):
 
28
    def setUp(self):
 
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()])
 
34
 
 
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
 
39
 
 
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
 
44
 
 
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
 
50
 
 
51
    def test_bidirectionalCallback(self):
 
52
        self.assertThat(
 
53
            lambda: self.eval_expression_in_page_unsafe(
 
54
                'return window.external.getUnityObject("1.0") != null;'),
 
55
            Eventually(Equals(True)))
 
56
 
 
57
        self.assertThat(
 
58
            lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').innerHTML;"),
 
59
            Eventually(Equals('callback-loop-count-reached')))
 
60