dom/tests/mochitest/notification/test_notification_basics.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial