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