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

Unified Diff: chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/background.js

Issue 227413008: Add the feature to retain the user gesture in the extension callback (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 6 years, 8 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: 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,79 @@
+// 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";
+
+function busyLoop(milliseconds) {
+ var startTime = new Date().getTime();
+ while (new Date().getTime() - startTime < milliseconds) {}
+}
+
+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) {
+ 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));
+ }
+ );
+
+ // Consume the user gesture
+ window.open("", "", "");
+ }
+ );
+ });
+ },
+
+ function testPermissionsRetainGestureExpire() {
+ 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(granted1) {
+ if (chrome.runtime.lastError) {
+ chrome.test.assertFalse(granted1);
+ chrome.test.assertEq(chrome.runtime.lastError.message,
+ GESTURE_ERROR);
+ chrome.test.succeed();
+ } else {
+ console.log("Retrying permissions.request in 3 " +
+ "seconds");
+ busyLoop(3000);
+ request();
+ }
+ });
+ };
+
+ // Wait 2s since the user gesture timeout is 1s.
+ busyLoop(2000);
+ request();
+ }
+ );
+ });
+ }
+ ]);
+});

Powered by Google App Engine
This is Rietveld 408576698