Bug 1945643 - Update to mozilla-nimbus-schemas 2025.1.1 r=chumphreys
[gecko.git] / dom / media / mediasession / test / test_trigger_actionhandler.html
blobf4fc84e7e2dd0c77b2f3e03b62c3ed437e7fd177
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test of triggering media session's action handlers</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7 <script src="MediaSessionTestUtils.js"></script>
8 </head>
9 <body>
10 <script>
11 /**
12 * This test is used to test if pressing media control keys can trigger media
13 * session's corresponding action handler under different situations.
15 const testCases = [
17 name: "Triggering action handlers for session created in [main-frame]",
18 shouldCreateFrom: "main-frame",
21 name: "Triggering action handlers for session created in [same-origin] [child-frame]",
22 shouldCreateFrom: "child-frame",
23 origin: "same-origin",
26 name: "Triggering action handlers for session created in [cross-origin] [child-frame]",
27 shouldCreateFrom: "child-frame",
28 origin: "cross-origin",
32 SimpleTest.waitForExplicitFinish();
34 SpecialPowers.pushPrefEnv({"set": [
35 ["media.mediacontrol.testingevents.enabled", true],
36 ]}, startTest());
38 async function startTest() {
39 for (const testCase of testCases) {
40 info(`- loading test '${testCase.name}' in a new window -`);
41 const testURL = "file_trigger_actionhandler_window.html";
42 const testWindow = window.open(testURL, "", "width=500,height=500");
43 await new Promise(r => testWindow.onload = r);
45 info("- start running test -");
46 testWindow.postMessage(testCase, window.origin);
47 is((await nextWindowMessage()).data, "success",
48 `- finished test '${testCase.name}' -`);
49 testWindow.close();
51 SimpleTest.finish();
54 </script>
55 </body>
56 </html>