dom/tests/mochitest/notification/test_notification_basics.html

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 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Notification Basics</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="MockServices.js"></script>
     7   <script type="text/javascript" src="NotificationTest.js"></script>
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     9 </head>
    10 <body>
    11 <p id="display"></p>
    12 <div id="content" style="display: none"></div>
    13 <pre id="test"></pre>
    14 <script type="text/javascript">
    16   var info = NotificationTest.info;
    18   var steps = [
    19     function () {
    20       info("Test notification spec");
    21       ok(Notification, "Notification constructor exists");
    22       ok(Notification.permission, "Notification.permission exists");
    23       ok(Notification.requestPermission, "Notification.requestPermission exists");
    24       ok(Notification.get, "Notification.get exists");
    25     },
    27     function () {
    28       info("Test blank requestPermission");
    29       Notification.requestPermission();
    30     },
    32     function (done) {
    33       info("Test requestPermission deny");
    34       NotificationTest.denyNotifications();
    35       Notification.requestPermission(function(perm) {
    36         is(perm, "denied", "Permission should be denied.");
    37         is(Notification.permission, "denied", "Permission should be denied.");
    38         done();
    39       });
    40     },
    42     function (done) {
    43       info("Test requestPermission grant");
    44       NotificationTest.allowNotifications();
    45       Notification.requestPermission(function (perm) {
    46         is(perm, "granted", "Permission should be granted.");
    47         is(Notification.permission, "granted", "Permission should be granted");
    48         done();
    49       });
    50     },
    52     function () {
    53       info("Test invalid requestPermission");
    54       try {
    55         Notification.requestPermission({});
    56         ok(false, "Non callable arg to requestPermission should throw");
    57       } catch (e) {
    58         ok(true, "Non callable arg to requestPermission should throw");
    59       }
    60     },
    62     function (done) {
    63       info("Test create notification");
    65       var options = {
    66         dir: "auto",
    67         lang: "",
    68         body: "This is a notification body",
    69         tag: "sometag",
    70         icon: "icon.png"
    71       };
    72       var notification = new Notification("This is a title", options);
    74       ok(notification, "Notification exists");
    75       is(notification.onclick, null, "onclick() should be null");
    76       is(notification.onshow, null, "onshow() should be null");
    77       is(notification.onerror, null, "onerror() should be null");
    78       is(notification.onclose, null, "onclose() should be null");
    79       is(typeof notification.close, "function", "close() should exist");
    81       is(notification.dir, options.dir, "auto should get set");
    82       is(notification.lang, options.lang, "lang should get set");
    83       is(notification.body, options.body, "body should get set");
    84       is(notification.tag, options.tag, "tag should get set");
    85       is(notification.icon, options.icon, "icon should get set");
    87       // store notification in test context
    88       this.notification = notification;
    90       notification.onshow = function () {
    91         ok(true, "onshow handler should be called");
    92         done();
    93       };
    94     },
    96     function (done) {
    97       info("Test closing a notification");
    98       var notification = this.notification;
   100       notification.onclose = function () {
   101         ok(true, "onclose handler should be called");
   102         done();
   103       };
   105       notification.close();
   106     },
   107   ];
   109   MockServices.register();
   110   NotificationTest.run(steps, function () {
   111     MockServices.unregister();
   112   });
   113 </script>
   114 </body>
   115 </html>

mercurial