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 if (window.testRunner) | 13 // This test is doing some hacks to make sure the internal representation |
| 14 // is correctly updated before calling Notification.permission because |
| 15 // testRunner.setPermission() and Notification.permission might end up |
| 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."); |
| 23 |
| 24 var testIndex = 0; |
| 25 var tests = [ |
| 26 function() { |
| 27 testRunner.setPermission('notifications', 'prompt', location.origin, l
ocation.origin); |
| 28 testRunner.clearWebNotificationPermissions(); |
| 29 |
| 30 navigator.permissions.query({name:'notifications'}).then(function() { |
| 31 // "default" indicates that no permission request has been answered. |
| 32 assert_equals(Notification.permission, 'default'); |
| 33 |
| 34 notificationsPermissionsTest.step(tests[++testIndex]); |
| 35 }); |
| 36 }, |
| 37 function() { |
| 38 testRunner.setPermission('notifications', 'denied', location.origin, l
ocation.origin); |
| 39 testRunner.grantWebNotificationPermission(location.origin, false); |
| 40 |
| 41 navigator.permissions.query({name:'notifications'}).then(function() { |
| 42 // "default" indicates that no permission request has been answered. |
| 43 assert_equals(Notification.permission, 'denied'); |
| 44 |
| 45 notificationsPermissionsTest.step(tests[++testIndex]); |
| 46 }); |
| 47 }, |
| 48 function () { |
| 49 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
14 testRunner.grantWebNotificationPermission(location.origin, true); | 50 testRunner.grantWebNotificationPermission(location.origin, true); |
15 | 51 |
16 test(function () { | 52 navigator.permissions.query({name:'notifications'}).then(function() { |
17 if (!window.testRunner) { | 53 // "default" indicates that no permission request has been answered. |
18 assert_unreached('This test requires the TestRunner for working co
rrectly.'); | 54 assert_equals(Notification.permission, 'granted'); |
19 return; | |
20 } | |
21 | 55 |
22 testRunner.clearWebNotificationPermissions(); | 56 notificationsPermissionsTest.step(tests[++testIndex]); |
| 57 }); |
| 58 }, |
| 59 function () { |
| 60 notificationsPermissionsTest.done(); |
| 61 } |
| 62 ]; |
23 | 63 |
24 // "default" indicates that no permission request has been answered. | 64 notificationsPermissionsTest.step(function() { |
25 assert_equals(Notification.permission, "default"); | 65 if (!window.testRunner) { |
26 | 66 assert_unreached('This test requires the TestRunner for working corr
ectly.'); |
27 testRunner.grantWebNotificationPermission(location.origin, false); | 67 return; |
28 assert_equals(Notification.permission, "denied"); | 68 } |
29 | 69 notificationsPermissionsTest.step(tests[testIndex]); |
30 testRunner.grantWebNotificationPermission(location.origin, true); | 70 }); |
31 assert_equals(Notification.permission, "granted"); | |
32 | |
33 }, 'Notification.permission reflects the actual permission level.'); | |
34 </script> | 71 </script> |
35 </body> | 72 </body> |
36 </html> | 73 </html> |
OLD | NEW |