gecko/dom/tests/mochitest/notification/NotificationTest.js
Michael Henretty 6ee42939de Bug 899574 - Part 2, add Notification.get() with notification storage. r=bent
--HG--
rename : dom/tests/mochitest/notification/create_notification.html => dom/tests/mochitest/notification/desktop-notification/create_notification.html
rename : dom/tests/mochitest/notification/notification_common.js => dom/tests/mochitest/notification/desktop-notification/notification_common.js
rename : dom/tests/mochitest/notification/test_basic_notification.html => dom/tests/mochitest/notification/desktop-notification/test_basic_notification.html
rename : dom/tests/mochitest/notification/test_basic_notification_click.html => dom/tests/mochitest/notification/desktop-notification/test_basic_notification_click.html
rename : dom/tests/mochitest/notification/test_leak_windowClose.html => dom/tests/mochitest/notification/desktop-notification/test_leak_windowClose.html
rename : dom/tests/mochitest/notification/test_notification_tag.html => dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html
rename : dom/tests/mochitest/notification/test_system_principal.xul => dom/tests/mochitest/notification/desktop-notification/test_system_principal.xul
2013-10-02 18:27:53 -07:00

74 lines
1.8 KiB
JavaScript

var NotificationTest = (function () {
"use strict";
function info(msg, name) {
SimpleTest.info("::Notification Tests::" + (name || ""), msg);
}
function setup_testing_env() {
SimpleTest.waitForExplicitFinish();
// turn on testing pref (used by notification.cpp, and mock the alerts
SpecialPowers.setBoolPref("notification.prompt.testing", true);
}
function teardown_testing_env() {
SimpleTest.finish();
}
function executeTests(tests, callback) {
// context is `this` object in test functions
// it can be used to track data between tests
var context = {};
(function executeRemainingTests(remainingTests) {
if (!remainingTests.length) {
return callback();
}
var nextTest = remainingTests.shift();
var finishTest = executeRemainingTests.bind(null, remainingTests);
var startTest = nextTest.call.bind(nextTest, context, finishTest);
try {
startTest();
// if no callback was defined for test function,
// we must manually invoke finish to continue
if (nextTest.length === 0) {
finishTest();
}
} catch (e) {
ok(false, "Test threw exception!");
finishTest();
}
})(tests);
}
// NotificationTest API
return {
run: function (tests, callback) {
setup_testing_env();
addLoadEvent(function () {
executeTests(tests, function () {
teardown_testing_env();
callback && callback();
});
});
},
allowNotifications: function () {
SpecialPowers.setBoolPref("notification.prompt.testing.allow", true);
},
denyNotifications: function () {
SpecialPowers.setBoolPref("notification.prompt.testing.allow", false);
},
clickNotification: function (notification) {
// TODO: how??
},
info: info
};
})();