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

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

Issue 1248703002: blink: permissions: add tests for request (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@permissions-request
Patch Set: Fix comments Created 5 years, 4 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-request-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 tests = [
12 {
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';
18 }, function(error) {
19 assert_equals(error.name, 'TypeError');
20
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';
25 }, function(error) {
26 assert_equals(error.name, 'TypeError');
27 callback();
28 }).catch(function(error) {
29 assert_unreached(error);
30 callback();
31 });
32 }
33 },
34 {
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 permissi on
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');
44
45 result.onchange = function() {
46 assert_equals(result.state, 'granted');
47
48 navigator.permissions.request({name:'geolocation'}).then(function( ) {
49 assert_true(result instanceof PermissionStatus);
50 assert_equals(result.state, 'granted');
51 callback();
52 }).catch(function() {
53 assert_unreached('requesting geolocation permission should not fail.')
54 callback();
55 });
56 };
57
58 setPermission('geolocation', 'granted', location.origin, location.orig in)
59 }).catch(function() {
60 assert_unreached('requesting geolocation permission should not fail.')
61 callback();
62 });
63 }
64 }];
65
66 function runTest(i) {
67 tests[i].test.step(function() {
68 tests[i].fn(function() {
69 tests[i].test.done();
70 if (i + 1 < tests.length) {
71 runTest(i + 1);
72 } else {
73 done();
74 }
75 });
76 });
77 }
78 runTest(0);
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/permissions/chromium/test-request-sharedworker.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698