OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Notifications: The Notification.permission property reflects the perm
ission status.</title> | 4 <title>Notifications: The Notification.permission property reflects the perm
ission status.</title> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
7 </head> | 7 </head> |
8 <body> | 8 <body> |
9 <script> | 9 <script> |
10 // Tests that the Notification.permission property reflects the current | 10 // Tests that the Notification.permission property reflects the current |
11 // permission level of notifications for the current origin. This test | 11 // permission level of notifications for the current origin. This test |
12 // requires the TestRunner. | 12 // requires the TestRunner. |
13 // This test is doing some hacks to make sure the internal representation | 13 // This test is doing some hacks to make sure the internal representation |
14 // is correctly updated before calling Notification.permission because | 14 // is correctly updated before calling Notification.permission because |
15 // testRunner.setPermission() and Notification.permission might end up | 15 // testRunner.setPermission() and Notification.permission might end up |
16 // in a race given the synchronous aspect of the latter. | 16 // in a race given the synchronous aspect of the latter. |
17 if (window.testRunner) { | |
18 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | |
19 testRunner.grantWebNotificationPermission(location.origin, true); | |
20 } | |
21 | |
22 var notificationsPermissionsTest = async_test("Notification.permission ref
lects th actual permission."); | 17 var notificationsPermissionsTest = async_test("Notification.permission ref
lects th actual permission."); |
23 | 18 |
24 var testIndex = 0; | 19 var testIndex = 0; |
25 var tests = [ | 20 var tests = [ |
26 function() { | 21 function() { |
27 testRunner.setPermission('notifications', 'prompt', location.origin, l
ocation.origin); | 22 testRunner.setPermission('notifications', 'prompt', location.origin, l
ocation.origin); |
28 testRunner.clearWebNotificationPermissions(); | |
29 | |
30 navigator.permissions.query({name:'notifications'}).then(function() { | 23 navigator.permissions.query({name:'notifications'}).then(function() { |
31 // "default" indicates that no permission request has been answered. | 24 // "default" indicates that no permission request has been answered. |
32 assert_equals(Notification.permission, 'default'); | 25 assert_equals(Notification.permission, 'default'); |
33 | 26 |
34 notificationsPermissionsTest.step(tests[++testIndex]); | 27 notificationsPermissionsTest.step(tests[++testIndex]); |
35 }); | 28 }); |
36 }, | 29 }, |
37 function() { | 30 function() { |
38 testRunner.setPermission('notifications', 'denied', location.origin, l
ocation.origin); | 31 testRunner.setPermission('notifications', 'denied', location.origin, l
ocation.origin); |
39 testRunner.grantWebNotificationPermission(location.origin, false); | |
40 | |
41 navigator.permissions.query({name:'notifications'}).then(function() { | 32 navigator.permissions.query({name:'notifications'}).then(function() { |
42 // "default" indicates that no permission request has been answered. | 33 // "default" indicates that no permission request has been answered. |
43 assert_equals(Notification.permission, 'denied'); | 34 assert_equals(Notification.permission, 'denied'); |
44 | 35 |
45 notificationsPermissionsTest.step(tests[++testIndex]); | 36 notificationsPermissionsTest.step(tests[++testIndex]); |
46 }); | 37 }); |
47 }, | 38 }, |
48 function () { | 39 function () { |
49 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 40 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
50 testRunner.grantWebNotificationPermission(location.origin, true); | |
51 | |
52 navigator.permissions.query({name:'notifications'}).then(function() { | 41 navigator.permissions.query({name:'notifications'}).then(function() { |
53 // "default" indicates that no permission request has been answered. | 42 // "default" indicates that no permission request has been answered. |
54 assert_equals(Notification.permission, 'granted'); | 43 assert_equals(Notification.permission, 'granted'); |
55 | 44 |
56 notificationsPermissionsTest.step(tests[++testIndex]); | 45 notificationsPermissionsTest.step(tests[++testIndex]); |
57 }); | 46 }); |
58 }, | 47 }, |
59 function () { | 48 function () { |
60 notificationsPermissionsTest.done(); | 49 notificationsPermissionsTest.done(); |
61 } | 50 } |
62 ]; | 51 ]; |
63 | 52 |
64 notificationsPermissionsTest.step(function() { | 53 notificationsPermissionsTest.step(function() { |
65 if (!window.testRunner) { | 54 if (!window.testRunner) { |
66 assert_unreached('This test requires the TestRunner for working corr
ectly.'); | 55 assert_unreached('This test requires the TestRunner for working corr
ectly.'); |
67 return; | 56 return; |
68 } | 57 } |
69 notificationsPermissionsTest.step(tests[testIndex]); | 58 notificationsPermissionsTest.step(tests[testIndex]); |
70 }); | 59 }); |
71 </script> | 60 </script> |
72 </body> | 61 </body> |
73 </html> | 62 </html> |
OLD | NEW |