Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
bug 895693 - notify title, text accept numbers
Browse files Browse the repository at this point in the history
and iconURL accepts URL instances.
plus a new test to confirm that.
  • Loading branch information
zombie committed Nov 17, 2013
1 parent ff9fec5 commit a71988f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/sdk/notifications.js
Expand Up @@ -11,6 +11,8 @@ module.metadata = {
const { Cc, Ci, Cr } = require("chrome");
const apiUtils = require("./deprecated/api-utils");
const errors = require("./deprecated/errors");
const { isString, isUndefined, instanceOf } = require('./lang/type');
const { URL } = require('./url');

try {
let alertServ = Cc["@mozilla.org/alerts-service;1"].
Expand Down Expand Up @@ -66,16 +68,20 @@ function validateOptions(options) {
is: ["string", "undefined"]
},
iconURL: {
is: ["string", "undefined"]
is: ["string", "undefined", "object"],
ok: function(value) {
return isUndefined(value) || isString(value) || (value instanceof URL);
},
msg: "`iconURL` must be a string or an URL instance."
},
onClick: {
is: ["function", "undefined"]
},
text: {
is: ["string", "undefined"]
is: ["string", "undefined", "number"]
},
title: {
is: ["string", "undefined"]
}
is: ["string", "undefined", "number"]
},
});
}
18 changes: 18 additions & 0 deletions test/test-notifications.js
Expand Up @@ -24,6 +24,24 @@ exports.testOnClick = function (assert) {
loader.unload();
};

exports['test:numbers and URLs in options'] = function(assert) {
let [loader] = makeLoader(module);
let notifs = loader.require('sdk/notifications');
let opts = {
title: 123,
text: 45678,
// must use in-loader `sdk/url` module for the validation type check to work
iconURL: loader.require('sdk/url').URL('data:image/png,blah')
};
try {
notifs.notify(opts);
assert.pass('using numbers and URLs in options works');
} catch (e) {
assert.fail('using numbers and URLs in options should not throw');
}
loader.unload();
}

// Returns [loader, mockAlertService].
function makeLoader(module) {
let loader = Loader(module);
Expand Down

0 comments on commit a71988f

Please sign in to comment.