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 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Test Adding and Removing Alarms with Alarm API</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 checkNumberOfAlarms(n, cbk) { |
michael@0 | 18 | var domRequest; |
michael@0 | 19 | try { |
michael@0 | 20 | domRequest = navigator.mozAlarms.getAll(); |
michael@0 | 21 | } catch (e) { |
michael@0 | 22 | ok(false, |
michael@0 | 23 | "Unexpected exception trying to get all alarms."); |
michael@0 | 24 | } |
michael@0 | 25 | domRequest.onsuccess = function(e) { |
michael@0 | 26 | ok(e.target.result.length === n, "Correct number of alarms set."); |
michael@0 | 27 | cbk(); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // Add alarm and then remove it |
michael@0 | 32 | function testAddRemove() { |
michael@0 | 33 | var tomorrow = new Date(); |
michael@0 | 34 | tomorrow.setDate(tomorrow.getDate() + 1); |
michael@0 | 35 | |
michael@0 | 36 | var domRequest; |
michael@0 | 37 | try { |
michael@0 | 38 | domRequest = navigator.mozAlarms.getAll(); |
michael@0 | 39 | } catch (e) { |
michael@0 | 40 | ok(false, |
michael@0 | 41 | "Unexpected exception trying to get all alarms."); |
michael@0 | 42 | |
michael@0 | 43 | return SimpleTest.finish(); |
michael@0 | 44 | } |
michael@0 | 45 | domRequest.onsuccess = function(e) { |
michael@0 | 46 | var initialAlarmsN = e.target.result.length; |
michael@0 | 47 | |
michael@0 | 48 | var dr; |
michael@0 | 49 | try { |
michael@0 | 50 | dr = navigator.mozAlarms.add(tomorrow, "honorTimezone", null); |
michael@0 | 51 | } catch (e) { |
michael@0 | 52 | ok(false, |
michael@0 | 53 | "Unexpected exception trying add alarm."); |
michael@0 | 54 | |
michael@0 | 55 | return SimpleTest.finish(); |
michael@0 | 56 | } |
michael@0 | 57 | dr.onsuccess = function(ev) { |
michael@0 | 58 | var alarmId = ev.target.result; |
michael@0 | 59 | |
michael@0 | 60 | checkNumberOfAlarms(initialAlarmsN + 1, function() { |
michael@0 | 61 | navigator.mozAlarms.remove(alarmId); |
michael@0 | 62 | |
michael@0 | 63 | checkNumberOfAlarms(initialAlarmsN, function() { |
michael@0 | 64 | SimpleTest.finish(); |
michael@0 | 65 | }); |
michael@0 | 66 | }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function startTests() { |
michael@0 | 74 | |
michael@0 | 75 | SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() { |
michael@0 | 76 | |
michael@0 | 77 | // Currently applicable only on FxOS |
michael@0 | 78 | if (navigator.userAgent.indexOf("Mobile") != -1 && |
michael@0 | 79 | navigator.appVersion.indexOf("Android") == -1) { |
michael@0 | 80 | |
michael@0 | 81 | testAddRemove(); |
michael@0 | 82 | |
michael@0 | 83 | } else { |
michael@0 | 84 | ok(true, "mozAlarms on Firefox OS only."); |
michael@0 | 85 | SimpleTest.finish(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | }); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | SimpleTest.expectAssertions(0, 9); |
michael@0 | 92 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 93 | if (SpecialPowers.hasPermission("alarms", document)) { |
michael@0 | 94 | startTests(); |
michael@0 | 95 | } else { |
michael@0 | 96 | // Add the permission and reload so it's propogated |
michael@0 | 97 | SpecialPowers.addPermission("alarms", true, document); |
michael@0 | 98 | window.location.reload(); |
michael@0 | 99 | } |
michael@0 | 100 | </script> |
michael@0 | 101 | </pre> |
michael@0 | 102 | </body> |
michael@0 | 103 | </html> |