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

Unified 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: Rebase on upstream patch 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/permissions/chromium/resources/test-revoke.js
diff --git a/LayoutTests/http/tests/permissions/chromium/resources/test-revoke.js b/LayoutTests/http/tests/permissions/chromium/resources/test-revoke.js
new file mode 100644
index 0000000000000000000000000000000000000000..5abc5db05f3d325482d332d53fe27cbc0ce1b6fc
--- /dev/null
+++ b/LayoutTests/http/tests/permissions/chromium/resources/test-revoke.js
@@ -0,0 +1,114 @@
+if (self.importScripts) {
+ importScripts('../../resources/helpers.js');
+ importScripts('testrunner-helpers.js');
+
+ if (get_current_scope() == 'ServiceWorker')
+ importScripts('../../../serviceworker/resources/worker-testharness.js');
+ else
+ importScripts('../../../resources/testharness.js');
+}
+
+tests = [
mlamouri (slow - plz ping) 2015/07/21 10:53:29 var tests
Lalit Maganti 2015/07/21 16:10:30 Done.
+{
+ test: async_test('Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ // Revoking a random permission name should fail.
+ navigator.permissions.revoke({name:'foobar'}).then(function(result) {
+ assert_unreached('revocing a random permission should fail');
mlamouri (slow - plz ping) 2015/07/21 10:53:29 nit: revoking
Lalit Maganti 2015/07/21 16:10:30 Done.
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+
+ // Querying a permission without a name should fail.
+ return navigator.permissions.query({});
+ }).then(function(result) {
+ assert_unreached('revoking a permission without a name should fail');
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+ callback();
+ });
+ }
+},
+{
+ test: async_test('Test geolocation permission in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ setPermission('geolocation', 'granted', location.origin, location.origin).then(function() {
+ navigator.permissions.revoke({name:'geolocation'}).then(function(result) {
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.status, 'denied');
mlamouri (slow - plz ping) 2015/07/21 10:53:29 Could you use .state instead of .status. Also, cou
Lalit Maganti 2015/07/21 16:10:30 Done.
+ callback();
+ }).catch(function() {
+ assert_unreached('revoking geolocation permission should not fail.')
+ });
+ });
+ }
+},
+{
+ test: async_test('Test midi permission in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ setPermission('midi-sysex', 'granted', location.origin, location.origin).then(function() {
+ navigator.permissions.revoke({name:'geolocation'}).then(function(result) {
mlamouri (slow - plz ping) 2015/07/21 10:53:29 You might want to revoke 'midi-sysex' ;)
Lalit Maganti 2015/07/21 16:10:30 Revoke actually expects 'midi' but done.
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.status, 'denied');
+ callback();
+ }).catch(function() {
+ assert_unreached('revoking geolocation permission should not fail.')
+ });
+ });
+ }
+},
+{
+ test: async_test('Test push permission in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ setPermission('push-messaging', 'granted', location.origin, location.origin).then(function() {
+ navigator.permissions.revoke({name:'push'}).catch(function(e) {
+ // By default, the permission query is rejected if "userVisibleOnly" option
+ // isn't set or set to true.
+ assert_equals(e.name, "NotSupportedError");
+
+ // Test for userVisibleOnly=false.
+ return navigator.permissions.revoke({name:'push', userVisibleOnly: false});
+ }).catch(function(e) {
+ // By default, the permission query is rejected if "userVisibleOnly" option
+ // isn't set or set to true.
+ assert_equals(e.name, "NotSupportedError");
+
+ // Test for userVisibleOnly=true.
+ return navigator.permissions.revoke({name:'push', userVisibleOnly: true});
+ }).then(function(result) {
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.status, 'denied');
+ callback();
+ }).catch(function() {
+ assert_unreached('querying push permission should not fail.')
+ });
+ });
+ }
+},
+{
+ test: async_test('Test notifications permission in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ setPermission('notifications', 'granted', location.origin, location.origin).then(function() {
+ navigator.permissions.revoke({name:'notifications'}).then(function(result) {
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.status, 'denied');
+ callback();
+ }).catch(function() {
+ assert_unreached('querying notifications permission should not fail.')
+ });
+ });
+ }
+}];
+
+function runTest(i) {
+ tests[i].test.step(function() {
+ tests[i].fn(function() {
+ tests[i].test.done();
+ if (i + 1 < tests.length) {
+ runTest(i + 1);
+ } else {
+ done();
mlamouri (slow - plz ping) 2015/07/21 10:53:29 In other tests done() is run when the test file is
Lalit Maganti 2015/07/21 16:10:30 As discussed offline.
+ }
+ });
+ });
+}
+runTest(0);
« 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