2013-08-21 05:24:12 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-02-02 01:17:34 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2015-04-24 22:36:06 +03:00
|
|
|
"use strict";
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
const { Loader } = require('sdk/test/loader');
|
|
|
|
|
2015-04-24 22:36:06 +03:00
|
|
|
exports["test onClick"] = function(assert) {
|
2013-02-02 01:17:34 +04:00
|
|
|
let [loader, mockAlertServ] = makeLoader(module);
|
|
|
|
let notifs = loader.require("sdk/notifications");
|
|
|
|
let data = "test data";
|
|
|
|
let opts = {
|
|
|
|
onClick: function (clickedData) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(this, notifs, "|this| should be notifications module");
|
|
|
|
assert.equal(clickedData, data,
|
2013-02-02 01:17:34 +04:00
|
|
|
"data passed to onClick should be correct");
|
|
|
|
},
|
|
|
|
data: data,
|
|
|
|
title: "test title",
|
|
|
|
text: "test text",
|
|
|
|
iconURL: "test icon URL"
|
|
|
|
};
|
|
|
|
notifs.notify(opts);
|
|
|
|
mockAlertServ.click();
|
|
|
|
loader.unload();
|
|
|
|
};
|
|
|
|
|
2015-04-24 22:36:06 +03:00
|
|
|
exports['test numbers and URLs in options'] = function(assert) {
|
2013-11-28 04:43:04 +04:00
|
|
|
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 must not throw');
|
|
|
|
}
|
|
|
|
loader.unload();
|
|
|
|
}
|
|
|
|
|
2015-04-24 22:36:06 +03:00
|
|
|
exports['test new tag, dir and lang options'] = function(assert) {
|
2013-11-28 04:43:04 +04:00
|
|
|
let [loader] = makeLoader(module);
|
|
|
|
let notifs = loader.require('sdk/notifications');
|
|
|
|
let opts = {
|
|
|
|
title: 'best',
|
|
|
|
tag: 'tagging',
|
|
|
|
lang: 'en'
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
opts.dir = 'ttb';
|
|
|
|
notifs.notify(opts);
|
|
|
|
assert.fail('`dir` option must not accept TopToBottom direction.');
|
|
|
|
} catch (e) {
|
2015-04-24 22:36:06 +03:00
|
|
|
assert.equal(e.message,
|
2013-11-28 04:43:04 +04:00
|
|
|
'`dir` option must be one of: "auto", "ltr" or "rtl".');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
opts.dir = 'rtl';
|
|
|
|
notifs.notify(opts);
|
|
|
|
assert.pass('`dir` option accepts "rtl" direction.');
|
|
|
|
} catch (e) {
|
|
|
|
assert.fail('`dir` option must accept "rtl" direction.');
|
|
|
|
}
|
|
|
|
|
|
|
|
loader.unload();
|
|
|
|
}
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Returns [loader, mockAlertService].
|
2013-10-05 03:48:52 +04:00
|
|
|
function makeLoader(module) {
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = Loader(module);
|
|
|
|
let mockAlertServ = {
|
|
|
|
showAlertNotification: function (imageUrl, title, text, textClickable,
|
|
|
|
cookie, alertListener, name) {
|
|
|
|
this._cookie = cookie;
|
|
|
|
this._alertListener = alertListener;
|
|
|
|
},
|
|
|
|
click: function () {
|
|
|
|
this._alertListener.observe(null, "alertclickcallback", this._cookie);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
loader.require("sdk/notifications");
|
|
|
|
let scope = loader.sandbox("sdk/notifications");
|
|
|
|
scope.notify = mockAlertServ.showAlertNotification.bind(mockAlertServ);
|
|
|
|
return [loader, mockAlertServ];
|
2013-10-05 03:48:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
require('sdk/test').run(exports);
|