OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>MediaSession Mojo Test</title> | 2 <title>MediaSession Mojo Test</title> |
3 <script src="../../../resources/testharness.js"></script> | 3 <script src="../../../resources/testharness.js"></script> |
4 <script src="../../../resources/testharnessreport.js"></script> | 4 <script src="../../../resources/testharnessreport.js"></script> |
5 <script src="../../../resources/mojo-helpers.js"></script> | 5 <script src="../../../resources/mojo-helpers.js"></script> |
6 <script src="resources/mediasessionservice-mock.js"></script> | 6 <script src="resources/mediasessionservice-mock.js"></script> |
7 <script src="resources/utils.js"></script> | 7 <script src="resources/utils.js"></script> |
8 <script> | 8 <script> |
9 | 9 |
10 var mock; | 10 var mock; |
11 | 11 |
12 var expectations = [ | 12 var expectations = [ |
13 "play", | 13 "play", |
14 "pause", | 14 "pause", |
15 "previoustrack", | 15 "previoustrack", |
16 "nexttrack", | 16 "nexttrack", |
17 "seekbackward", | 17 "seekbackward", |
18 "seekforward", | 18 "seekforward", |
19 ]; | 19 ]; |
20 | 20 |
21 var nextExpectation = 0; | 21 var nextExpectation = 0; |
22 | 22 |
23 function checkExpectation(t, event) { | 23 function checkExpectation(t, action) { |
24 var expectedEvent = expectations[nextExpectation]; | 24 var expectedEvent = expectations[nextExpectation]; |
25 assert_equals(expectedEvent, event.type); | 25 assert_equals(expectedEvent, action); |
26 if (++nextExpectation >= expectations.length) | 26 if (++nextExpectation >= expectations.length) |
27 t.done(); | 27 t.done(); |
28 } | 28 } |
29 | 29 |
30 function runTests(t) { | 30 function runTests(t) { |
31 window.navigator.mediaSession.onplay = t.step_func(checkExpectation.bind(null,
t)); | 31 window.navigator.mediaSession.setActionHandler( |
32 window.navigator.mediaSession.onpause = t.step_func(checkExpectation.bind(null
, t)); | 32 "play", t.step_func(checkExpectation.bind(null, t, "play"))); |
33 window.navigator.mediaSession.onprevioustrack = t.step_func(checkExpectation.b
ind(null, t)); | 33 window.navigator.mediaSession.setActionHandler( |
34 window.navigator.mediaSession.onnexttrack = t.step_func(checkExpectation.bind(
null, t)); | 34 "pause", t.step_func(checkExpectation.bind(null, t, "pause"))); |
35 window.navigator.mediaSession.onseekforward = t.step_func(checkExpectation.bin
d(null, t)); | 35 window.navigator.mediaSession.setActionHandler( |
36 window.navigator.mediaSession.onseekbackward = t.step_func(checkExpectation.bi
nd(null, t)); | 36 "previoustrack", t.step_func(checkExpectation.bind(null, t, "previoustrack
"))); |
| 37 window.navigator.mediaSession.setActionHandler( |
| 38 "nexttrack", t.step_func(checkExpectation.bind(null, t, "nexttrack"))); |
| 39 window.navigator.mediaSession.setActionHandler( |
| 40 "seekbackward", t.step_func(checkExpectation.bind(null, t, "seekbackward")
)); |
| 41 window.navigator.mediaSession.setActionHandler( |
| 42 "seekforward", t.step_func(checkExpectation.bind(null, t, "seekforward")))
; |
37 | 43 |
38 mock.getClient().didReceiveAction(MediaSessionAction.PLAY); | 44 mock.getClient().didReceiveAction(MediaSessionAction.PLAY); |
39 mock.getClient().didReceiveAction(MediaSessionAction.PAUSE); | 45 mock.getClient().didReceiveAction(MediaSessionAction.PAUSE); |
40 mock.getClient().didReceiveAction(MediaSessionAction.PREVIOUS_TRACK); | 46 mock.getClient().didReceiveAction(MediaSessionAction.PREVIOUS_TRACK); |
41 mock.getClient().didReceiveAction(MediaSessionAction.NEXT_TRACK); | 47 mock.getClient().didReceiveAction(MediaSessionAction.NEXT_TRACK); |
42 mock.getClient().didReceiveAction(MediaSessionAction.SEEK_BACKWARD); | 48 mock.getClient().didReceiveAction(MediaSessionAction.SEEK_BACKWARD); |
43 mock.getClient().didReceiveAction(MediaSessionAction.SEEK_FORWARD); | 49 mock.getClient().didReceiveAction(MediaSessionAction.SEEK_FORWARD); |
44 } | 50 } |
45 | 51 |
46 // Use async_test to do asynchronous setup since setup() only works for | 52 // Use async_test to do asynchronous setup since setup() only works for |
47 // synchronous setup. | 53 // synchronous setup. |
48 async_test(function(t) { | 54 async_test(function(t) { |
49 mediaSessionServiceMock.then(m => { | 55 mediaSessionServiceMock.then(m => { |
50 mock = m; | 56 mock = m; |
51 mock.setClientCallback(t.step_func(runTests.bind(null, t))); | 57 mock.setClientCallback(t.step_func(runTests.bind(null, t))); |
52 // Touch window.navigator.mediaSession to start the service. | 58 // Touch window.navigator.mediaSession to start the service. |
53 window.navigator.mediaSession.metadata = null; | 59 window.navigator.mediaSession.metadata = null; |
54 }); | 60 }); |
55 }, "test that the mock service is setup"); | 61 }, "test that the mock service is setup"); |
56 | 62 |
57 </script> | 63 </script> |
OLD | NEW |