1 // Copyright 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.
5 var fail = chrome.test.callbackFail;
7 var GESTURE_ERROR = "This function must be called during a user gesture";
9 function busyLoop(milliseconds) {
10 var startTime = new Date().getTime();
11 while (new Date().getTime() - startTime < milliseconds) {}
14 chrome.test.getConfig(function(config) {
15 chrome.test.runTests([
16 function testPermissionsRetainGesture() {
17 chrome.test.runWithUserGesture(function() {
18 chrome.permissions.request(
19 {permissions: ['bookmarks']},
21 chrome.test.assertTrue(granted);
23 // The user gesture is retained, so we can request again.
24 chrome.permissions.request(
25 {permissions: ['bookmarks']},
27 chrome.test.assertTrue(granted);
29 // The user gesture is retained but is consumed outside,
30 // so the following request will fail.
31 chrome.permissions.request(
32 {permissions: ['bookmarks']},
37 // Consume the user gesture
38 window.open("", "", "");
44 function testPermissionsRetainGestureExpire() {
45 chrome.test.runWithUserGesture(function() {
46 chrome.permissions.request(
47 {permissions: ['bookmarks']},
49 chrome.test.assertTrue(granted);
51 var request = function() {
52 // The following request will fail if the user gesture is
54 chrome.permissions.request(
55 {permissions: ['bookmarks']},
57 if (chrome.runtime.lastError) {
58 chrome.test.assertFalse(granted1);
59 chrome.test.assertEq(chrome.runtime.lastError.message,
61 chrome.test.succeed();
63 console.log("Retrying permissions.request in 3 " +
71 // Wait 2s since the user gesture timeout is 1s.