Tue, 06 Jan 2015 21:39:09 +0100
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 gamepad</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 | |
michael@0 | 15 | var testNum = 0; |
michael@0 | 16 | var tests = [ |
michael@0 | 17 | check_first_gamepad, |
michael@0 | 18 | check_second_gamepad, |
michael@0 | 19 | check_gamepad_hole, |
michael@0 | 20 | check_no_gamepads, |
michael@0 | 21 | ]; |
michael@0 | 22 | |
michael@0 | 23 | function run_next_test(event) { |
michael@0 | 24 | SpecialPowers.executeSoon(function() { tests[testNum++](event); }); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | // gamepads should be empty first |
michael@0 | 28 | is(navigator.getGamepads().length, 0, "should be zero gamepads exposed"); |
michael@0 | 29 | |
michael@0 | 30 | function connecthandler(e) { |
michael@0 | 31 | run_next_test(e); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function disconnecthandler(e) { |
michael@0 | 35 | run_next_test(e); |
michael@0 | 36 | } |
michael@0 | 37 | window.addEventListener("gamepadconnected", connecthandler); |
michael@0 | 38 | window.addEventListener("gamepaddisconnected", disconnecthandler); |
michael@0 | 39 | // Add a gamepad |
michael@0 | 40 | var index1 = GamepadService.addGamepad("test gamepad 1", // id |
michael@0 | 41 | SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, |
michael@0 | 42 | 4, // buttons |
michael@0 | 43 | 2);// axes |
michael@0 | 44 | var index2; |
michael@0 | 45 | |
michael@0 | 46 | // Press a button to make the gamepad visible to the page. |
michael@0 | 47 | GamepadService.newButtonEvent(index1, 0, true); |
michael@0 | 48 | |
michael@0 | 49 | function check_first_gamepad(e) { |
michael@0 | 50 | // First gamepad gets added. |
michael@0 | 51 | is(e.gamepad.id, "test gamepad 1", "correct gamepad name"); |
michael@0 | 52 | var gamepads = navigator.getGamepads(); |
michael@0 | 53 | is(gamepads.length, 1, "should have one gamepad exposed"); |
michael@0 | 54 | is(gamepads[e.gamepad.index], e.gamepad, "right gamepad exposed at index"); |
michael@0 | 55 | // Add a second gamepad, should automatically show up. |
michael@0 | 56 | index2 = GamepadService.addGamepad("test gamepad 2", // id |
michael@0 | 57 | SpecialPowers.Ci.nsIGamepadServiceTest.NO_MAPPING, |
michael@0 | 58 | 4, // buttons |
michael@0 | 59 | 2);// axes |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function check_second_gamepad(e) { |
michael@0 | 63 | // Second gamepad gets added. |
michael@0 | 64 | is(e.gamepad.id, "test gamepad 2", "correct gamepad name"); |
michael@0 | 65 | var gamepads = navigator.getGamepads(); |
michael@0 | 66 | is(gamepads.length, 2, "should have two gamepads exposed"); |
michael@0 | 67 | is(gamepads[e.gamepad.index], e.gamepad, "right gamepad exposed at index"); |
michael@0 | 68 | // Now remove the first one. |
michael@0 | 69 | GamepadService.removeGamepad(index1); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function check_gamepad_hole(e) { |
michael@0 | 73 | // First gamepad gets removed. |
michael@0 | 74 | var gamepads = navigator.getGamepads(); |
michael@0 | 75 | is(gamepads.length, 2, "gamepads should have two entries"); |
michael@0 | 76 | is(gamepads[index1], null, "should be a hole in the gamepad list"); |
michael@0 | 77 | isnot(gamepads[index2], null, "second gamepad should exist"); |
michael@0 | 78 | // Now remove the second one. |
michael@0 | 79 | GamepadService.removeGamepad(index2); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function check_no_gamepads(e) { |
michael@0 | 83 | // Second gamepad gets removed. |
michael@0 | 84 | var gamepads = navigator.getGamepads(); |
michael@0 | 85 | is(gamepads.length, 0, "gamepads should be empty"); |
michael@0 | 86 | SimpleTest.finish(); |
michael@0 | 87 | } |
michael@0 | 88 | </script> |
michael@0 | 89 | </body> |
michael@0 | 90 | </html> |
michael@0 | 91 |