Bug 879308 - null date to mozAlarms.add throws exception. r=nsm sr=mounir

--HG--
extra : rebase_source : 538259df2de7483e277e59de8edcefe94f04c0a9
This commit is contained in:
Mina Almasry 2013-07-24 10:46:59 -07:00
parent 2c00aaf97f
commit 783d0e604b
2 changed files with 38 additions and 31 deletions

View File

@ -53,6 +53,10 @@ AlarmsManager.prototype = {
throw Components.results.NS_ERROR_FAILURE;
}
if (!aDate) {
throw Components.results.NS_ERROR_INVALID_ARG;
}
let isIgnoreTimezone = true;
switch (aRespectTimezone) {
case "honorTimezone":
@ -64,13 +68,13 @@ AlarmsManager.prototype = {
break;
default:
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
throw Components.results.NS_ERROR_INVALID_ARG;
break;
}
let request = this.createRequest();
this._cpmm.sendAsyncMessage(
"AlarmsManager:Add",
"AlarmsManager:Add",
{ requestId: this.getRequestId(request),
date: aDate,
ignoreTimezone: isIgnoreTimezone,

View File

@ -25,23 +25,26 @@
} catch (e) {
ok(false,
"Unexpected exception trying to add alarm for tomorrow.");
// Proceed to next test.
return testPastDate();
}
domRequest.onsuccess = function(e) {
navigator.mozAlarms.remove(e.target.result);
ok(true, "Add alarm for future date.");
// Awesome, no error so proceed to next test
// Awesome, no error so proceed to next test.
testPastDate();
};
domRequest.onerror = function(e) {
ok(false, "Unable to add alarm for tomorrow`.");
// Proceed to next test.
testPastDate();
};
}
// Verify passing a Date that's already past fails
// Verify passing a Date that's already past doesn't fail (it should fire immediately).
function testPastDate() {
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
@ -52,61 +55,61 @@
} catch (e) {
ok(false,
"Unexpected exception trying to add alarm for yesterday.");
return testNull();
// Move on to the next test.
testNullDate();
}
domRequest.onsuccess = function(e) {
navigator.mozAlarms.remove(e.target.result);
ok(true, "Should be able to add alarm for already past date, which should fire immediately.");
testNull();
// Move on to the next test.
testNullDate();
};
domRequest.onerror = function(e) {
ok(false, "Unable to add alarm for yesterday.");
// Errors as it should, on to the next test
testNull();
// Move on to the next test.
testNullDate();
}
}
// Verify passing null does indeed fail
function testNull() {
var domRequest;
function testNullDate() {
try {
domRequest = navigator.mozAlarms.add(null, "honorTimezone", {});
navigator.mozAlarms.add(null, "honorTimezone", {});
ok(false, "Expected an exception to be thrown for alarm with null date.");
} catch(e) {
ok(false, "Unexpected exception thrown while testing null case.");
// Exception thrown
return SimpleTest.finish();
ok(true, "Exception thrown for alarm with null date.");
}
domRequest.onsuccess = function(e) {
// Null should not be valid
ok(false, "Null should not be accepted as input for `date` param.");
SimpleTest.finish();
};
domRequest.onerror = function(e) {
// Null should not be valid
ok(true, "Passing null for date value causes failure.");
SimpleTest.finish();
};
// 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();
}
function startTests() {
SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
// Currently applicable only on FxOS
if (navigator.userAgent.indexOf("Mobile") != -1 &&
navigator.appVersion.indexOf("Android") == -1) {
navigator.appVersion.indexOf("Android") == -1)
{
testFutureDate();
} else {
ok(true, "mozAlarms on Firefox OS only.");
SimpleTest.finish();
}
});
}