1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/notification/NotificationTest.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +var NotificationTest = (function () { 1.5 + "use strict"; 1.6 + 1.7 + function info(msg, name) { 1.8 + SimpleTest.info("::Notification Tests::" + (name || ""), msg); 1.9 + } 1.10 + 1.11 + function setup_testing_env() { 1.12 + SimpleTest.waitForExplicitFinish(); 1.13 + // turn on testing pref (used by notification.cpp, and mock the alerts 1.14 + SpecialPowers.setBoolPref("notification.prompt.testing", true); 1.15 + } 1.16 + 1.17 + function teardown_testing_env() { 1.18 + SimpleTest.finish(); 1.19 + } 1.20 + 1.21 + function executeTests(tests, callback) { 1.22 + // context is `this` object in test functions 1.23 + // it can be used to track data between tests 1.24 + var context = {}; 1.25 + 1.26 + (function executeRemainingTests(remainingTests) { 1.27 + if (!remainingTests.length) { 1.28 + return callback(); 1.29 + } 1.30 + 1.31 + var nextTest = remainingTests.shift(); 1.32 + var finishTest = executeRemainingTests.bind(null, remainingTests); 1.33 + var startTest = nextTest.call.bind(nextTest, context, finishTest); 1.34 + 1.35 + try { 1.36 + startTest(); 1.37 + // if no callback was defined for test function, 1.38 + // we must manually invoke finish to continue 1.39 + if (nextTest.length === 0) { 1.40 + finishTest(); 1.41 + } 1.42 + } catch (e) { 1.43 + ok(false, "Test threw exception!"); 1.44 + finishTest(); 1.45 + } 1.46 + })(tests); 1.47 + } 1.48 + 1.49 + // NotificationTest API 1.50 + return { 1.51 + run: function (tests, callback) { 1.52 + setup_testing_env(); 1.53 + 1.54 + addLoadEvent(function () { 1.55 + executeTests(tests, function () { 1.56 + teardown_testing_env(); 1.57 + callback && callback(); 1.58 + }); 1.59 + }); 1.60 + }, 1.61 + 1.62 + allowNotifications: function () { 1.63 + SpecialPowers.setBoolPref("notification.prompt.testing.allow", true); 1.64 + }, 1.65 + 1.66 + denyNotifications: function () { 1.67 + SpecialPowers.setBoolPref("notification.prompt.testing.allow", false); 1.68 + }, 1.69 + 1.70 + clickNotification: function (notification) { 1.71 + // TODO: how?? 1.72 + }, 1.73 + 1.74 + info: info 1.75 + }; 1.76 +})();