Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/permissions/resources/test-query.js

Issue 2797713002: [sensor][permission] Adding permission guard to sensors based on Generic Sensor.
Patch Set: blink format changes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('helpers.js'); 2 importScripts('helpers.js');
3 3
4 if (get_current_scope() == 'ServiceWorker') 4 if (get_current_scope() == 'ServiceWorker')
5 importScripts('../../serviceworker/resources/worker-testharness.js'); 5 importScripts('../../serviceworker/resources/worker-testharness.js');
6 else 6 else
7 importScripts('../../resources/testharness.js'); 7 importScripts('../../resources/testharness.js');
8 } 8 }
9 9
10 async_test(function(test) { 10 async_test(function(test) {
11 // Querying a random permission name should fail. 11 // Querying a random permission name should fail.
12 navigator.permissions.query({name:'foobar'}).then(function(result) { 12 navigator.permissions.query({name:'foobar'}).then(function(result) {
13 assert_unreached('querying a random permission should fail'); 13 assert_unreached('querying a random permission should fail');
14 }, function(error) { 14 }, function(error) {
15 assert_equals(error.name, 'TypeError'); 15 assert_equals(error.name, 'TypeError');
16 16
17 // Querying a permission without a name should fail. 17 // Querying a permission without a name should fail.
18 return navigator.permissions.query({}); 18 return navigator.permissions.query({});
19 }).then(function(result) { 19 }).then(function(result) {
20 assert_unreached('querying a permission without a name should fail'); 20 assert_unreached('querying a permission without a name should fail');
21 }, function(error) { 21 }, function(error) {
22 assert_equals(error.name, 'TypeError'); 22 assert_equals(error.name, 'TypeError');
23 test.done(); 23 test.done();
24 }); 24 });
25 }, 'Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope .'); 25 }, 'Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope .');
26 26
27 async_test(function(test) { 27 async_test(function(test) {
28 navigator.permissions.query({name:'ambient-light-sensor'}).then(function(res ult) { 28 navigator.permissions.query({name:'ambient-light-sensor'}).then(function(res ult) {
29 assert_true(result instanceof PermissionStatus); 29 assert_true(result instanceof PermissionStatus);
30 assert_equals(result.state, 'granted');
30 test.done(); 31 test.done();
31 }).catch(function() { 32 }).catch(function() {
32 assert_unreached('querying ambient-light-sensor permission should not fa il.') 33 assert_unreached('querying ambient-light-sensor permission should not fa il.')
33 }); 34 });
34 }, 'Test ambient-light-sensor permission in ' + get_current_scope() + ' scope.') ; 35 }, 'Test ambient-light-sensor permission in ' + get_current_scope() + ' scope.') ;
35 36
36 async_test(function(test) { 37 async_test(function(test) {
37 navigator.permissions.query({name:'accelerometer'}).then(function(result) { 38 navigator.permissions.query({name:'accelerometer'}).then(function(result) {
38 assert_true(result instanceof PermissionStatus); 39 assert_true(result instanceof PermissionStatus);
40 assert_equals(result.state, 'granted');
39 test.done(); 41 test.done();
40 }).catch(function() { 42 }).catch(function() {
41 assert_unreached('querying accelerometer permission should not fail.') 43 assert_unreached('querying accelerometer permission should not fail.')
42 }); 44 });
43 }, 'Test accelerometer permission in ' + get_current_scope() + ' scope.'); 45 }, 'Test accelerometer permission in ' + get_current_scope() + ' scope.');
44 46
45 async_test(function(test) { 47 async_test(function(test) {
46 navigator.permissions.query({name:'gyroscope'}).then(function(result) { 48 navigator.permissions.query({name:'gyroscope'}).then(function(result) {
47 assert_true(result instanceof PermissionStatus); 49 assert_true(result instanceof PermissionStatus);
50 assert_equals(result.state, 'granted');
48 test.done(); 51 test.done();
49 }).catch(function() { 52 }).catch(function() {
50 assert_unreached('querying gyroscope permission should not fail.') 53 assert_unreached('querying gyroscope permission should not fail.')
51 }); 54 });
52 }, 'Test gyroscope permission in ' + get_current_scope() + ' scope.'); 55 }, 'Test gyroscope permission in ' + get_current_scope() + ' scope.');
53 56
54 async_test(function(test) { 57 async_test(function(test) {
55 navigator.permissions.query({name:'magnetometer'}).then(function(result) { 58 navigator.permissions.query({name:'magnetometer'}).then(function(result) {
56 assert_true(result instanceof PermissionStatus); 59 assert_true(result instanceof PermissionStatus);
60 assert_equals(result.state, 'granted');
57 test.done(); 61 test.done();
58 }).catch(function() { 62 }).catch(function() {
59 assert_unreached('querying magnetometer permission should not fail.') 63 assert_unreached('querying magnetometer permission should not fail.')
60 }); 64 });
61 }, 'Test magnetometer permission in ' + get_current_scope() + ' scope.'); 65 }, 'Test magnetometer permission in ' + get_current_scope() + ' scope.');
62 66
63 async_test(function(test) { 67 async_test(function(test) {
64 navigator.permissions.query({name:'orientation-sensor'}).then(function(resul t) { 68 navigator.permissions.query({name:'orientation-sensor'}).then(function(resul t) {
65 assert_true(result instanceof PermissionStatus); 69 assert_true(result instanceof PermissionStatus);
70 assert_equals(result.state, 'granted');
66 test.done(); 71 test.done();
67 }).catch(function() { 72 }).catch(function() {
68 assert_unreached('querying orientation-sensor permission should not fail .') 73 assert_unreached('querying orientation-sensor permission should not fail .')
69 }); 74 });
70 }, 'Test orientation-sensor permission in ' + get_current_scope() + ' scope.'); 75 }, 'Test orientation-sensor permission in ' + get_current_scope() + ' scope.');
71 76
72 async_test(function(test) { 77 async_test(function(test) {
73 navigator.permissions.query({name:'geolocation'}).then(function(result) { 78 navigator.permissions.query({name:'geolocation'}).then(function(result) {
74 assert_true(result instanceof PermissionStatus); 79 assert_true(result instanceof PermissionStatus);
75 assert_equals(result.state, 'denied'); 80 assert_equals(result.state, 'denied');
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 }).then(function(result) { 134 }).then(function(result) {
130 assert_true(result instanceof PermissionStatus); 135 assert_true(result instanceof PermissionStatus);
131 assert_equals(result.state, 'denied'); 136 assert_equals(result.state, 'denied');
132 test.done(); 137 test.done();
133 }).catch(function() { 138 }).catch(function() {
134 assert_unreached('querying push permission should not fail.') 139 assert_unreached('querying push permission should not fail.')
135 }); 140 });
136 }, 'Test push permission in ' + get_current_scope() + ' scope.'); 141 }, 'Test push permission in ' + get_current_scope() + ' scope.');
137 142
138 done(); 143 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698