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 #include <map> | 5 #include <map> |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/active_script_controller.h" | 8 #include "chrome/browser/extensions/active_script_controller.h" |
9 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 9 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 212 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
213 | 213 |
214 // Request an injection. There should be an action visible, but no executions. | 214 // Request an injection. There should be an action visible, but no executions. |
215 controller()->RequestScriptInjection( | 215 controller()->RequestScriptInjection( |
216 extension, | 216 extension, |
217 GetPageId(), | 217 GetPageId(), |
218 GetExecutionCallbackForExtension(extension->id())); | 218 GetExecutionCallbackForExtension(extension->id())); |
219 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 219 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
220 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 220 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
221 | 221 |
222 // Navigate away. This should remove the pending injection, and we should not | 222 // Reload. This should remove the pending injection, and we should not |
223 // execute anything. | 223 // execute anything. |
224 NavigateAndCommit(GURL("https://www.google.com")); | 224 Reload(); |
225 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | 225 EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
226 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 226 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
227 | 227 |
228 // Request and accept a new injection. | 228 // Request and accept a new injection. |
229 controller()->RequestScriptInjection( | 229 controller()->RequestScriptInjection( |
230 extension, | 230 extension, |
231 GetPageId(), | 231 GetPageId(), |
232 GetExecutionCallbackForExtension(extension->id())); | 232 GetExecutionCallbackForExtension(extension->id())); |
233 controller()->OnClicked(extension); | 233 controller()->OnClicked(extension); |
234 | 234 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ASSERT_TRUE(active_tab_permission_granter); | 274 ASSERT_TRUE(active_tab_permission_granter); |
275 // Grant the extension active tab permissions. This normally happens, e.g., | 275 // Grant the extension active tab permissions. This normally happens, e.g., |
276 // if the user clicks on a browser action. | 276 // if the user clicks on a browser action. |
277 active_tab_permission_granter->GrantIfRequested(extension); | 277 active_tab_permission_granter->GrantIfRequested(extension); |
278 | 278 |
279 // Since we have active tab permissions, we shouldn't need user consent | 279 // Since we have active tab permissions, we shouldn't need user consent |
280 // anymore. | 280 // anymore. |
281 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); | 281 EXPECT_FALSE(controller()->RequiresUserConsentForScriptInjection(extension)); |
282 | 282 |
283 // Also test that granting active tab runs any pending tasks. | 283 // Also test that granting active tab runs any pending tasks. |
284 NavigateAndCommit(GURL("https://www.google.com")); | 284 Reload(); |
285 // Navigating should mean we need permission again. | 285 // Navigating should mean we need permission again. |
286 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 286 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); |
287 | 287 |
288 controller()->RequestScriptInjection( | 288 controller()->RequestScriptInjection( |
289 extension, | 289 extension, |
290 GetPageId(), | 290 GetPageId(), |
291 GetExecutionCallbackForExtension(extension->id())); | 291 GetExecutionCallbackForExtension(extension->id())); |
292 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | 292 EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
293 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | 293 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
294 | 294 |
(...skipping 24 matching lines...) Expand all Loading... |
319 // Turning off the preference should have instant effect. | 319 // Turning off the preference should have instant effect. |
320 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); | 320 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); |
321 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 321 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); |
322 | 322 |
323 // And should also persist across navigations and websites. | 323 // And should also persist across navigations and websites. |
324 NavigateAndCommit(GURL("http://www.bar.com")); | 324 NavigateAndCommit(GURL("http://www.bar.com")); |
325 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); | 325 EXPECT_TRUE(controller()->RequiresUserConsentForScriptInjection(extension)); |
326 } | 326 } |
327 | 327 |
328 } // namespace extensions | 328 } // namespace extensions |
OLD | NEW |