dom/tests/mochitest/notification/NotificationTest.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 var NotificationTest = (function () {
     2   "use strict";
     4   function info(msg, name) {
     5     SimpleTest.info("::Notification Tests::" + (name || ""), msg);
     6   }
     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   }
    14   function teardown_testing_env() {
    15     SimpleTest.finish();
    16   }
    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 = {};
    23     (function executeRemainingTests(remainingTests) {
    24       if (!remainingTests.length) {
    25         return callback();
    26       }
    28       var nextTest = remainingTests.shift();
    29       var finishTest = executeRemainingTests.bind(null, remainingTests);
    30       var startTest = nextTest.call.bind(nextTest, context, finishTest);
    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   }
    46   // NotificationTest API
    47   return {
    48     run: function (tests, callback) {
    49       setup_testing_env();
    51       addLoadEvent(function () {
    52         executeTests(tests, function () {
    53           teardown_testing_env();
    54           callback && callback();
    55         });
    56       });
    57     },
    59     allowNotifications: function () {
    60       SpecialPowers.setBoolPref("notification.prompt.testing.allow", true);
    61     },
    63     denyNotifications: function () {
    64       SpecialPowers.setBoolPref("notification.prompt.testing.allow", false);
    65     },
    67     clickNotification: function (notification) {
    68       // TODO: how??
    69     },
    71     info: info
    72   };
    73 })();

mercurial