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..cf553b79a3123fa5c97ca16710b4f2f9c5d55d1e 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 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.
|
+// a valid persisted permission even when active permissions are cleared. |
+TEST_F(ActiveScriptControllerUnitTest, TestAlwaysRun) { |
+ 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 run" menu item. |
+ controller()->AlwaysRunOnVisibleHost(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)); |
+ |
+ // Reinitializing permissions should clear active permissions, but not |
+ // persisted permissions. |
+ 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.
|
+ Reload(); |
+ EXPECT_FALSE(RequiresUserConsent(extension)); |
+} |
+ |
} // namespace extensions |