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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var fail = chrome.test.callbackFail;
6
7 var GESTURE_ERROR = "This function must be called during a user gesture";
8
9 chrome.test.getConfig(function(config) {
10 chrome.test.runTests([
11 function testPermissionsRetainGesture() {
12 chrome.test.runWithUserGesture(function() {
13 chrome.permissions.request(
14 {permissions: ['bookmarks']},
15 function(granted) {
16 chrome.test.assertTrue(granted);
17
18 // The user gesture is retained, so we can request again.
19 chrome.permissions.request(
20 {permissions: ['bookmarks']},
21 function(granted) {
22 // Wait 500ms for consuming the user gesture in
23 // 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,
24 // gesture will expire.
25 window.setTimeout(function() {
26 chrome.test.assertTrue(granted);
27 // The user gesture is retained but is consumed outside,
28 // so the following request will fail.
29 chrome.permissions.request(
30 {permissions: ['bookmarks']},
31 fail(GESTURE_ERROR));
32 }, 500);
33 }
34 );
35
36 // Consume the user gesture
37 window.open("", "", "");
38 }
39 );
40 });
41 },
42
43 function testPermissionsRetainGestureExpire() {
Marijn Kruisselbrink 2014/04/23 23:00:43 Similarly all the setTimeout calls in this test do
44 chrome.test.runWithUserGesture(function() {
45 chrome.permissions.request(
46 {permissions: ['bookmarks']},
47 function(granted) {
48 chrome.test.assertTrue(granted);
49
50 var request = function() {
51 // The following request will fail if the user gesture is
52 // expired.
53 chrome.permissions.request(
54 {permissions: ['bookmarks']},
55 function(granted) {
56 if (chrome.runtime.lastError) {
57 chrome.test.assertFalse(granted);
58 chrome.permissions.request(
59 {permissions: ['bookmarks']},
60 fail(GESTURE_ERROR));
61 } else {
62 console.log("Retrying permissions.request in 3 " +
63 "seconds");
64 window.setTimeout(request, 3000);
65 }
66 });
67 };
68
69 // Wait 2s since the user gesture timeout is 1s.
70 window.setTimeout(function() {
71 request();
72 }, 2000);
73 }
74 );
75 });
76 }
77 ]);
78 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698