|
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. --> |
|
6 <!DOCTYPE HTML> |
|
7 <html> |
|
8 <head> |
|
9 <title>Test hidden frames</title> |
|
10 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
12 </head> |
|
13 <body> |
|
14 <script type="text/javascript" src="mock_gamepad.js"></script> |
|
15 <script class="testbody" type="text/javascript"> |
|
16 SimpleTest.waitForExplicitFinish(); |
|
17 var index = GamepadService.addGamepad("test gamepad", // id |
|
18 SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, |
|
19 4, // buttons |
|
20 2);// axes |
|
21 |
|
22 function pressButton() { |
|
23 GamepadService.newButtonEvent(index, 0, true); |
|
24 GamepadService.newButtonEvent(index, 0, false); |
|
25 } |
|
26 |
|
27 var f1, f2; |
|
28 function frame_loaded() { |
|
29 f1 = document.getElementById('f1'); |
|
30 pressButton(); |
|
31 } |
|
32 |
|
33 window.addEventListener("gamepadbuttondown", function() { |
|
34 // Wait to ensure that all frames received the button press as well. |
|
35 SpecialPowers.executeSoon(tests[testNum++]); |
|
36 }); |
|
37 |
|
38 var testNum = 0; |
|
39 var tests = [ |
|
40 test1, |
|
41 test2, |
|
42 ]; |
|
43 |
|
44 function test1() { |
|
45 is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1"); |
|
46 |
|
47 // Now add another frame. |
|
48 f2 = document.createElement("iframe"); |
|
49 f2.addEventListener("load", function() { |
|
50 // When the frame is loaded, press a button again. |
|
51 pressButton(); |
|
52 }); |
|
53 f2.src = "gamepad_frame.html"; |
|
54 document.body.appendChild(f2); |
|
55 } |
|
56 |
|
57 function test2() { |
|
58 is(f1.contentWindow.connectedEvents, 1, "right number of connection events in frame 1"); |
|
59 is(f2.contentWindow.connectedEvents, 1, "right number of connection events in frame 2"); |
|
60 GamepadService.removeGamepad(index); |
|
61 SimpleTest.finish(); |
|
62 } |
|
63 |
|
64 </script> |
|
65 <iframe id="f1" src="gamepad_frame.html" onload="frame_loaded()"></iframe> |
|
66 </body> |
|
67 </html> |