2013-08-20 18:24:12 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-02-01 13:17:34 -08: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/. */
|
|
|
|
|
|
|
|
const { Loader } = require('sdk/test/loader');
|
|
|
|
|
2013-10-04 16:48:52 -07:00
|
|
|
exports.testOnClick = function (assert) {
|
2013-02-01 13:17:34 -08:00
|
|
|
let [loader, mockAlertServ] = makeLoader(module);
|
|
|
|
let notifs = loader.require("sdk/notifications");
|
|
|
|
let data = "test data";
|
|
|
|
let opts = {
|
|
|
|
onClick: function (clickedData) {
|
2013-10-04 16:48:52 -07:00
|
|
|
assert.equal(this, notifs, "|this| should be notifications module");
|
|
|
|
assert.equal(clickedData, data,
|
2013-02-01 13:17:34 -08: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();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns [loader, mockAlertService].
|
2013-10-04 16:48:52 -07:00
|
|
|
function makeLoader(module) {
|
2013-02-01 13:17:34 -08: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-04 16:48:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
require('sdk/test').run(exports);
|