|
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"> |
|
15 |
|
16 var info = NotificationTest.info; |
|
17 |
|
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 }, |
|
26 |
|
27 function () { |
|
28 info("Test blank requestPermission"); |
|
29 Notification.requestPermission(); |
|
30 }, |
|
31 |
|
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 }, |
|
41 |
|
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 }, |
|
51 |
|
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 }, |
|
61 |
|
62 function (done) { |
|
63 info("Test create notification"); |
|
64 |
|
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); |
|
73 |
|
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"); |
|
80 |
|
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"); |
|
86 |
|
87 // store notification in test context |
|
88 this.notification = notification; |
|
89 |
|
90 notification.onshow = function () { |
|
91 ok(true, "onshow handler should be called"); |
|
92 done(); |
|
93 }; |
|
94 }, |
|
95 |
|
96 function (done) { |
|
97 info("Test closing a notification"); |
|
98 var notification = this.notification; |
|
99 |
|
100 notification.onclose = function () { |
|
101 ok(true, "onclose handler should be called"); |
|
102 done(); |
|
103 }; |
|
104 |
|
105 notification.close(); |
|
106 }, |
|
107 ]; |
|
108 |
|
109 MockServices.register(); |
|
110 NotificationTest.run(steps, function () { |
|
111 MockServices.unregister(); |
|
112 }); |
|
113 </script> |
|
114 </body> |
|
115 </html> |