dom/tests/mochitest/notification/test_notification_basics.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/notification/test_notification_basics.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Notification Basics</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="MockServices.js"></script>
    1.10 +  <script type="text/javascript" src="NotificationTest.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body>
    1.14 +<p id="display"></p>
    1.15 +<div id="content" style="display: none"></div>
    1.16 +<pre id="test"></pre>
    1.17 +<script type="text/javascript">
    1.18 +
    1.19 +  var info = NotificationTest.info;
    1.20 +
    1.21 +  var steps = [
    1.22 +    function () {
    1.23 +      info("Test notification spec");
    1.24 +      ok(Notification, "Notification constructor exists");
    1.25 +      ok(Notification.permission, "Notification.permission exists");
    1.26 +      ok(Notification.requestPermission, "Notification.requestPermission exists");
    1.27 +      ok(Notification.get, "Notification.get exists");
    1.28 +    },
    1.29 +
    1.30 +    function () {
    1.31 +      info("Test blank requestPermission");
    1.32 +      Notification.requestPermission();
    1.33 +    },
    1.34 +
    1.35 +    function (done) {
    1.36 +      info("Test requestPermission deny");
    1.37 +      NotificationTest.denyNotifications();
    1.38 +      Notification.requestPermission(function(perm) {
    1.39 +        is(perm, "denied", "Permission should be denied.");
    1.40 +        is(Notification.permission, "denied", "Permission should be denied.");
    1.41 +        done();
    1.42 +      });
    1.43 +    },
    1.44 +
    1.45 +    function (done) {
    1.46 +      info("Test requestPermission grant");
    1.47 +      NotificationTest.allowNotifications();
    1.48 +      Notification.requestPermission(function (perm) {
    1.49 +        is(perm, "granted", "Permission should be granted.");
    1.50 +        is(Notification.permission, "granted", "Permission should be granted");
    1.51 +        done();
    1.52 +      });
    1.53 +    },
    1.54 +
    1.55 +    function () {
    1.56 +      info("Test invalid requestPermission");
    1.57 +      try {
    1.58 +        Notification.requestPermission({});
    1.59 +        ok(false, "Non callable arg to requestPermission should throw");
    1.60 +      } catch (e) {
    1.61 +        ok(true, "Non callable arg to requestPermission should throw");
    1.62 +      }
    1.63 +    },
    1.64 +
    1.65 +    function (done) {
    1.66 +      info("Test create notification");
    1.67 +
    1.68 +      var options = {
    1.69 +        dir: "auto",
    1.70 +        lang: "",
    1.71 +        body: "This is a notification body",
    1.72 +        tag: "sometag",
    1.73 +        icon: "icon.png"
    1.74 +      };
    1.75 +      var notification = new Notification("This is a title", options);
    1.76 +
    1.77 +      ok(notification, "Notification exists");
    1.78 +      is(notification.onclick, null, "onclick() should be null");
    1.79 +      is(notification.onshow, null, "onshow() should be null");
    1.80 +      is(notification.onerror, null, "onerror() should be null");
    1.81 +      is(notification.onclose, null, "onclose() should be null");
    1.82 +      is(typeof notification.close, "function", "close() should exist");
    1.83 +
    1.84 +      is(notification.dir, options.dir, "auto should get set");
    1.85 +      is(notification.lang, options.lang, "lang should get set");
    1.86 +      is(notification.body, options.body, "body should get set");
    1.87 +      is(notification.tag, options.tag, "tag should get set");
    1.88 +      is(notification.icon, options.icon, "icon should get set");
    1.89 +
    1.90 +      // store notification in test context
    1.91 +      this.notification = notification;
    1.92 +
    1.93 +      notification.onshow = function () {
    1.94 +        ok(true, "onshow handler should be called");
    1.95 +        done();
    1.96 +      };
    1.97 +    },
    1.98 +
    1.99 +    function (done) {
   1.100 +      info("Test closing a notification");
   1.101 +      var notification = this.notification;
   1.102 +
   1.103 +      notification.onclose = function () {
   1.104 +        ok(true, "onclose handler should be called");
   1.105 +        done();
   1.106 +      };
   1.107 +
   1.108 +      notification.close();
   1.109 +    },
   1.110 +  ];
   1.111 +
   1.112 +  MockServices.register();
   1.113 +  NotificationTest.run(steps, function () {
   1.114 +    MockServices.unregister();
   1.115 +  });
   1.116 +</script>
   1.117 +</body>
   1.118 +</html>

mercurial