|
1 <!-- Any copyright is dedicated to the Public Domain. |
|
2 - http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
3 <!DOCTYPE HTML> |
|
4 <html> |
|
5 <head> |
|
6 <title>Test hidden frames</title> |
|
7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
9 </head> |
|
10 <body> |
|
11 <script type="text/javascript" src="mock_gamepad.js"></script> |
|
12 <script class="testbody" type="text/javascript"> |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 var index = GamepadService.addGamepad("test gamepad", // id |
|
15 SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, |
|
16 4, // buttons |
|
17 2);// axes |
|
18 |
|
19 function pressButton() { |
|
20 GamepadService.newButtonEvent(index, 0, true); |
|
21 GamepadService.newButtonEvent(index, 0, false); |
|
22 } |
|
23 |
|
24 function setFrameVisible(f, visible) { |
|
25 var Ci = SpecialPowers.Ci; |
|
26 var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell); |
|
27 docshell.isActive = visible; |
|
28 } |
|
29 |
|
30 var frames_loaded = 0; |
|
31 var f1, f2; |
|
32 function frame_loaded() { |
|
33 frames_loaded++; |
|
34 if (frames_loaded == 2) { |
|
35 f1 = document.getElementById('f1'); |
|
36 f2 = document.getElementById('f2'); |
|
37 pressButton(); |
|
38 } |
|
39 } |
|
40 |
|
41 window.addEventListener("gamepadbuttondown", function() { |
|
42 // Wait to ensure that all frames received the button press as well. |
|
43 SpecialPowers.executeSoon(tests[testNum++]); |
|
44 }); |
|
45 |
|
46 var testNum = 0; |
|
47 var tests = [ |
|
48 test1, |
|
49 test2, |
|
50 ]; |
|
51 |
|
52 function test1() { |
|
53 is(f1.contentWindow.buttonPresses, 1, "right number of button presses in frame 1"); |
|
54 is(f2.contentWindow.buttonPresses, 1, "right number of button presses in frame 2"); |
|
55 |
|
56 // Now hide the second frame and send another button press. |
|
57 setFrameVisible(f2, false); |
|
58 SpecialPowers.executeSoon(function() { pressButton(); }); |
|
59 } |
|
60 |
|
61 function test2() { |
|
62 is(f1.contentWindow.buttonPresses, 2, "right number of button presses in frame 1"); |
|
63 is(f2.contentWindow.buttonPresses, 1, "right number of button presses in frame 2"); |
|
64 GamepadService.removeGamepad(index); |
|
65 SimpleTest.finish(); |
|
66 } |
|
67 |
|
68 </script> |
|
69 <iframe id="f1" src="gamepad_frame.html" onload="frame_loaded()"></iframe> |
|
70 <iframe id="f2" src="gamepad_frame.html" onload="frame_loaded()"></iframe> |
|
71 </body> |
|
72 </html> |