dom/alarm/test/test_bug1037079.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 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <meta charset="utf-8">
michael@0 5 <title>Test time alert is fired for Bug 1037079</title>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <p id="display"></p>
michael@0 11 <div id="content" style="display: none"></div>
michael@0 12 <pre id="test">
michael@0 13 <script type="application/javascript">
michael@0 14
michael@0 15 "use strict";
michael@0 16
michael@0 17 function testFireTimeAlert() {
michael@0 18 var secondsLater = new Date();
michael@0 19 secondsLater.setSeconds(secondsLater.getSeconds() + 10);
michael@0 20
michael@0 21 var domRequest;
michael@0 22 try {
michael@0 23 // Set system message handler.
michael@0 24 navigator.mozSetMessageHandler('alarm', function(message){
michael@0 25 ok(true, "Time alert has been fired.");
michael@0 26 SimpleTest.finish();
michael@0 27 });
michael@0 28
michael@0 29 domRequest = navigator.mozAlarms.add(secondsLater, "honorTimezone",
michael@0 30 {type: "timer"});
michael@0 31 } catch (e) {
michael@0 32 ok(false, "Unexpected exception trying to set time alert.");
michael@0 33
michael@0 34 return SimpleTest.finish();
michael@0 35 }
michael@0 36 domRequest.onsuccess = function(e) {
michael@0 37 ok(true, "Set time alert. Waiting to be fired.");
michael@0 38 };
michael@0 39 domRequest.onerror = function(e) {
michael@0 40 ok(false, "Unable to set time alert.");
michael@0 41
michael@0 42 SimpleTest.finish();
michael@0 43 };
michael@0 44 }
michael@0 45
michael@0 46 function startTests() {
michael@0 47 SpecialPowers.pushPrefEnv({
michael@0 48 "set": [["dom.mozAlarms.enabled", true]]
michael@0 49 }, function() {
michael@0 50 var isAllowedToTest = true;
michael@0 51
michael@0 52 if (navigator.appVersion.indexOf("Android") !== -1) {
michael@0 53 ok(true, "mozAlarms is not allowed on Android for now. " +
michael@0 54 "TODO Bug 863557.");
michael@0 55 isAllowedToTest = false;
michael@0 56 } else if (SpecialPowers.wrap(document).nodePrincipal.appStatus ==
michael@0 57 SpecialPowers.Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED) {
michael@0 58 ok(true, "mozAlarms is not allowed for non-installed apps. " +
michael@0 59 "TODO Bug 876981.");
michael@0 60 isAllowedToTest = false;
michael@0 61 }
michael@0 62
michael@0 63 if (isAllowedToTest) {
michael@0 64 ok(true, "Start to test...");
michael@0 65 testFireTimeAlert();
michael@0 66 } else {
michael@0 67 // A sanity check to make sure we must run tests on Firefox OS (B2G).
michael@0 68 if (navigator.userAgent.indexOf("Mobile") != -1 &&
michael@0 69 navigator.appVersion.indexOf("Android") == -1) {
michael@0 70 ok(false, "Should run the test on Firefox OS (B2G)!");
michael@0 71 }
michael@0 72
michael@0 73 SimpleTest.finish();
michael@0 74 }
michael@0 75 });
michael@0 76 }
michael@0 77
michael@0 78 SimpleTest.expectAssertions(0, 9);
michael@0 79 SimpleTest.waitForExplicitFinish();
michael@0 80 if (SpecialPowers.hasPermission("alarms", document)) {
michael@0 81 startTests();
michael@0 82 } else {
michael@0 83 // Add the permissions and reload so they propogate
michael@0 84 SpecialPowers.addPermission("alarms", true, document);
michael@0 85 window.location.reload();
michael@0 86 }
michael@0 87
michael@0 88 </script>
michael@0 89 </pre>
michael@0 90 </body>
michael@0 91 </html>

mercurial