~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_mediaplayer.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
#!/usr/bin/env python
 
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
import os
 
9
import time
 
10
 
 
11
from gi.repository import Unity, GObject
 
12
 
 
13
from testtools.matchers import Equals, GreaterThan, NotEquals
 
14
from testtools import skipUnless
 
15
 
 
16
from autopilot import platform
 
17
from autopilot.matchers import Eventually
 
18
 
 
19
from unity.emulators import ensure_unity_is_running
 
20
 
 
21
from unity_webapps_qml.tests import UnityWebappsTestCaseBase
 
22
 
 
23
 
 
24
class UnityWebappsMediaplayerTestCase(UnityWebappsTestCaseBase):
 
25
    LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_mediaplayer.html')
 
26
    INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_mediaplayer.html'
 
27
 
 
28
    def get_html_test_file(self):
 
29
        if os.path.exists(self.LOCAL_HTML_TEST_FILE):
 
30
            return os.path.abspath(self.LOCAL_HTML_TEST_FILE)
 
31
        return self.INSTALLED_HTML_TEST_FILE
 
32
 
 
33
    def setUp(self):
 
34
        super(UnityWebappsMediaplayerTestCase, self).setUp()
 
35
        # On Touch the dbus unity if does is not exposed
 
36
        if platform.model() == 'Desktop':
 
37
            ensure_unity_is_running()
 
38
        self.launch_with_html_filepath(self.get_html_test_file())
 
39
 
 
40
    @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
 
41
    def test_checkInitialSetTrack(self):
 
42
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
 
43
 
 
44
        expr = """
 
45
           document.addEventListener('unity-webapps-do-call-response', function(e) {
 
46
                var response = e.detail;
 
47
                document.getElementById('status').innerHTML = '' + e.detail;
 
48
           });
 
49
 
 
50
           var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['track']})});
 
51
           document.dispatchEvent (e);
 
52
           return true;
 
53
        """
 
54
        self.eval_expression_in_page_unsafe(expr)
 
55
 
 
56
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('TXlBcnRpc3Q=;TXlUaXRsZQ==;TXlBbGJ1bQ==')))
 
57
 
 
58
    @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
 
59
    def test_checkInitialSetCanGoNext(self):
 
60
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
 
61
 
 
62
        expr = """
 
63
           document.addEventListener('unity-webapps-do-call-response', function(e) {
 
64
                var response = e.detail;
 
65
                document.getElementById('status').innerHTML = '' + e.detail;
 
66
           });
 
67
 
 
68
           var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-next']})});
 
69
           document.dispatchEvent (e);
 
70
           return true;
 
71
        """
 
72
        self.eval_expression_in_page_unsafe(expr)
 
73
 
 
74
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
 
75
 
 
76
    @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
 
77
    def test_checkInitialSetCanGoPrevious(self):
 
78
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
 
79
 
 
80
        expr = """
 
81
           document.addEventListener('unity-webapps-do-call-response', function(e) {
 
82
                var response = e.detail;
 
83
                document.getElementById('status').innerHTML = '' + e.detail;
 
84
           });
 
85
 
 
86
           var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-previous']})});
 
87
           document.dispatchEvent (e);
 
88
           return true;
 
89
        """
 
90
        self.eval_expression_in_page_unsafe(expr)
 
91
 
 
92
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
 
93
 
 
94
    @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
 
95
    def test_checkInitialSetCanPlay(self):
 
96
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
 
97
 
 
98
        expr = """
 
99
           document.addEventListener('unity-webapps-do-call-response', function(e) {
 
100
                var response = e.detail;
 
101
                document.getElementById('status').innerHTML = '' + e.detail;
 
102
           });
 
103
 
 
104
           var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-play']})});
 
105
           document.dispatchEvent (e);
 
106
           return true;
 
107
        """
 
108
        self.eval_expression_in_page_unsafe(expr)
 
109
 
 
110
        self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
 
111