summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasession/test/test_trigger_actionhanlder.html
blob: a0e170c8682996fc9766db49146eadd0076d147e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE HTML>
<html>
  <head>
    <title>Test of triggering media session's action handlers</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    <script src="MediaSessionTestUtils.js"></script>
  </head>
<body>
<script>
/**
 * This test is used to test if pressing media control keys can trigger media
 * session's corresponding action handler under different situations.
 */
const testCases = [
  {
    name: "Triggering action handlers for session created in [main-frame]",
    shouldCreateFrom: "main-frame",
  },
  {
    name: "Triggering action handlers for session created in [same-origin] [child-frame]",
    shouldCreateFrom: "child-frame",
    origin: "same-origin",
  },
  {
    name: "Triggering action handlers for session created in [cross-origin] [child-frame]",
    shouldCreateFrom: "child-frame",
    origin: "cross-origin",
  },
];

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv({"set": [
  ["media.mediacontrol.testingevents.enabled", true],
]}, startTest());

async function startTest() {
  for (const testCase of testCases) {
    info(`- loading test '${testCase.name}' in a new window -`);
    const testURL = "file_trigger_actionhanlder_window.html";
    const testWindow = window.open(testURL, "", "width=500,height=500");
    await new Promise(r => testWindow.onload = r);

    info("- start running test -");
    testWindow.postMessage(testCase, window.origin);
    is((await nextWindowMessage()).data, "success",
       `- finished test '${testCase.name}' -`);
    testWindow.close();
  }
  SimpleTest.finish();
}

</script>
</body>
</html>