dom/tests/mochitest/gamepad/test_gamepad_frame_state_sync.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!-- Any copyright is dedicated to the Public Domain.
michael@0 2 - http://creativecommons.org/publicdomain/zero/1.0/ -->
michael@0 3 <!DOCTYPE HTML>
michael@0 4 <html>
michael@0 5 <head>
michael@0 6 <title>Test hidden frames</title>
michael@0 7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <script type="text/javascript" src="mock_gamepad.js"></script>
michael@0 12 <script class="testbody" type="text/javascript">
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14 var index = GamepadService.addGamepad("test gamepad", // id
michael@0 15 SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING,
michael@0 16 4, // buttons
michael@0 17 2);// axes
michael@0 18
michael@0 19 function setFrameVisible(f, visible) {
michael@0 20 var Ci = SpecialPowers.Ci;
michael@0 21 var docshell = SpecialPowers.wrap(f.contentWindow).QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
michael@0 22 docshell.isActive = visible;
michael@0 23 }
michael@0 24
michael@0 25 var frames_loaded = 0;
michael@0 26 var f1, f2;
michael@0 27 function frame_loaded() {
michael@0 28 frames_loaded++;
michael@0 29 if (frames_loaded == 2) {
michael@0 30 f1 = document.getElementById('f1');
michael@0 31 f2 = document.getElementById('f2');
michael@0 32 // Now press the button, but don't release it.
michael@0 33 GamepadService.newButtonEvent(index, 0, true);
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 window.addEventListener("gamepadbuttondown", function() {
michael@0 38 // Wait to ensure that all frames received the button press as well.
michael@0 39 SpecialPowers.executeSoon(tests[testNum++]);
michael@0 40 });
michael@0 41
michael@0 42 var testNum = 0;
michael@0 43 var tests = [
michael@0 44 check_button_pressed,
michael@0 45 check_second_frame_no_button_press,
michael@0 46 ];
michael@0 47
michael@0 48 function check_button_pressed() {
michael@0 49 // At this point the both frames should see the button as pressed.
michael@0 50 ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
michael@0 51 ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
michael@0 52
michael@0 53 // Now release the button, then hide the second frame.
michael@0 54 GamepadService.newButtonEvent(index, 0, false);
michael@0 55 setFrameVisible(f2, false);
michael@0 56 SpecialPowers.executeSoon(function() {
michael@0 57 // Now press the button, but don't release it.
michael@0 58 GamepadService.newButtonEvent(index, 0, true);
michael@0 59 });
michael@0 60 }
michael@0 61
michael@0 62 function check_second_frame_no_button_press () {
michael@0 63 /*
michael@0 64 * At this point the first frame should see the button as pressed,
michael@0 65 * but the second frame should not, since it's hidden.
michael@0 66 */
michael@0 67 ok(f1.contentWindow.gamepad.buttons[0].pressed, "frame 1 sees button pressed");
michael@0 68 ok(!f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 should not see button pressed");
michael@0 69
michael@0 70 // Now unhide the second frame.
michael@0 71 setFrameVisible(f2, true);
michael@0 72 SpecialPowers.executeSoon(function() {
michael@0 73 // Now that the frame is visible again, it should see the button
michael@0 74 // that was pressed.
michael@0 75 ok(f2.contentWindow.gamepad.buttons[0].pressed, "frame 2 sees button pressed");
michael@0 76 // cleanup
michael@0 77 GamepadService.removeGamepad(index);
michael@0 78 SimpleTest.finish();
michael@0 79 });
michael@0 80 }
michael@0 81
michael@0 82 </script>
michael@0 83 <iframe id="f1" src="gamepad_frame_state.html" onload="frame_loaded()"></iframe>
michael@0 84 <iframe id="f2" src="gamepad_frame_state.html" onload="frame_loaded()"></iframe>
michael@0 85 </body>
michael@0 86 </html>

mercurial