1 <!-- Any copyright is dedicated to the Public Domain.
2 - http://creativecommons.org/publicdomain/zero/1.0/ -->
3 <!-- bug 893785 - Test that sending a gamepadconnected event to a new window
4 doesn't result in a gamepadconnected event being sent to existing
5 windows that have already received it. -->
9 <title>Test hidden frames
</title>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <script type=
"text/javascript" src=
"mock_gamepad.js"></script>
14 <script class=
"testbody" type=
"text/javascript">
15 let ok = window.parent.ok;
16 let is = window.parent.is;
17 let SimpleTest = window.parent.SimpleTest;
18 let SpecialPowers = window.parent.SpecialPowers;
22 async function pressButton() {
23 await GamepadService.newButtonEvent(gamepad_index,
0, true, true);
24 await GamepadService.newButtonEvent(gamepad_index,
0, false, false);
28 async function startTests() {
29 window.addEventListener(
"gamepadbuttondown", function() {
30 // Wait to ensure that all frames received the button press as well.
31 SpecialPowers.executeSoon(tests[testNum++]);
34 gamepad_index = await GamepadService.addGamepad(
"test gamepad", // id
35 GamepadService.standardMapping,
36 GamepadService.noHand,
43 await gamepad_connected();
47 async function gamepad_connected() {
48 f1 = document.getElementById('f1');
59 is(f1.contentWindow.connectedEvents,
1,
"right number of connection events in frame 1");
61 // Now add another frame.
62 f2 = document.createElement(
"iframe");
63 f2.addEventListener(
"load", async () =
> {
64 // When the frame is loaded, press a button again.
67 f2.src =
"gamepad_frame.html";
68 document.body.appendChild(f2);
71 async function test2() {
72 is(f1.contentWindow.connectedEvents,
1,
"right number of connection events in frame 1");
73 is(f2.contentWindow.connectedEvents,
1,
"right number of connection events in frame 2");
74 is(f1.contentWindow.idlConnected,
1,
"right number of IDL connection events in frame 1");
75 is(f2.contentWindow.idlConnected,
1,
"right number of IDL connection events in frame 2");
76 await GamepadService.removeGamepad(gamepad_index);
81 <iframe id=
"f1" src=
"gamepad_frame.html" onload=
"runGamepadTest(startTests)"></iframe>