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

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 comments 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-request-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-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..95f452065a5a7927c0959e07d799e29a0a722b0f
--- /dev/null
+++ b/LayoutTests/http/tests/permissions/chromium/resources/test-request.js
@@ -0,0 +1,78 @@
+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) {
+ throw 'requesting a random permission should fail';
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+
+ // Querying a permission without a name should fail.
+ return navigator.permissions.request({});
+ }).then(function(result) {
+ throw 'requesting a permission without a name should fail';
+ }, function(error) {
+ assert_equals(error.name, 'TypeError');
+ callback();
+ }).catch(function(error) {
+ assert_unreached(error);
+ callback();
+ });
+ }
+},
+{
+ // request() is expected to show a UI then return the new permission status.
+ // In layout tests no UI is shown so it boils down to returning the permission
+ // status. The tests only check that behaviour given that trying to simulate
+ // user decision would simply test the test infrastructure.
+ test: async_test('Test basic request behaviour in ' + get_current_scope() + ' scope.'),
+ 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);
« 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