Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / permissions / resources / test-query.js
blobfe16ccd5b08f617412692929c64cd9eac1a233c9
1 if (self.importScripts) {
2 importScripts('helpers.js');
4 if (get_current_scope() == 'ServiceWorker')
5 importScripts('../../serviceworker/resources/worker-testharness.js');
6 else
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');
14 }, function(error) {
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');
21 }, function(error) {
22 assert_equals(error.name, 'TypeError');
23 test.done();
24 });
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');
31 test.done();
32 }).catch(function() {
33 assert_unreached('querying geolocation permission should not fail.')
34 });
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');
53 test.done();
54 }).catch(function() {
55 assert_unreached('querying midi permission should not fail.')
56 });
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');
63 test.done();
64 }).catch(function() {
65 assert_unreached('querying notifications permission should not fail.')
66 });
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');
87 test.done();
88 }).catch(function() {
89 assert_unreached('querying push permission should not fail.')
90 });
91 }, 'Test push permission in ' + get_current_scope() + ' scope.');
93 done();