dom/alarm/test/test_alarm_add_date.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 date Paramter for 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 // Verify passing a Date in the future doesn't fail
michael@0 18 function testFutureDate() {
michael@0 19 var tomorrow = new Date();
michael@0 20 tomorrow.setDate(tomorrow.getDate() + 1);
michael@0 21
michael@0 22 var domRequest;
michael@0 23 try {
michael@0 24 domRequest = navigator.mozAlarms.add(tomorrow, "honorTimezone", {});
michael@0 25 } catch (e) {
michael@0 26 ok(false,
michael@0 27 "Unexpected exception trying to add alarm for tomorrow.");
michael@0 28
michael@0 29 // Proceed to next test.
michael@0 30 return testPastDate();
michael@0 31 }
michael@0 32 domRequest.onsuccess = function(e) {
michael@0 33 navigator.mozAlarms.remove(e.target.result);
michael@0 34 ok(true, "Add alarm for future date.");
michael@0 35
michael@0 36 // Awesome, no error so proceed to next test.
michael@0 37 testPastDate();
michael@0 38 };
michael@0 39 domRequest.onerror = function(e) {
michael@0 40 ok(false, "Unable to add alarm for tomorrow`.");
michael@0 41
michael@0 42 // Proceed to next test.
michael@0 43 testPastDate();
michael@0 44 };
michael@0 45 }
michael@0 46
michael@0 47 // Verify passing a Date that's already past doesn't fail (it should fire immediately).
michael@0 48 function testPastDate() {
michael@0 49 var yesterday = new Date();
michael@0 50 yesterday.setDate(yesterday.getDate() - 1);
michael@0 51
michael@0 52 var domRequest;
michael@0 53 try {
michael@0 54 domRequest = navigator.mozAlarms.add(yesterday, "honorTimezone", {});
michael@0 55 } catch (e) {
michael@0 56 ok(false,
michael@0 57 "Unexpected exception trying to add alarm for yesterday.");
michael@0 58
michael@0 59 // Move on to the next test.
michael@0 60 testNullDate();
michael@0 61 }
michael@0 62 domRequest.onsuccess = function(e) {
michael@0 63 navigator.mozAlarms.remove(e.target.result);
michael@0 64
michael@0 65 ok(true, "Should be able to add alarm for already past date, which should fire immediately.");
michael@0 66
michael@0 67 // Move on to the next test.
michael@0 68 testNullDate();
michael@0 69 };
michael@0 70 domRequest.onerror = function(e) {
michael@0 71 ok(false, "Unable to add alarm for yesterday.");
michael@0 72
michael@0 73 // Move on to the next test.
michael@0 74 testNullDate();
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 // Verify passing null does indeed fail
michael@0 79 function testNullDate() {
michael@0 80 try {
michael@0 81 navigator.mozAlarms.add(null, "honorTimezone", {});
michael@0 82 ok(false, "Expected an exception to be thrown for alarm with null date.");
michael@0 83 } catch(e) {
michael@0 84 ok(true, "Exception thrown for alarm with null date.");
michael@0 85 }
michael@0 86
michael@0 87 // Move on to the next test.
michael@0 88 testInvalidTimeZone()
michael@0 89 }
michael@0 90
michael@0 91 function testInvalidTimeZone() {
michael@0 92 try {
michael@0 93 navigator.mozAlarms.add(new Date(), "badTimeZoneArg", {});
michael@0 94 ok(false, "Expected an exception to be thrown while testing bad time zone arg.");
michael@0 95 } catch(e) {
michael@0 96 ok(true, "Exception thrown while testing bad time zone arg.");
michael@0 97 }
michael@0 98 SimpleTest.finish();
michael@0 99 }
michael@0 100
michael@0 101 function startTests() {
michael@0 102
michael@0 103 SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
michael@0 104 // Currently applicable only on FxOS
michael@0 105 if (navigator.userAgent.indexOf("Mobile") != -1 &&
michael@0 106 navigator.appVersion.indexOf("Android") == -1)
michael@0 107 {
michael@0 108 testFutureDate();
michael@0 109 } else {
michael@0 110 ok(true, "mozAlarms on Firefox OS only.");
michael@0 111 SimpleTest.finish();
michael@0 112 }
michael@0 113 });
michael@0 114 }
michael@0 115
michael@0 116 SimpleTest.expectAssertions(0, 9);
michael@0 117 SimpleTest.waitForExplicitFinish();
michael@0 118 if (SpecialPowers.hasPermission("alarms", document)) {
michael@0 119 startTests();
michael@0 120 } else {
michael@0 121 // Add the permissions and reload so they propogate
michael@0 122 SpecialPowers.addPermission("alarms", true, document);
michael@0 123 window.location.reload();
michael@0 124 }
michael@0 125
michael@0 126 </script>
michael@0 127 </pre>
michael@0 128 </body>
michael@0 129 </html>

mercurial