1 if (self
.importScripts
) {
2 importScripts('helpers.js');
4 if (get_current_scope() == 'ServiceWorker')
5 importScripts('../../serviceworker/resources/worker-testharness.js');
7 importScripts('../../resources/testharness.js');
10 async_test(function(test
) {
11 // Querying a random permission name should fail.
12 navigator
.permissions
.query({name
:'foobar'}).then(function(result
) {
13 assert_unreached('querying a random permission should fail');
15 assert_equals(error
.name
, 'TypeError');
17 // Querying a permission without a name should fail.
18 return navigator
.permissions
.query({});
19 }).then(function(result
) {
20 assert_unreached('querying a permission without a name should fail');
22 assert_equals(error
.name
, 'TypeError');
25 }, 'Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope.');
27 async_test(function(test
) {
28 navigator
.permissions
.query({name
:'geolocation'}).then(function(result
) {
29 assert_true(result
instanceof PermissionStatus
);
30 assert_equals(result
.state
, 'denied');
33 assert_unreached('querying geolocation permission should not fail.')
35 }, 'Test geolocation permission in ' + get_current_scope() + ' scope.');
37 async_test(function(test
) {
38 navigator
.permissions
.query({name
:'midi'}).then(function(result
) {
39 assert_true(result
instanceof PermissionStatus
);
40 assert_equals(result
.state
, 'denied');
42 // Test for sysex=false.
43 return navigator
.permissions
.query({name
:'midi', sysex
: false});
44 }).then(function(result
) {
45 assert_true(result
instanceof PermissionStatus
);
46 assert_equals(result
.state
, 'denied');
48 // Test for sysex=true.
49 return navigator
.permissions
.query({name
:'midi', sysex
: true});
50 }).then(function(result
) {
51 assert_true(result
instanceof PermissionStatus
);
52 assert_equals(result
.state
, 'denied');
55 assert_unreached('querying midi permission should not fail.')
57 }, 'Test midi permission in ' + get_current_scope() + ' scope.');
59 async_test(function(test
) {
60 navigator
.permissions
.query({name
:'notifications'}).then(function(result
) {
61 assert_true(result
instanceof PermissionStatus
);
62 assert_equals(result
.state
, 'denied');
65 assert_unreached('querying notifications permission should not fail.')
67 }, 'Test notifications permission in ' + get_current_scope() + ' scope.');
69 async_test(function(test
) {
70 navigator
.permissions
.query({name
:'push'}).catch(function(e
) {
71 // By default, the permission query is rejected if "userVisibleOnly" option
72 // isn't set or set to true.
73 assert_equals(e
.name
, "NotSupportedError");
75 // Test for userVisibleOnly=false.
76 return navigator
.permissions
.query({name
:'push', userVisibleOnly
: false});
77 }).catch(function(e
) {
78 // By default, the permission query is rejected if "userVisibleOnly" option
79 // isn't set or set to true.
80 assert_equals(e
.name
, "NotSupportedError");
82 // Test for userVisibleOnly=true.
83 return navigator
.permissions
.query({name
:'push', userVisibleOnly
: true});
84 }).then(function(result
) {
85 assert_true(result
instanceof PermissionStatus
);
86 assert_equals(result
.state
, 'denied');
89 assert_unreached('querying push permission should not fail.')
91 }, 'Test push permission in ' + get_current_scope() + ' scope.');