5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
11 SimpleTest
.waitForExplicitFinish();
27 (async
function testSetActionHandler() {
28 for (const action
of ACTIONS
) {
29 info(`Test setActionHandler for '${action}'`);
30 generateAction(action
);
31 ok(true, "it's ok to do " + action
+ " without any handler");
33 let expectedDetails
= generateActionDetails(action
);
36 await
setHandlerAndTakeAction(action
, details
=> {
37 ok(hasSameValue(details
, expectedDetails
), "get expected details for " + action
);
39 clearActionHandler(action
);
42 generateAction(action
);
43 ok(fired
, "handler of " + action
+ " is cleared");
49 function generateAction(action
) {
50 let details
= generateActionDetails(action
);
51 SpecialPowers
.wrap(navigator
.mediaSession
).notifyHandler(details
);
54 function generateActionDetails(action
) {
55 let details
= { action
};
56 if (action
== "seekbackward" || action
== "seekforward") {
57 details
.seekOffset
= 3.14159;
58 } else if (action
== "seekto") {
59 details
.seekTime
= 1.618;
64 function setHandlerAndTakeAction(action
, handler
) {
65 let promise
= new Promise(resolve
=> {
66 navigator
.mediaSession
.setActionHandler(action
, details
=> {
71 generateAction(action
);
75 function hasSameValue(a
, b
) {
76 // The order of the object matters when stringify the object.
77 return JSON
.stringify(a
) == JSON
.stringify(b
);
80 function clearActionHandler(action
) {
81 navigator
.mediaSession
.setActionHandler(action
, null);