OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var fail = chrome.test.callbackFail; | 5 var fail = chrome.test.callbackFail; |
6 | 6 |
7 var GESTURE_ERROR = "This function must be called during a user gesture"; | 7 var GESTURE_ERROR = "This function must be called during a user gesture"; |
8 | 8 |
9 function busyLoop(milliseconds) { | 9 function busyLoop(milliseconds) { |
10 var startTime = new Date().getTime(); | 10 var startTime = new Date().getTime(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 function(granted) { | 48 function(granted) { |
49 chrome.test.assertTrue(granted); | 49 chrome.test.assertTrue(granted); |
50 | 50 |
51 var request = function() { | 51 var request = function() { |
52 // The following request will fail if the user gesture is | 52 // The following request will fail if the user gesture is |
53 // expired. | 53 // expired. |
54 chrome.permissions.request( | 54 chrome.permissions.request( |
55 {permissions: ['bookmarks']}, | 55 {permissions: ['bookmarks']}, |
56 function(granted1) { | 56 function(granted1) { |
57 if (chrome.runtime.lastError) { | 57 if (chrome.runtime.lastError) { |
58 chrome.test.assertFalse(granted1); | 58 chrome.test.assertFalse(!!granted1); |
59 chrome.test.assertEq(chrome.runtime.lastError.message, | 59 chrome.test.assertEq(chrome.runtime.lastError.message, |
60 GESTURE_ERROR); | 60 GESTURE_ERROR); |
61 chrome.test.succeed(); | 61 chrome.test.succeed(); |
62 } else { | 62 } else { |
63 console.log("Retrying permissions.request in 3 " + | 63 console.log("Retrying permissions.request in 3 " + |
64 "seconds"); | 64 "seconds"); |
65 busyLoop(3000); | 65 busyLoop(3000); |
66 request(); | 66 request(); |
67 } | 67 } |
68 }); | 68 }); |
69 }; | 69 }; |
70 | 70 |
71 // Wait 2s since the user gesture timeout is 1s. | 71 // Wait 2s since the user gesture timeout is 1s. |
72 busyLoop(2000); | 72 busyLoop(2000); |
73 request(); | 73 request(); |
74 } | 74 } |
75 ); | 75 ); |
76 }); | 76 }); |
77 } | 77 } |
78 ]); | 78 ]); |
79 }); | 79 }); |
OLD | NEW |