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');
13 test: async_test('Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope.'),
14 fn: function(callback) {
15 // Requesting a random permission name should fail.
16 navigator.permissions.request({name:'foobar'}).then(function(result) {
17 throw 'requesting a random permission should fail';
19 assert_equals(error.name, 'TypeError');
21 // Querying a permission without a name should fail.
22 return navigator.permissions.request({});
23 }).then(function(result) {
24 throw 'requesting a permission without a name should fail';
26 assert_equals(error.name, 'TypeError');
28 }).catch(function(error) {
29 assert_unreached(error);
35 // request() is expected to show a UI then return the new permission status.
36 // In layout tests no UI is shown so it boils down to returning the permission
37 // status. The tests only check that behaviour given that trying to simulate
38 // user decision would simply test the test infrastructure.
39 test: async_test('Test basic request behaviour in ' + get_current_scope() + ' scope.'),
40 fn: function(callback) {
41 navigator.permissions.request({name:'geolocation'}).then(function(result) {
42 assert_true(result instanceof PermissionStatus);
43 assert_equals(result.state, 'denied');
45 result.onchange = function() {
46 assert_equals(result.state, 'granted');
48 navigator.permissions.request({name:'geolocation'}).then(function() {
49 assert_true(result instanceof PermissionStatus);
50 assert_equals(result.state, 'granted');
53 assert_unreached('requesting geolocation permission should not fail.')
58 setPermission('geolocation', 'granted', location.origin, location.origin)
60 assert_unreached('requesting geolocation permission should not fail.')
67 tests[i].test.step(function() {
68 tests[i].fn(function() {
70 if (i + 1 < tests.length) {