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

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

Issue 1285263006: Revert of [Script Injection] Allow whitelisted extensions to inject scripts everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/all_urls/bystander/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/all_urls_apitest.cc
diff --git a/chrome/browser/extensions/all_urls_apitest.cc b/chrome/browser/extensions/all_urls_apitest.cc
index ab83cbdb41061a495c221c46a2a9e89172f32f80..2c1ba28bd0981f9b2bdf09d6377c1fdfb3e770a8 100644
--- a/chrome/browser/extensions/all_urls_apitest.cc
+++ b/chrome/browser/extensions/all_urls_apitest.cc
@@ -4,7 +4,6 @@
#include "base/command_line.h"
#include "chrome/browser/extensions/extension_apitest.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/test_switches.h"
@@ -16,46 +15,9 @@
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
-namespace extensions {
+const std::string kAllUrlsTarget = "/extensions/api_test/all_urls/index.html";
-namespace {
-const std::string kAllUrlsTarget = "/extensions/api_test/all_urls/index.html";
-}
-
-class AllUrlsApiTest : public ExtensionApiTest {
- protected:
- AllUrlsApiTest() {}
- ~AllUrlsApiTest() override {}
-
- const Extension* content_script() const { return content_script_.get(); }
- const Extension* execute_script() const { return execute_script_.get(); }
-
- void WhitelistExtensions() {
- ExtensionsClient::ScriptingWhitelist whitelist;
- whitelist.push_back(content_script_->id());
- whitelist.push_back(execute_script_->id());
- ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
- // Extensions will have certain permissions withheld at initialization if
- // they aren't whitelisted, so we need to reload them.
- extension_service()->ReloadExtension(content_script_->id());
- extension_service()->ReloadExtension(execute_script_->id());
- }
-
- private:
- void SetUpOnMainThread() override {
- ExtensionApiTest::SetUpOnMainThread();
- base::FilePath data_dir = test_data_dir_.AppendASCII("all_urls");
- content_script_ = LoadExtension(data_dir.AppendASCII("content_script"));
- ASSERT_TRUE(content_script_);
- execute_script_ = LoadExtension(data_dir.AppendASCII("execute_script"));
- ASSERT_TRUE(execute_script_);
- }
-
- scoped_refptr<const Extension> content_script_;
- scoped_refptr<const Extension> execute_script_;
-
- DISALLOW_COPY_AND_ASSIGN(AllUrlsApiTest);
-};
+typedef ExtensionApiTest AllUrlsApiTest;
#if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_CHROMEOS)
// http://crbug.com/174341
@@ -71,7 +33,25 @@
return;
#endif
- WhitelistExtensions();
+ // First setup the two extensions.
+ base::FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
+ .AppendASCII("content_script");
+ base::FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
+ .AppendASCII("execute_script");
+
+ // Then add the two extensions to the whitelist.
+ extensions::ExtensionsClient::ScriptingWhitelist whitelist;
+ whitelist.push_back(crx_file::id_util::GenerateIdForPath(extension_dir1));
+ whitelist.push_back(crx_file::id_util::GenerateIdForPath(extension_dir2));
+ extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
+
+ // Then load extensions.
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser()->profile());
+ const size_t size_before = registry->enabled_extensions().size();
+ ASSERT_TRUE(LoadExtension(extension_dir1));
+ ASSERT_TRUE(LoadExtension(extension_dir2));
+ EXPECT_EQ(size_before + 2, registry->enabled_extensions().size());
std::string url;
@@ -121,6 +101,19 @@
// Test that an extension NOT whitelisted for scripting can ask for <all_urls>
// and run scripts on non-restricted all pages.
IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, RegularExtensions) {
+ // First load the two extensions.
+ base::FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
+ .AppendASCII("content_script");
+ base::FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
+ .AppendASCII("execute_script");
+
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser()->profile());
+ const size_t size_before = registry->enabled_extensions().size();
+ ASSERT_TRUE(LoadExtension(extension_dir1));
+ ASSERT_TRUE(LoadExtension(extension_dir2));
+ EXPECT_EQ(size_before + 2, registry->enabled_extensions().size());
+
// Now verify we can script a regular http page.
ASSERT_TRUE(StartEmbeddedTestServer());
GURL page_url = embedded_test_server()->GetURL(kAllUrlsTarget);
@@ -131,25 +124,3 @@
ASSERT_TRUE(listener1a.WaitUntilSatisfied());
ASSERT_TRUE(listener1b.WaitUntilSatisfied());
}
-
-IN_PROC_BROWSER_TEST_F(AllUrlsApiTest,
- WhitelistedExtensionRunsOnExtensionPages) {
- WhitelistExtensions();
- const Extension* bystander =
- LoadExtension(test_data_dir_.AppendASCII("all_urls")
- .AppendASCII("bystander"));
- ASSERT_TRUE(bystander);
-
- // TODO(devlin): This test should probably go in the WhitelistedExtension test
- // above, but that one has a bunch of disableds, so it wouldn't be very
- // useful.
- GURL url(bystander->GetResourceURL("page.html"));
- ExtensionTestMessageListener listenerA(
- "content script: " + url.spec(), false);
- ExtensionTestMessageListener listenerB("execute: " + url.spec(), false);
- ui_test_utils::NavigateToURL(browser(), GURL(url));
- ASSERT_TRUE(listenerA.WaitUntilSatisfied());
- ASSERT_TRUE(listenerB.WaitUntilSatisfied());
-}
-
-} // namespace extensions
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/all_urls/bystander/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698