Index: chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/background.js |
=================================================================== |
--- chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/background.js (revision 0) |
+++ chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/background.js (revision 0) |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+var fail = chrome.test.callbackFail; |
+ |
+var GESTURE_ERROR = "This function must be called during a user gesture"; |
+ |
+chrome.test.getConfig(function(config) { |
+ chrome.test.runTests([ |
+ function testPermissionsRetainGesture() { |
+ chrome.test.runWithUserGesture(function() { |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ function(granted) { |
+ chrome.test.assertTrue(granted); |
+ |
+ // The user gesture is retained, so we can request again. |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ function(granted) { |
+ // Wait 500ms for consuming the user gesture in |
+ // window.open. Can't wait longer than 1s since the user |
Marijn Kruisselbrink
2014/04/23 23:00:43
very minor nit: this comment is a bit misleading,
|
+ // gesture will expire. |
+ window.setTimeout(function() { |
+ chrome.test.assertTrue(granted); |
+ // The user gesture is retained but is consumed outside, |
+ // so the following request will fail. |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ fail(GESTURE_ERROR)); |
+ }, 500); |
+ } |
+ ); |
+ |
+ // Consume the user gesture |
+ window.open("", "", ""); |
+ } |
+ ); |
+ }); |
+ }, |
+ |
+ function testPermissionsRetainGestureExpire() { |
Marijn Kruisselbrink
2014/04/23 23:00:43
Similarly all the setTimeout calls in this test do
|
+ chrome.test.runWithUserGesture(function() { |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ function(granted) { |
+ chrome.test.assertTrue(granted); |
+ |
+ var request = function() { |
+ // The following request will fail if the user gesture is |
+ // expired. |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ function(granted) { |
+ if (chrome.runtime.lastError) { |
+ chrome.test.assertFalse(granted); |
+ chrome.permissions.request( |
+ {permissions: ['bookmarks']}, |
+ fail(GESTURE_ERROR)); |
+ } else { |
+ console.log("Retrying permissions.request in 3 " + |
+ "seconds"); |
+ window.setTimeout(request, 3000); |
+ } |
+ }); |
+ }; |
+ |
+ // Wait 2s since the user gesture timeout is 1s. |
+ window.setTimeout(function() { |
+ request(); |
+ }, 2000); |
+ } |
+ ); |
+ }); |
+ } |
+ ]); |
+}); |