4 <title>Notifications: Requesting permission using the Promise return value.
</title>
5 <script src=
"../resources/testharness.js"></script>
6 <script src=
"../resources/testharnessreport.js"></script>
7 <script src=
"../resources/permissions-helper.js"></script>
11 // Tests that Notification.requestPermission() returns a promise that will be
12 // resolved with the current permission level. This test cannot be ran manually
13 // because of the permission shifting going on.
14 promise_test(test
=> {
15 // Default value in layout tests is "denied".
16 return Notification
.requestPermission().then(permission
=> {
17 assert_equals(permission
, 'denied');
19 return PermissionsHelper
.setPermission('notifications', 'granted');
21 return Notification
.requestPermission();
22 }).then(permission
=> {
23 assert_equals(permission
, 'granted');
26 }, 'Requesting permission returns a promise that will be resolved.');
28 // Tests that Notification.requestPermission() still invokes the callback (before
29 // resolving the promise) and that the values are equal. Like the previous test,
30 // this cannot be ran manually.
31 promise_test(test
=> {
32 var callbackPermission
= 'undefined';
34 function permissionCallback(value
) {
35 callbackPermission
= value
;
38 return PermissionsHelper
.setPermission('notifications', 'denied').then(function() {
39 return Notification
.requestPermission(permissionCallback
).then(permission
=> {
40 assert_equals(permission
, 'denied');
41 assert_equals(permission
, callbackPermission
);
43 return PermissionsHelper
.setPermission('notifications', 'granted');
45 return Notification
.requestPermission(permissionCallback
);
46 }).then(permission
=> {
47 assert_equals(permission
, 'granted');
48 assert_equals(permission
, callbackPermission
);
51 }, 'Requesting permission returns a promise, maintains the callback behaviour.');