2
# Copyright 2013 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.
11
from gi.repository import Unity, GObject
13
from testtools.matchers import Equals, GreaterThan, NotEquals
14
from testtools import skipUnless
16
from autopilot import platform
17
from autopilot.matchers import Eventually
19
from unity.emulators import ensure_unity_is_running
21
from unity_webapps_qml.tests import UnityWebappsTestCaseBase
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'
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
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())
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')))
45
document.addEventListener('unity-webapps-do-call-response', function(e) {
46
var response = e.detail;
47
document.getElementById('status').innerHTML = '' + e.detail;
50
var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['track']})});
51
document.dispatchEvent (e);
54
self.eval_expression_in_page_unsafe(expr)
56
self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('TXlBcnRpc3Q=;TXlUaXRsZQ==;TXlBbGJ1bQ==')))
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')))
63
document.addEventListener('unity-webapps-do-call-response', function(e) {
64
var response = e.detail;
65
document.getElementById('status').innerHTML = '' + e.detail;
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);
72
self.eval_expression_in_page_unsafe(expr)
74
self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
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')))
81
document.addEventListener('unity-webapps-do-call-response', function(e) {
82
var response = e.detail;
83
document.getElementById('status').innerHTML = '' + e.detail;
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);
90
self.eval_expression_in_page_unsafe(expr)
92
self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
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')))
99
document.addEventListener('unity-webapps-do-call-response', function(e) {
100
var response = e.detail;
101
document.getElementById('status').innerHTML = '' + e.detail;
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);
108
self.eval_expression_in_page_unsafe(expr)
110
self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))