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