dom/alarm/test/test_alarm_add_respectTimezone.html

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

mercurial