| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: Requesting permission using the Promise return value.<
/title> | 4 <title>Notifications: Requesting permission using the Promise return value.<
/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 <script src="../resources/permissions-helper.js"></script> |
| 7 </head> | 8 </head> |
| 8 <body> | 9 <body> |
| 9 <script> | 10 <script> |
| 10 // Tests that Notification.requestPermission() returns a promise that will
be | 11 // Tests that Notification.requestPermission() returns a promise that will
be |
| 11 // resolved with the current permission level. This test cannot be ran man
ually | 12 // resolved with the current permission level. This test cannot be ran man
ually |
| 12 // because of the permission shifting going on. | 13 // because of the permission shifting going on. |
| 13 promise_test(test => { | 14 promise_test(test => { |
| 14 // Default value in layout tests is "denied". | 15 // Default value in layout tests is "denied". |
| 15 return Notification.requestPermission().then(permission => { | 16 return Notification.requestPermission().then(permission => { |
| 16 assert_equals(permission, 'denied'); | 17 assert_equals(permission, 'denied'); |
| 17 | 18 |
| 18 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 19 return PermissionsHelper.setPermission('notifications', 'granted'); |
| 20 }).then(function() { |
| 19 return Notification.requestPermission(); | 21 return Notification.requestPermission(); |
| 20 | |
| 21 }).then(permission => { | 22 }).then(permission => { |
| 22 assert_equals(permission, 'granted'); | 23 assert_equals(permission, 'granted'); |
| 23 }); | 24 }); |
| 24 | 25 |
| 25 }, 'Requesting permission returns a promise that will be resolved.'); | 26 }, 'Requesting permission returns a promise that will be resolved.'); |
| 26 | 27 |
| 27 // Tests that Notification.requestPermission() still invokes the callback
(before | 28 // Tests that Notification.requestPermission() still invokes the callback
(before |
| 28 // resolving the promise) and that the values are equal. Like the previous
test, | 29 // resolving the promise) and that the values are equal. Like the previous
test, |
| 29 // this cannot be ran manually. | 30 // this cannot be ran manually. |
| 30 promise_test(test => { | 31 promise_test(test => { |
| 31 var callbackPermission = 'undefined'; | 32 var callbackPermission = 'undefined'; |
| 32 | 33 |
| 33 function permissionCallback(value) { | 34 function permissionCallback(value) { |
| 34 callbackPermission = value; | 35 callbackPermission = value; |
| 35 } | 36 } |
| 36 | 37 |
| 37 testRunner.setPermission('notifications', 'denied', location.origin, loc
ation.origin); | 38 return PermissionsHelper.setPermission('notifications', 'denied').then(f
unction() { |
| 39 return Notification.requestPermission(permissionCallback).then(permiss
ion => { |
| 40 assert_equals(permission, 'denied'); |
| 41 assert_equals(permission, callbackPermission); |
| 38 | 42 |
| 39 return Notification.requestPermission(permissionCallback).then(permissio
n => { | 43 return PermissionsHelper.setPermission('notifications', 'granted'); |
| 40 assert_equals(permission, 'denied'); | 44 }).then(function() { |
| 41 assert_equals(permission, callbackPermission); | 45 return Notification.requestPermission(permissionCallback); |
| 42 | 46 }).then(permission => { |
| 43 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 47 assert_equals(permission, 'granted'); |
| 44 return Notification.requestPermission(permissionCallback); | 48 assert_equals(permission, callbackPermission); |
| 45 | 49 }); |
| 46 }).then(permission => { | 50 }) |
| 47 assert_equals(permission, 'granted'); | |
| 48 assert_equals(permission, callbackPermission); | |
| 49 }); | |
| 50 | |
| 51 }, 'Requesting permission returns a promise, maintains the callback behavi
our.'); | 51 }, 'Requesting permission returns a promise, maintains the callback behavi
our.'); |
| 52 </script> | 52 </script> |
| 53 </body> | 53 </body> |
| 54 </html> | 54 </html> |
| OLD | NEW |