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

Unified 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 tests 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
Index: LayoutTests/http/tests/permissions/chromium/resources/test-request.js
diff --git a/LayoutTests/http/tests/permissions/chromium/resources/test-request.js b/LayoutTests/http/tests/permissions/chromium/resources/test-request.js
new file mode 100644
index 0000000000000000000000000000000000000000..2427b53f7c94d235b9353da9cf7de0a71e761f45
--- /dev/null
+++ b/LayoutTests/http/tests/permissions/chromium/resources/test-request.js
@@ -0,0 +1,73 @@
+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');
+}
+
+var tests = [
+{
+ test: async_test('Test PermissionDescription WebIDL rules in ' + get_current_scope() + ' scope.'),
+ fn: function(callback) {
+ // Requesting a random permission name should fail.
+ navigator.permissions.request({name:'foobar'}).then(function(result) {
+ assert_unreached('requesting a random permission should fail');
+ callback();
mlamouri (slow - plz ping) 2015/07/24 14:31:12 Can you call throw and pass the message then at th
Lalit Maganti 2015/07/30 10:10:14 Done.
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+
+ // Querying a permission without a name should fail.
+ return navigator.permissions.request({});
+ }).then(function(result) {
+ assert_unreached('requesting a permission without a name should fail');
+ callback();
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+ callback();
+ });
+ }
+},
+{
+ test: async_test('Test geolocation permission in ' + get_current_scope() + ' scope.'),
mlamouri (slow - plz ping) 2015/07/24 14:31:12 'Test basic request behaviour in [...] And add a
Lalit Maganti 2015/07/30 10:10:14 Done.
+ fn: function(callback) {
+ navigator.permissions.request({name:'geolocation'}).then(function(result) {
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.state, 'denied');
+
+ result.onchange = function() {
+ assert_equals(result.state, 'granted');
+
+ navigator.permissions.request({name:'geolocation'}).then(function() {
+ assert_true(result instanceof PermissionStatus);
+ assert_equals(result.state, 'granted');
+ callback();
+ }).catch(function() {
+ assert_unreached('requesting geolocation permission should not fail.')
+ callback();
+ });
+ };
+
+ setPermission('geolocation', 'granted', location.origin, location.origin)
+ }).catch(function() {
+ assert_unreached('requesting geolocation permission should not fail.')
+ callback();
+ });
+ }
+}];
+
+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();
+ }
+ });
+ });
+}
+runTest(0);

Powered by Google App Engine
This is Rietveld 408576698