Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: chrome/browser/extensions/active_script_controller_unittest.cc

Issue 396033002: Support "always allow" for runtime script execution (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Histogram updates Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..670c5bf5b8e3cbe41382ce75a088fbdc1f0fbd2d 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
+// 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 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);
+ Reload();
+ EXPECT_FALSE(RequiresUserConsent(extension));
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698