1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/alarm/test/test_alarm_add_respectTimezone.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Test respectTimezone Parameter for Alarm API</title> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.10 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 +</head> 1.12 +<body> 1.13 +<p id="display"></p> 1.14 +<div id="content" style="display: none"></div> 1.15 +<pre id="test"> 1.16 + <script type="application/javascript"> 1.17 + 1.18 + "use strict"; 1.19 + 1.20 + // Verify passing `honorTimezone` doesn't fail 1.21 + function testHonorTimezone(tomorrow) { 1.22 + var domRequest; 1.23 + try { 1.24 + domRequest = navigator.mozAlarms.add(tomorrow, "honorTimezone", {}); 1.25 + } catch (e) { 1.26 + ok(false, 1.27 + "Unexpected exception trying to add alarm for tomorrow with `honorTimezone`."); 1.28 + return testIgnoreTimezone(tomorrow); 1.29 + } 1.30 + domRequest.onsuccess = function(e) { 1.31 + navigator.mozAlarms.remove(e.target.result); 1.32 + 1.33 + ok(true, "Passing `honorTimezone` for repectTimezone argument."); 1.34 + testIgnoreTimezone(tomorrow); 1.35 + }; 1.36 + domRequest.onerror = function(e) { 1.37 + ok(false, "Unable to add alarm for tomorrow with `honorTimezone`."); 1.38 + testIgnoreTimezone(tomorrow); 1.39 + }; 1.40 + 1.41 + } 1.42 + 1.43 + // Verify passing `ignoreTimezone` doesn't fail 1.44 + function testIgnoreTimezone(tomorrow) { 1.45 + var domRequest; 1.46 + try { 1.47 + domRequest = navigator.mozAlarms.add(tomorrow, "ignoreTimezone", {}); 1.48 + } catch (e) { 1.49 + ok(false, 1.50 + "Unexpected exception trying to add alarm for tomorrow with `ignoreTimezone`."); 1.51 + return testBadInput(tomorrow); 1.52 + } 1.53 + domRequest.onsuccess = function(e) { 1.54 + navigator.mozAlarms.remove(e.target.result); 1.55 + 1.56 + ok(true, "Passing `ignoreTimezone` for respectTimezone argument."); 1.57 + testBadInput(tomorrow); 1.58 + }; 1.59 + domRequest.onerror = function(e) { 1.60 + ok(false, "Unable to add alarm for tomorrow with `ignoreTimezone`."); 1.61 + testBadInput(tomorrow); 1.62 + } 1.63 + } 1.64 + 1.65 + // Verify passing a string that's not `honorTimezone` or `ignoreTimezone` 1.66 + // does fail 1.67 + function testBadInput(tomorrow) { 1.68 + var domRequest; 1.69 + try { 1.70 + domRequest = navigator.mozAlarms.add(tomorrow, "badinput", {}); 1.71 + } catch (e) { 1.72 + ok(true, "Bad input for repectTimezone does indeed fail."); 1.73 + 1.74 + // Errors, as it should. On to the next test. 1.75 + return testNull(tomorrow); 1.76 + } 1.77 + domRequest.onsuccess = function(e) { 1.78 + // Welp, this shouldn't happen 1.79 + ok(false, "Malformed input accepted for `respectTimezone` param."); 1.80 + testNull(tomorrow); 1.81 + }; 1.82 + } 1.83 + 1.84 + // Verify passing null does indeed fail 1.85 + function testNull(tomorrow) { 1.86 + var domRequest; 1.87 + try { 1.88 + domRequest = navigator.mozAlarms.add(tomorrow, null, {}); 1.89 + } catch(e) { 1.90 + ok(true, "Passing null for respectTimezone does indeed fail."); 1.91 + 1.92 + // Exception thrown, on to the next test 1.93 + return testMisspelt(tomorrow); 1.94 + } 1.95 + domRequest.onsuccess = function(e) { 1.96 + // Null should not be valid 1.97 + ok(false, "Null should not be accepted as input for `respectTimezone` param."); 1.98 + testMisspelt(tomorrow); 1.99 + }; 1.100 + } 1.101 + 1.102 + // Verify that misspelling does indeed fail 1.103 + function testMisspelt(tomorrow) { 1.104 + var domRequest; 1.105 + try { 1.106 + // Missing the e in `ignoreTimezone` 1.107 + domRequest = navigator.mozAlarms.add(tomorrow, "ignoreTimzone", {}); 1.108 + } catch (e) { 1.109 + ok(true, "Misspelling `ignoreTimezone` does indeed fail."); 1.110 + 1.111 + // Exception thrown, all is right in the world. 1.112 + // All done with tests now. 1.113 + return SimpleTest.finish(); 1.114 + } 1.115 + domRequest.onsuccess = function(e) { 1.116 + // The misspelled word should not be valid 1.117 + ok(false, "Misspelt parameter should fail."); 1.118 + SimpleTest.finish(); 1.119 + }; 1.120 + } 1.121 + 1.122 + function startTests() { 1.123 + 1.124 + SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() { 1.125 + 1.126 + // Currently applicable only on FxOS 1.127 + if (navigator.userAgent.indexOf("Mobile") != -1 && 1.128 + navigator.appVersion.indexOf("Android") == -1) { 1.129 + 1.130 + // Arbitrary date to use for tests 1.131 + var tomorrow = new Date(); 1.132 + tomorrow.setDate(tomorrow.getDate() + 1); 1.133 + 1.134 + // Kick off the tests 1.135 + testHonorTimezone(tomorrow); 1.136 + 1.137 + } else { 1.138 + ok(true, "mozAlarms on Firefox OS only."); 1.139 + SimpleTest.finish(); 1.140 + } 1.141 + 1.142 + }); 1.143 + } 1.144 + 1.145 + SimpleTest.expectAssertions(0, 9); 1.146 + SimpleTest.waitForExplicitFinish(); 1.147 + if (SpecialPowers.hasPermission("alarms", document)) { 1.148 + startTests(); 1.149 + } else { 1.150 + // Add the permission and reload the page so it propogates 1.151 + SpecialPowers.addPermission("alarms", true, document); 1.152 + window.location.reload(); 1.153 + } 1.154 + 1.155 + </script> 1.156 +</pre> 1.157 +</body> 1.158 +</html>