Chromium Code Reviews| Index: chrome/browser/extensions/active_script_controller_unittest.cc |
| diff --git a/chrome/browser/extensions/active_script_controller_unittest.cc b/chrome/browser/extensions/active_script_controller_unittest.cc |
| index 01fe26ba0cf72bcc319482f4dd6684c120a1d75c..52e079279ab2d00952e8a435181640ce67c24b9c 100644 |
| --- a/chrome/browser/extensions/active_script_controller_unittest.cc |
| +++ b/chrome/browser/extensions/active_script_controller_unittest.cc |
| @@ -322,4 +322,51 @@ TEST_F(ActiveScriptControllerUnitTest, ActiveScriptsCanHaveAllUrlsPref) { |
| EXPECT_TRUE(RequiresUserConsent(extension)); |
| } |
| +// Test that the "always allow" extension action context menu item will create |
| +// a valid persisted permission even when active permissions are cleared. |
| +TEST_F(ActiveScriptControllerUnitTest, TestAlwaysAllow) { |
| + const Extension* extension = AddExtension(); |
| + ASSERT_TRUE(extension); |
| + |
| + NavigateAndCommit(GURL("https://www.google.com")); |
| + |
| + // Ensure that there aren't any executions pending. |
| + ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| + ASSERT_FALSE(controller()->GetActionForExtension(extension)); |
| + |
| + // Since the extension requests all_hosts, we should require user consent. |
| + EXPECT_TRUE(RequiresUserConsent(extension)); |
| + |
| + // Request an injection. There should be an action visible, but no executions. |
| + RequestInjection(extension); |
| + EXPECT_TRUE(controller()->GetActionForExtension(extension)); |
| + EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); |
| + |
| + // Simulate clicking "always allow" menu item. |
| + controller()->AddPersistedPermission(extension); |
| + |
| + // The extension should execute, and the action should go away. |
| + EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); |
| + EXPECT_FALSE(controller()->GetActionForExtension(extension)); |
| + |
| + // Since we already executed on the given page, we shouldn't need permission |
| + // for a second time. |
| + EXPECT_FALSE(RequiresUserConsent(extension)); |
| + |
| + // Navigating to another site that hasn't been granted a persisted permission |
| + // should necessitate user consent. |
| + NavigateAndCommit(GURL("https://www.foo.com")); |
| + EXPECT_TRUE(RequiresUserConsent(extension)); |
| + |
| + // We shouldn't need user permission upon returning to the original host. |
| + NavigateAndCommit(GURL("https://www.google.com")); |
| + EXPECT_FALSE(RequiresUserConsent(extension)); |
|
gpdavis
2014/07/21 20:25:40
This check fails. I think this has to do with act
|
| + |
| + // Reinitializing permissions should clear active permissions, but not |
| + // persisted permissions. |
| + PermissionsUpdater(profile()).InitializePermissions(extension); |
| + Reload(); |
| + EXPECT_FALSE(RequiresUserConsent(extension)); |
|
gpdavis
2014/07/21 20:25:40
This check also fails, but I'm not sure why. The
|
| +} |
| + |
| } // namespace extensions |