1 if (self.importScripts) {
2 importScripts('../../resources/helpers.js');
3 importScripts('testrunner-helpers.js');
5 if (get_current_scope() == 'ServiceWorker')
6 importScripts('../../../serviceworker/resources/worker-testharness.js');
8 importScripts('../../../resources/testharness.js');
11 var DEFAULT_PERMISSION_STATE = 'denied';
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');
21 assert_equals(error.name, 'TypeError');
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');
29 assert_equals(error.name, 'TypeError');
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);
44 assert_unreached('revoking geolocation permission should not fail.');
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, DEFAULT_PERMISSION_STATE);
57 return navigator.permissions.revoke({name:'midi', sysex:false});
58 }).then(function(result) {
59 assert_true(result instanceof PermissionStatus);
60 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
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);
67 assert_unreached('revoking midi permission should not fail.')
73 test: async_test('Test push permission in ' + get_current_scope() + ' scope.'),
74 fn: function(callback) {
75 setPermission('push-messaging', 'granted', location.origin, location.origin).then(function() {
76 return navigator.permissions.revoke({name:'push'});
77 }).catch(function(e) {
78 // By default, the permission revocation is rejected if "userVisibleOnly" option
79 // isn't set or set to true.
80 assert_equals(e.name, "NotSupportedError");
82 // Test for userVisibleOnly=false.
83 return navigator.permissions.revoke({name:'push', userVisibleOnly: false});
84 }).catch(function(e) {
85 // By default, the permission revocation is rejected if "userVisibleOnly" option
86 // isn't set or set to true.
87 assert_equals(e.name, "NotSupportedError");
89 // Test for userVisibleOnly=true.
90 return navigator.permissions.revoke({name:'push', userVisibleOnly: true});
91 }).then(function(result) {
92 assert_true(result instanceof PermissionStatus);
93 assert_equals(result.state, DEFAULT_PERMISSION_STATE);
96 assert_unreached('revoking push permission should not fail.')
102 test: async_test('Test notifications permission in ' + get_current_scope() + ' scope.'),
103 fn: function(callback) {
104 setPermission('notifications', 'granted', location.origin, location.origin).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);
110 }).catch(function() {
111 assert_unreached('revoking notifications permission should not fail.')
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) {