test_trigger_actionhandler.html (1685B)
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. 14 */ 15 const testCases = [ 16 { 17 name: "Triggering action handlers for session created in [main-frame]", 18 shouldCreateFrom: "main-frame", 19 }, 20 { 21 name: "Triggering action handlers for session created in [same-origin] [child-frame]", 22 shouldCreateFrom: "child-frame", 23 origin: "same-origin", 24 }, 25 { 26 name: "Triggering action handlers for session created in [cross-origin] [child-frame]", 27 shouldCreateFrom: "child-frame", 28 origin: "cross-origin", 29 }, 30 ]; 31 32 SimpleTest.waitForExplicitFinish(); 33 34 SpecialPowers.pushPrefEnv({"set": [ 35 ["media.mediacontrol.testingevents.enabled", true], 36 ]}, startTest()); 37 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); 44 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(); 50 } 51 SimpleTest.finish(); 52 } 53 54 </script> 55 </body> 56 </html>