dom/alarm/test/test_alarm_add_respectTimezone.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 respectTimezone Parameter 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 `honorTimezone` doesn't fail
michael@0 18 function testHonorTimezone(tomorrow) {
michael@0 19 var domRequest;
michael@0 20 try {
michael@0 21 domRequest = navigator.mozAlarms.add(tomorrow, "honorTimezone", {});
michael@0 22 } catch (e) {
michael@0 23 ok(false,
michael@0 24 "Unexpected exception trying to add alarm for tomorrow with `honorTimezone`.");
michael@0 25 return testIgnoreTimezone(tomorrow);
michael@0 26 }
michael@0 27 domRequest.onsuccess = function(e) {
michael@0 28 navigator.mozAlarms.remove(e.target.result);
michael@0 29
michael@0 30 ok(true, "Passing `honorTimezone` for repectTimezone argument.");
michael@0 31 testIgnoreTimezone(tomorrow);
michael@0 32 };
michael@0 33 domRequest.onerror = function(e) {
michael@0 34 ok(false, "Unable to add alarm for tomorrow with `honorTimezone`.");
michael@0 35 testIgnoreTimezone(tomorrow);
michael@0 36 };
michael@0 37
michael@0 38 }
michael@0 39
michael@0 40 // Verify passing `ignoreTimezone` doesn't fail
michael@0 41 function testIgnoreTimezone(tomorrow) {
michael@0 42 var domRequest;
michael@0 43 try {
michael@0 44 domRequest = navigator.mozAlarms.add(tomorrow, "ignoreTimezone", {});
michael@0 45 } catch (e) {
michael@0 46 ok(false,
michael@0 47 "Unexpected exception trying to add alarm for tomorrow with `ignoreTimezone`.");
michael@0 48 return testBadInput(tomorrow);
michael@0 49 }
michael@0 50 domRequest.onsuccess = function(e) {
michael@0 51 navigator.mozAlarms.remove(e.target.result);
michael@0 52
michael@0 53 ok(true, "Passing `ignoreTimezone` for respectTimezone argument.");
michael@0 54 testBadInput(tomorrow);
michael@0 55 };
michael@0 56 domRequest.onerror = function(e) {
michael@0 57 ok(false, "Unable to add alarm for tomorrow with `ignoreTimezone`.");
michael@0 58 testBadInput(tomorrow);
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 // Verify passing a string that's not `honorTimezone` or `ignoreTimezone`
michael@0 63 // does fail
michael@0 64 function testBadInput(tomorrow) {
michael@0 65 var domRequest;
michael@0 66 try {
michael@0 67 domRequest = navigator.mozAlarms.add(tomorrow, "badinput", {});
michael@0 68 } catch (e) {
michael@0 69 ok(true, "Bad input for repectTimezone does indeed fail.");
michael@0 70
michael@0 71 // Errors, as it should. On to the next test.
michael@0 72 return testNull(tomorrow);
michael@0 73 }
michael@0 74 domRequest.onsuccess = function(e) {
michael@0 75 // Welp, this shouldn't happen
michael@0 76 ok(false, "Malformed input accepted for `respectTimezone` param.");
michael@0 77 testNull(tomorrow);
michael@0 78 };
michael@0 79 }
michael@0 80
michael@0 81 // Verify passing null does indeed fail
michael@0 82 function testNull(tomorrow) {
michael@0 83 var domRequest;
michael@0 84 try {
michael@0 85 domRequest = navigator.mozAlarms.add(tomorrow, null, {});
michael@0 86 } catch(e) {
michael@0 87 ok(true, "Passing null for respectTimezone does indeed fail.");
michael@0 88
michael@0 89 // Exception thrown, on to the next test
michael@0 90 return testMisspelt(tomorrow);
michael@0 91 }
michael@0 92 domRequest.onsuccess = function(e) {
michael@0 93 // Null should not be valid
michael@0 94 ok(false, "Null should not be accepted as input for `respectTimezone` param.");
michael@0 95 testMisspelt(tomorrow);
michael@0 96 };
michael@0 97 }
michael@0 98
michael@0 99 // Verify that misspelling does indeed fail
michael@0 100 function testMisspelt(tomorrow) {
michael@0 101 var domRequest;
michael@0 102 try {
michael@0 103 // Missing the e in `ignoreTimezone`
michael@0 104 domRequest = navigator.mozAlarms.add(tomorrow, "ignoreTimzone", {});
michael@0 105 } catch (e) {
michael@0 106 ok(true, "Misspelling `ignoreTimezone` does indeed fail.");
michael@0 107
michael@0 108 // Exception thrown, all is right in the world.
michael@0 109 // All done with tests now.
michael@0 110 return SimpleTest.finish();
michael@0 111 }
michael@0 112 domRequest.onsuccess = function(e) {
michael@0 113 // The misspelled word should not be valid
michael@0 114 ok(false, "Misspelt parameter should fail.");
michael@0 115 SimpleTest.finish();
michael@0 116 };
michael@0 117 }
michael@0 118
michael@0 119 function startTests() {
michael@0 120
michael@0 121 SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
michael@0 122
michael@0 123 // Currently applicable only on FxOS
michael@0 124 if (navigator.userAgent.indexOf("Mobile") != -1 &&
michael@0 125 navigator.appVersion.indexOf("Android") == -1) {
michael@0 126
michael@0 127 // Arbitrary date to use for tests
michael@0 128 var tomorrow = new Date();
michael@0 129 tomorrow.setDate(tomorrow.getDate() + 1);
michael@0 130
michael@0 131 // Kick off the tests
michael@0 132 testHonorTimezone(tomorrow);
michael@0 133
michael@0 134 } else {
michael@0 135 ok(true, "mozAlarms on Firefox OS only.");
michael@0 136 SimpleTest.finish();
michael@0 137 }
michael@0 138
michael@0 139 });
michael@0 140 }
michael@0 141
michael@0 142 SimpleTest.expectAssertions(0, 9);
michael@0 143 SimpleTest.waitForExplicitFinish();
michael@0 144 if (SpecialPowers.hasPermission("alarms", document)) {
michael@0 145 startTests();
michael@0 146 } else {
michael@0 147 // Add the permission and reload the page so it propogates
michael@0 148 SpecialPowers.addPermission("alarms", true, document);
michael@0 149 window.location.reload();
michael@0 150 }
michael@0 151
michael@0 152 </script>
michael@0 153 </pre>
michael@0 154 </body>
michael@0 155 </html>

mercurial