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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for Vibrator</title> |
michael@0 | 5 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | |
michael@0 | 11 | <!-- Although we can't test that the vibrator works properly, we can test that |
michael@0 | 12 | navigator.vibrate throws an exception where appropriate. --> |
michael@0 | 13 | |
michael@0 | 14 | <script class="testbody" type="text/javascript;version=1.7"> |
michael@0 | 15 | var result; |
michael@0 | 16 | function expectFailure(param) { |
michael@0 | 17 | result = navigator.vibrate(param); |
michael@0 | 18 | is(result, false, 'vibrate(' + param + ') should have failed.'); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function expectSuccess(param) { |
michael@0 | 22 | result = navigator.vibrate(param); |
michael@0 | 23 | is(result, true, 'vibrate(' + param + ') must succeed.'); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function testFailures() { |
michael@0 | 27 | expectSuccess(null); |
michael@0 | 28 | expectSuccess(undefined); |
michael@0 | 29 | expectFailure(-1); |
michael@0 | 30 | expectSuccess('a'); |
michael@0 | 31 | expectFailure([100, -1]); |
michael@0 | 32 | expectSuccess([100, 'a']); |
michael@0 | 33 | |
michael@0 | 34 | var maxVibrateMs = SpecialPowers.getIntPref('dom.vibrator.max_vibrate_ms'); |
michael@0 | 35 | var maxVibrateListLen = SpecialPowers.getIntPref('dom.vibrator.max_vibrate_list_len'); |
michael@0 | 36 | |
michael@0 | 37 | // Make sure that these preferences are respected. |
michael@0 | 38 | expectFailure(maxVibrateMs + 1); |
michael@0 | 39 | expectFailure([maxVibrateMs + 1]); |
michael@0 | 40 | |
michael@0 | 41 | var arr = []; |
michael@0 | 42 | for (var i = 0; i < maxVibrateListLen + 1; i++) { |
michael@0 | 43 | arr[i] = 0; |
michael@0 | 44 | } |
michael@0 | 45 | expectFailure(arr); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function testSuccesses() { |
michael@0 | 49 | expectSuccess(0); |
michael@0 | 50 | expectSuccess([]); |
michael@0 | 51 | expectSuccess('1000'); |
michael@0 | 52 | expectSuccess(1000); |
michael@0 | 53 | expectSuccess(1000.1); |
michael@0 | 54 | expectSuccess([0, 0, 0]); |
michael@0 | 55 | expectSuccess(['1000', 1000]); |
michael@0 | 56 | expectSuccess([1000, 1000]); |
michael@0 | 57 | expectSuccess([1000, 1000.1]); |
michael@0 | 58 | |
michael@0 | 59 | // The following loop shouldn't cause us to crash. See bug 701716. |
michael@0 | 60 | for (var i = 0; i < 10000; i++) { |
michael@0 | 61 | navigator.vibrate([100, 100]); |
michael@0 | 62 | } |
michael@0 | 63 | ok(true, "Didn't crash after issuing a lot of vibrate() calls."); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | var origVibratorEnabled = SpecialPowers.getBoolPref('dom.vibrator.enabled'); |
michael@0 | 67 | |
michael@0 | 68 | // Test with the vibrator pref enabled. |
michael@0 | 69 | try { |
michael@0 | 70 | SpecialPowers.setBoolPref('dom.vibrator.enabled', true); |
michael@0 | 71 | testFailures(); |
michael@0 | 72 | testSuccesses(); |
michael@0 | 73 | |
michael@0 | 74 | // Everything should be the same when the vibrator is disabled -- in |
michael@0 | 75 | // particular, a disabled vibrator shouldn't eat failures we'd otherwise |
michael@0 | 76 | // observe. |
michael@0 | 77 | SpecialPowers.setBoolPref('dom.vibrator.enabled', false); |
michael@0 | 78 | testFailures(); |
michael@0 | 79 | testSuccesses(); |
michael@0 | 80 | } |
michael@0 | 81 | finally { |
michael@0 | 82 | SpecialPowers.setBoolPref('dom.vibrator.enabled', origVibratorEnabled); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | </script> |
michael@0 | 86 | </body> |
michael@0 | 87 | |
michael@0 | 88 | </html> |