dom/tests/mochitest/notification/NotificationTest.js

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:fe79edd2eb66
1 var NotificationTest = (function () {
2 "use strict";
3
4 function info(msg, name) {
5 SimpleTest.info("::Notification Tests::" + (name || ""), msg);
6 }
7
8 function setup_testing_env() {
9 SimpleTest.waitForExplicitFinish();
10 // turn on testing pref (used by notification.cpp, and mock the alerts
11 SpecialPowers.setBoolPref("notification.prompt.testing", true);
12 }
13
14 function teardown_testing_env() {
15 SimpleTest.finish();
16 }
17
18 function executeTests(tests, callback) {
19 // context is `this` object in test functions
20 // it can be used to track data between tests
21 var context = {};
22
23 (function executeRemainingTests(remainingTests) {
24 if (!remainingTests.length) {
25 return callback();
26 }
27
28 var nextTest = remainingTests.shift();
29 var finishTest = executeRemainingTests.bind(null, remainingTests);
30 var startTest = nextTest.call.bind(nextTest, context, finishTest);
31
32 try {
33 startTest();
34 // if no callback was defined for test function,
35 // we must manually invoke finish to continue
36 if (nextTest.length === 0) {
37 finishTest();
38 }
39 } catch (e) {
40 ok(false, "Test threw exception!");
41 finishTest();
42 }
43 })(tests);
44 }
45
46 // NotificationTest API
47 return {
48 run: function (tests, callback) {
49 setup_testing_env();
50
51 addLoadEvent(function () {
52 executeTests(tests, function () {
53 teardown_testing_env();
54 callback && callback();
55 });
56 });
57 },
58
59 allowNotifications: function () {
60 SpecialPowers.setBoolPref("notification.prompt.testing.allow", true);
61 },
62
63 denyNotifications: function () {
64 SpecialPowers.setBoolPref("notification.prompt.testing.allow", false);
65 },
66
67 clickNotification: function (notification) {
68 // TODO: how??
69 },
70
71 info: info
72 };
73 })();

mercurial