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

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

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: rebase + blink reformat 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('../../resources/helpers.js'); 2 importScripts('../../resources/helpers.js');
3 importScripts('testrunner-helpers.js'); 3 importScripts('testrunner-helpers.js');
4 4
5 if (get_current_scope() == 'ServiceWorker') 5 if (get_current_scope() == 'ServiceWorker')
6 importScripts('../../../serviceworker/resources/worker-testharness.js'); 6 importScripts('../../../serviceworker/resources/worker-testharness.js');
7 else 7 else
8 importScripts('../../../resources/testharness.js'); 8 importScripts('../../../resources/testharness.js');
9 } 9 }
10 10
11 var DEFAULT_PERMISSION_STATE = 'denied'; 11 var DEFAULT_PERMISSION_STATE = 'denied';
12 var tests = [ 12 var tests = [
13 { 13 {
14 test: async_test('Test PermissionDescription WebIDL rules in ' + get_current _scope() + ' scope.'), 14 test: async_test(
15 'Test PermissionDescription WebIDL rules in ' + get_current_scope() +
16 ' scope.'),
15 fn: function(callback) { 17 fn: function(callback) {
16 // Revoking a random permission name should fail. 18 // Revoking a random permission name should fail.
17 navigator.permissions.revoke({name:'foobar'}).then(function(result) { 19 navigator.permissions.revoke({name: 'foobar'})
18 assert_unreached('revoking a random permission should fail'); 20 .then(
19 callback(); 21 function(result) {
20 }, function(error) { 22 assert_unreached('revoking a random permission should fail');
21 assert_equals(error.name, 'TypeError'); 23 callback();
24 },
25 function(error) {
26 assert_equals(error.name, 'TypeError');
22 27
23 // Revoking a permission without a name should fail. 28 // Revoking a permission without a name should fail.
24 return navigator.permissions.revoke({}); 29 return navigator.permissions.revoke({});
25 }).then(function(result) { 30 })
26 assert_unreached('revoking a permission without a name should fail') ; 31 .then(
27 callback(); 32 function(result) {
28 }, function(error) { 33 assert_unreached(
29 assert_equals(error.name, 'TypeError'); 34 'revoking a permission without a name should fail');
30 callback(); 35 callback();
31 }); 36 },
37 function(error) {
38 assert_equals(error.name, 'TypeError');
39 callback();
40 });
32 } 41 }
33 }, 42 },
34 { 43 {
35 test: async_test('Test geolocation permission in ' + get_current_scope() + ' scope.'), 44 test: async_test(
45 'Test geolocation permission in ' + get_current_scope() + ' scope.'),
36 fn: function(callback) { 46 fn: function(callback) {
37 setPermission('geolocation', 'granted', location.origin, location.origin). then(function() { 47 setPermission('geolocation', 'granted', location.origin, location.origin). then(function() {
38 return navigator.permissions.revoke({name:'geolocation'}); 48 return navigator.permissions.revoke({name:'geolocation'});
39 }).then(function(result) { 49 }).then(function(result) {
40 assert_true(result instanceof PermissionStatus); 50 assert_true(result instanceof PermissionStatus);
41 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 51 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
42 callback(); 52 callback();
43 }).catch(function() { 53 }).catch(function() {
44 assert_unreached('revoking geolocation permission should not fail.'); 54 assert_unreached('revoking geolocation permission should not fail.');
45 callback(); 55 callback();
46 }); 56 });
47 } 57 }
48 }, 58 },
49 { 59 {
50 test: async_test('Test midi permission in ' + get_current_scope() + ' scope. '), 60 test: async_test(
61 'Test midi permission in ' + get_current_scope() + ' scope.'),
51 fn: function(callback) { 62 fn: function(callback) {
52 setPermission('midi-sysex', 'granted', location.origin, location.origin) .then(function() { 63 setPermission('midi-sysex', 'granted', location.origin, location.origin)
64 .then(function() {
53 return navigator.permissions.revoke({name:'midi'}); 65 return navigator.permissions.revoke({name:'midi'});
54 }).then(function(result) { 66 })
67 .then(function(result) {
55 assert_true(result instanceof PermissionStatus); 68 assert_true(result instanceof PermissionStatus);
56 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 69 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
57 return navigator.permissions.revoke({name:'midi', sysex:false}); 70 return navigator.permissions.revoke({name:'midi', sysex:false});
58 }).then(function(result) { 71 })
72 .then(function(result) {
59 assert_true(result instanceof PermissionStatus); 73 assert_true(result instanceof PermissionStatus);
60 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 74 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
61 return navigator.permissions.revoke({name:'midi', sysex:true}); 75 return navigator.permissions.revoke({name:'midi', sysex:true});
62 }).then(function(result) { 76 })
77 .then(function(result) {
63 assert_true(result instanceof PermissionStatus); 78 assert_true(result instanceof PermissionStatus);
64 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 79 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
65 callback(); 80 callback();
66 }).catch(function() { 81 })
82 .catch(function() {
67 assert_unreached('revoking midi permission should not fail.') 83 assert_unreached('revoking midi permission should not fail.')
68 callback(); 84 callback();
69 }); 85 });
70 } 86 }
71 }, 87 },
72 { 88 {
73 test: async_test('Test push permission in ' + get_current_scope() + ' scope. '), 89 test: async_test(
90 'Test sensors permission in ' + get_current_scope() + ' scope.'),
74 fn: function(callback) { 91 fn: function(callback) {
75 setPermission('push-messaging', 'granted', location.origin, location.ori gin).then(function() { 92 setPermission('sensors', 'granted', location.origin, location.origin)
93 .then(function() {
94 return navigator.permissions.revoke({name: 'sensors'});
95 })
96 .then(function(result) {
97 assert_true(result instanceof PermissionStatus);
98 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
99 callback();
100 })
101 .catch(function() {
102 assert_unreached('revoking sensors permission should not fail.');
103 callback();
104 });
105 }
106 },
107 {
108 test: async_test(
109 'Test push permission in ' + get_current_scope() + ' scope.'),
110 fn: function(callback) {
111 setPermission(
112 'push-messaging', 'granted', location.origin, location.origin)
113 .then(function() {
76 return navigator.permissions.revoke({name:'push'}); 114 return navigator.permissions.revoke({name:'push'});
77 }).catch(function(e) { 115 })
116 .catch(function(e) {
78 // By default, the permission revocation is rejected if "userVisible Only" option 117 // By default, the permission revocation is rejected if "userVisible Only" option
79 // isn't set or set to true. 118 // isn't set or set to true.
80 assert_equals(e.name, "NotSupportedError"); 119 assert_equals(e.name, "NotSupportedError");
81 120
82 // Test for userVisibleOnly=false. 121 // Test for userVisibleOnly=false.
83 return navigator.permissions.revoke({name:'push', userVisibleOnly: f alse}); 122 return navigator.permissions.revoke({name:'push', userVisibleOnly: f alse});
84 }).catch(function(e) { 123 })
124 .catch(function(e) {
85 // By default, the permission revocation is rejected if "userVisible Only" option 125 // By default, the permission revocation is rejected if "userVisible Only" option
86 // isn't set or set to true. 126 // isn't set or set to true.
87 assert_equals(e.name, "NotSupportedError"); 127 assert_equals(e.name, "NotSupportedError");
88 128
89 // Test for userVisibleOnly=true. 129 // Test for userVisibleOnly=true.
90 return navigator.permissions.revoke({name:'push', userVisibleOnly: t rue}); 130 return navigator.permissions.revoke({name:'push', userVisibleOnly: t rue});
91 }).then(function(result) { 131 })
132 .then(function(result) {
92 assert_true(result instanceof PermissionStatus); 133 assert_true(result instanceof PermissionStatus);
93 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 134 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
94 callback(); 135 callback();
95 }).catch(function() { 136 })
137 .catch(function() {
96 assert_unreached('revoking push permission should not fail.') 138 assert_unreached('revoking push permission should not fail.')
97 callback(); 139 callback();
98 }); 140 });
99 } 141 }
100 }, 142 },
101 { 143 {
102 test: async_test('Test notifications permission in ' + get_current_scope() + ' scope.'), 144 test: async_test(
145 'Test notifications permission in ' + get_current_scope() + ' scope.'),
103 fn: function(callback) { 146 fn: function(callback) {
104 setPermission('notifications', 'granted', location.origin, location.orig in).then(function() { 147 setPermission(
148 'notifications', 'granted', location.origin, location.origin)
149 .then(function() {
105 return navigator.permissions.revoke({name:'notifications'}); 150 return navigator.permissions.revoke({name:'notifications'});
106 }).then(function(result) { 151 })
152 .then(function(result) {
107 assert_true(result instanceof PermissionStatus); 153 assert_true(result instanceof PermissionStatus);
108 assert_equals(result.state, DEFAULT_PERMISSION_STATE); 154 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
109 callback(); 155 callback();
110 }).catch(function() { 156 })
157 .catch(function() {
111 assert_unreached('revoking notifications permission should not fail. ') 158 assert_unreached('revoking notifications permission should not fail. ')
112 callback(); 159 callback();
113 }); 160 });
114 } 161 }
115 }]; 162 }
163 ];
116 164
117 function runTest(i) { 165 function runTest(i) {
118 tests[i].test.step(function() { 166 tests[i].test.step(function() {
119 tests[i].fn(function() { 167 tests[i].fn(function() {
120 tests[i].test.done(); 168 tests[i].test.done();
121 if (i + 1 < tests.length) { 169 if (i + 1 < tests.length) {
122 runTest(i + 1); 170 runTest(i + 1);
123 } else { 171 } else {
124 done(); 172 done();
125 } 173 }
126 }); 174 });
127 }); 175 });
128 } 176 }
129 runTest(0); 177 runTest(0);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698