2013-03-18 22:47:30 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Test date Paramter for Alarm API</title>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Verify passing a Date in the future doesn't fail
|
|
|
|
function testFutureDate() {
|
|
|
|
var tomorrow = new Date();
|
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
|
|
|
|
|
|
var domRequest;
|
|
|
|
try {
|
|
|
|
domRequest = navigator.mozAlarms.add(tomorrow, "honorTimezone", {});
|
|
|
|
} catch (e) {
|
|
|
|
ok(false,
|
|
|
|
"Unexpected exception trying to add alarm for tomorrow.");
|
2013-07-24 17:46:59 +00:00
|
|
|
|
|
|
|
// Proceed to next test.
|
2013-03-18 22:47:30 +00:00
|
|
|
return testPastDate();
|
|
|
|
}
|
|
|
|
domRequest.onsuccess = function(e) {
|
|
|
|
navigator.mozAlarms.remove(e.target.result);
|
|
|
|
ok(true, "Add alarm for future date.");
|
|
|
|
|
2013-07-24 17:46:59 +00:00
|
|
|
// Awesome, no error so proceed to next test.
|
2013-03-18 22:47:30 +00:00
|
|
|
testPastDate();
|
|
|
|
};
|
|
|
|
domRequest.onerror = function(e) {
|
|
|
|
ok(false, "Unable to add alarm for tomorrow`.");
|
2013-07-24 17:46:59 +00:00
|
|
|
|
|
|
|
// Proceed to next test.
|
2013-03-18 22:47:30 +00:00
|
|
|
testPastDate();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:46:59 +00:00
|
|
|
// Verify passing a Date that's already past doesn't fail (it should fire immediately).
|
2013-03-18 22:47:30 +00:00
|
|
|
function testPastDate() {
|
|
|
|
var yesterday = new Date();
|
|
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
|
|
|
|
var domRequest;
|
|
|
|
try {
|
|
|
|
domRequest = navigator.mozAlarms.add(yesterday, "honorTimezone", {});
|
|
|
|
} catch (e) {
|
|
|
|
ok(false,
|
|
|
|
"Unexpected exception trying to add alarm for yesterday.");
|
2013-07-24 17:46:59 +00:00
|
|
|
|
|
|
|
// Move on to the next test.
|
|
|
|
testNullDate();
|
2013-03-18 22:47:30 +00:00
|
|
|
}
|
|
|
|
domRequest.onsuccess = function(e) {
|
|
|
|
navigator.mozAlarms.remove(e.target.result);
|
|
|
|
|
2013-06-04 16:13:16 +00:00
|
|
|
ok(true, "Should be able to add alarm for already past date, which should fire immediately.");
|
2013-07-24 17:46:59 +00:00
|
|
|
|
|
|
|
// Move on to the next test.
|
|
|
|
testNullDate();
|
2013-03-18 22:47:30 +00:00
|
|
|
};
|
|
|
|
domRequest.onerror = function(e) {
|
2013-06-04 16:13:16 +00:00
|
|
|
ok(false, "Unable to add alarm for yesterday.");
|
2013-03-18 22:47:30 +00:00
|
|
|
|
2013-07-24 17:46:59 +00:00
|
|
|
// Move on to the next test.
|
|
|
|
testNullDate();
|
2013-03-18 22:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify passing null does indeed fail
|
2013-07-24 17:46:59 +00:00
|
|
|
function testNullDate() {
|
2013-03-18 22:47:30 +00:00
|
|
|
try {
|
2013-07-24 17:46:59 +00:00
|
|
|
navigator.mozAlarms.add(null, "honorTimezone", {});
|
|
|
|
ok(false, "Expected an exception to be thrown for alarm with null date.");
|
2013-03-18 22:47:30 +00:00
|
|
|
} catch(e) {
|
2013-07-24 17:46:59 +00:00
|
|
|
ok(true, "Exception thrown for alarm with null date.");
|
2013-03-18 22:47:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 17:46:59 +00:00
|
|
|
// Move on to the next test.
|
|
|
|
testInvalidTimeZone()
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInvalidTimeZone() {
|
|
|
|
try {
|
|
|
|
navigator.mozAlarms.add(new Date(), "badTimeZoneArg", {});
|
|
|
|
ok(false, "Expected an exception to be thrown while testing bad time zone arg.");
|
|
|
|
} catch(e) {
|
|
|
|
ok(true, "Exception thrown while testing bad time zone arg.");
|
|
|
|
}
|
|
|
|
SimpleTest.finish();
|
2013-03-18 22:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function startTests() {
|
|
|
|
|
|
|
|
SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
|
|
|
|
// Currently applicable only on FxOS
|
|
|
|
if (navigator.userAgent.indexOf("Mobile") != -1 &&
|
2013-07-24 17:46:59 +00:00
|
|
|
navigator.appVersion.indexOf("Android") == -1)
|
|
|
|
{
|
2013-03-18 22:47:30 +00:00
|
|
|
testFutureDate();
|
|
|
|
} else {
|
|
|
|
ok(true, "mozAlarms on Firefox OS only.");
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.expectAssertions(0, 9);
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
if (SpecialPowers.hasPermission("alarms", document)) {
|
|
|
|
startTests();
|
|
|
|
} else {
|
|
|
|
// Add the permissions and reload so they propogate
|
|
|
|
SpecialPowers.addPermission("alarms", true, document);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|