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

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

Issue 1241133002: blink: permissions: cleanup and add tests for revoke (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@permissions-revoke
Patch Set: Query -> Revoke Created 5 years, 5 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
« no previous file with comments | « no previous file | LayoutTests/http/tests/permissions/chromium/test-revoke-sharedworker.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 if (self.importScripts) {
2 importScripts('../../resources/helpers.js');
3 importScripts('testrunner-helpers.js');
4
5 if (get_current_scope() == 'ServiceWorker')
6 importScripts('../../../serviceworker/resources/worker-testharness.js');
7 else
8 importScripts('../../../resources/testharness.js');
9 }
10
11 var DEFAULT_PERMISSION_STATE = 'denied';
12 var tests = [
13 {
14 test: async_test('Test PermissionDescription WebIDL rules in ' + get_current _scope() + ' scope.'),
15 fn: function(callback) {
16 // Revoking a random permission name should fail.
17 navigator.permissions.revoke({name:'foobar'}).then(function(result) {
18 assert_unreached('revoking a random permission should fail');
19 callback();
20 }, function(error) {
21 assert_equals(error.name, 'TypeError');
22
23 // Revoking a permission without a name should fail.
24 return navigator.permissions.revoke({});
25 }).then(function(result) {
26 assert_unreached('revoking a permission without a name should fail') ;
27 callback();
28 }, function(error) {
29 assert_equals(error.name, 'TypeError');
30 callback();
31 });
32 }
33 },
34 {
35 test: async_test('Test geolocation permission in ' + get_current_scope() + ' scope.'),
36 fn: function(callback) {
37 setPermission('geolocation', 'granted', location.origin, location.origin). then(function() {
38 return navigator.permissions.revoke({name:'geolocation'});
39 }).then(function(result) {
40 assert_true(result instanceof PermissionStatus);
41 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
42 callback();
43 }).catch(function() {
44 assert_unreached('revoking geolocation permission should not fail.');
45 callback();
46 });
47 }
48 },
49 {
50 test: async_test('Test midi permission in ' + get_current_scope() + ' scope. '),
51 fn: function(callback) {
52 setPermission('midi-sysex', 'granted', location.origin, location.origin) .then(function() {
53 return navigator.permissions.revoke({name:'midi'});
54 }).then(function(result) {
55 assert_true(result instanceof PermissionStatus);
56 assert_equals(result.state, 'granted');
57 return navigator.permissions.revoke({name:'midi', sysex:false});
58 }).then(function(result) {
59 assert_true(result instanceof PermissionStatus);
60 assert_equals(result.state, 'granted');
61 return navigator.permissions.revoke({name:'midi', sysex:true});
62 }).then(function(result) {
63 assert_true(result instanceof PermissionStatus);
64 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
65 callback();
66 }).catch(function() {
67 assert_unreached('revoking geolocation permission should not fail.')
68 callback();
69 });
70 }
71 },
72 {
73 test: async_test('Test push permission in ' + get_current_scope() + ' scope. '),
74 fn: function(callback) {
75 setPermission('push-messaging', 'granted', location.origin, location.ori gin).then(function() {
76 return navigator.permissions.revoke({name:'push'});
77 }).catch(function(e) {
78 // By default, the permission revocation is rejected if "userVisible Only" option
79 // isn't set or set to true.
80 assert_equals(e.name, "NotSupportedError");
81
82 // Test for userVisibleOnly=false.
83 return navigator.permissions.revoke({name:'push', userVisibleOnly: f alse});
84 }).catch(function(e) {
85 // By default, the permission revocation is rejected if "userVisible Only" option
86 // isn't set or set to true.
87 assert_equals(e.name, "NotSupportedError");
88
89 // Test for userVisibleOnly=true.
90 return navigator.permissions.revoke({name:'push', userVisibleOnly: t rue});
91 }).then(function(result) {
92 assert_true(result instanceof PermissionStatus);
93 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
94 callback();
95 }).catch(function() {
96 assert_unreached('revoking push permission should not fail.')
97 callback();
98 });
99 }
100 },
101 {
102 test: async_test('Test notifications permission in ' + get_current_scope() + ' scope.'),
103 fn: function(callback) {
104 setPermission('notifications', 'granted', location.origin, location.orig in).then(function() {
105 return navigator.permissions.revoke({name:'notifications'});
106 }).then(function(result) {
107 assert_true(result instanceof PermissionStatus);
108 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
109 callback();
110 }).catch(function() {
111 assert_unreached('revoking notifications permission should not fail. ')
112 callback();
113 });
114 }
115 }];
116
117 function runTest(i) {
118 tests[i].test.step(function() {
119 tests[i].fn(function() {
120 tests[i].test.done();
121 if (i + 1 < tests.length) {
122 runTest(i + 1);
123 } else {
124 done();
125 }
126 });
127 });
128 }
129 runTest(0);
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/permissions/chromium/test-revoke-sharedworker.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698