diff --git a/dom/alarm/AlarmsManager.js b/dom/alarm/AlarmsManager.js index 9e5ff0becf3f..edefcb01cbdc 100644 --- a/dom/alarm/AlarmsManager.js +++ b/dom/alarm/AlarmsManager.js @@ -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, diff --git a/dom/alarm/test/test_alarm_add_date.html b/dom/alarm/test/test_alarm_add_date.html index 4acb9d85658e..fb724b87c3f7 100644 --- a/dom/alarm/test/test_alarm_add_date.html +++ b/dom/alarm/test/test_alarm_add_date.html @@ -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(); } - }); }