Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "extensions/common/feature_switch.h" | 21 #include "extensions/common/feature_switch.h" |
| 22 #include "extensions/common/id_util.h" | 22 #include "extensions/common/id_util.h" |
| 23 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 24 #include "extensions/common/user_script.h" | 24 #include "extensions/common/user_script.h" |
| 25 #include "extensions/common/value_builder.h" | 25 #include "extensions/common/value_builder.h" |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kAllHostsPermission[] = "*://*/*"; | 31 const char kAllHostsPermission[] = "*://*/*"; |
|
not at google - send to devlin
2014/08/13 17:21:22
hm I'd actually like to check both this pattern an
gpdavis
2014/08/13 22:18:36
Acknowledged.
| |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 // Unittests for the ActiveScriptController mostly test the internal logic | 35 // Unittests for the ActiveScriptController mostly test the internal logic |
| 36 // of the controller itself (when to allow/deny extension script injection). | 36 // of the controller itself (when to allow/deny extension script injection). |
| 37 // Testing real injection is allowed/denied as expected (i.e., that the | 37 // Testing real injection is allowed/denied as expected (i.e., that the |
| 38 // ActiveScriptController correctly interfaces in the system) is done in the | 38 // ActiveScriptController correctly interfaces in the system) is done in the |
| 39 // ActiveScriptControllerBrowserTests. | 39 // ActiveScriptControllerBrowserTests. |
| 40 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { | 40 class ActiveScriptControllerUnitTest : public ChromeRenderViewHostTestHarness { |
| 41 protected: | 41 protected: |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 315 |
| 316 // Turning off the preference should have instant effect. | 316 // Turning off the preference should have instant effect. |
| 317 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); | 317 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); |
| 318 EXPECT_TRUE(RequiresUserConsent(extension)); | 318 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 319 | 319 |
| 320 // And should also persist across navigations and websites. | 320 // And should also persist across navigations and websites. |
| 321 NavigateAndCommit(GURL("http://www.bar.com")); | 321 NavigateAndCommit(GURL("http://www.bar.com")); |
| 322 EXPECT_TRUE(RequiresUserConsent(extension)); | 322 EXPECT_TRUE(RequiresUserConsent(extension)); |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Test that the "always run" extension action context menu item will create | |
|
Devlin
2014/08/13 16:55:03
This is separate from the context menu, and should
gpdavis
2014/08/13 22:18:36
Done.
| |
| 326 // a valid persisted permission even when active permissions are cleared. | |
| 327 TEST_F(ActiveScriptControllerUnitTest, TestAlwaysRun) { | |
| 328 const Extension* extension = AddExtension(); | |
| 329 ASSERT_TRUE(extension); | |
| 330 | |
| 331 NavigateAndCommit(GURL("https://www.google.com")); | |
| 332 | |
| 333 // Ensure that there aren't any executions pending. | |
| 334 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | |
| 335 ASSERT_FALSE(controller()->GetActionForExtension(extension)); | |
| 336 | |
| 337 // Since the extension requests all_hosts, we should require user consent. | |
| 338 EXPECT_TRUE(RequiresUserConsent(extension)); | |
| 339 | |
| 340 // Request an injection. There should be an action visible, but no executions. | |
| 341 RequestInjection(extension); | |
| 342 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | |
| 343 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | |
| 344 | |
| 345 // Simulate clicking "always run" menu item. | |
| 346 controller()->AlwaysRunOnVisibleHost(extension); | |
| 347 | |
| 348 // The extension should execute, and the action should go away. | |
| 349 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | |
| 350 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | |
| 351 | |
| 352 // Since we already executed on the given page, we shouldn't need permission | |
| 353 // for a second time. | |
| 354 EXPECT_FALSE(RequiresUserConsent(extension)); | |
| 355 | |
| 356 // Navigating to another site that hasn't been granted a persisted permission | |
| 357 // should necessitate user consent. | |
| 358 NavigateAndCommit(GURL("https://www.foo.com")); | |
| 359 EXPECT_TRUE(RequiresUserConsent(extension)); | |
| 360 | |
| 361 // We shouldn't need user permission upon returning to the original host. | |
| 362 NavigateAndCommit(GURL("https://www.google.com")); | |
| 363 EXPECT_FALSE(RequiresUserConsent(extension)); | |
| 364 | |
| 365 // Reinitializing permissions should clear active permissions, but not | |
| 366 // persisted permissions. | |
| 367 PermissionsUpdater(profile()).InitializePermissions(extension); | |
|
Devlin
2014/08/13 16:55:04
Better: unload and reload the extension.
gpdavis
2014/08/13 22:18:36
We don't seem to have an extension service for thi
not at google - send to devlin
2014/08/13 22:59:17
Yeah, testing this would require introducing a dep
gpdavis
2014/08/13 23:23:06
So... perhaps a later CL? Or what would you like
not at google - send to devlin
2014/08/13 23:32:47
Here's a good approximation we can implement witho
gpdavis
2014/08/14 00:55:28
Alright, that works.
| |
| 368 Reload(); | |
| 369 EXPECT_FALSE(RequiresUserConsent(extension)); | |
| 370 } | |
| 371 | |
| 325 } // namespace extensions | 372 } // namespace extensions |
| OLD | NEW |