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

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

Issue 2166513002: Create --disable-extensions-except switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Patch 2 Code Review Created 4 years, 5 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/extension_startup_browsertest.cc
diff --git a/chrome/browser/extensions/extension_startup_browsertest.cc b/chrome/browser/extensions/extension_startup_browsertest.cc
index 462f2ba9d06049f078fcec1192e2ce90b9632be5..e9f85bc4466a7feac4eea5324fd3fbed5e15ef5a 100644
--- a/chrome/browser/extensions/extension_startup_browsertest.cc
+++ b/chrome/browser/extensions/extension_startup_browsertest.cc
@@ -16,6 +16,7 @@
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/shared_user_script_master.h"
@@ -42,6 +43,7 @@
#include "net/base/filename_util.h"
using extensions::FeatureSwitch;
+using extensions::ExtensionRegistry;
// This file contains high-level startup tests for the extensions system. We've
// had many silly bugs where command line flags did not get propagated correctly
@@ -311,3 +313,70 @@ IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
WaitForServicesToStart(4, true);
TestInjection(true, true);
}
+
+class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest {
+ public:
+ DisableExtensionsExceptBrowserTest() {}
+
+ void SetUpCommandLine(base::CommandLine* command_line) override;
+
+ ExtensionRegistry* GetExtensionRegistry() {
+ return ExtensionRegistry::Get(browser()->profile());
+ }
+};
+
+void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
+ base::CommandLine* command_line) {
+ ExtensionBrowserTest::SetUpCommandLine(command_line);
+#if defined(OS_WIN)
Devlin 2016/07/27 17:00:59 This kind of platform-specific path logic is handl
catmullings 2016/08/04 22:59:31 Done.
+ command_line->AppendSwitchASCII(switches::kDisableExtensionsExcept,
+ "chrome\\test\\data\\extensions\\app_dot_com_"
+ "app\\,"
+ "chrome\\test\\data\\extensions\\app\\");
+#else
+ command_line->AppendSwitchASCII(switches::kDisableExtensionsExcept,
+ "chrome/test/data/extensions/app_dot_com_app/"
+ ",chrome/test/data/extensions/app/");
+#endif
+}
+
+// Tests disabling all extensions except those listed
+// (--disable-extensions-except).
+IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
Devlin 2016/07/27 17:01:00 This test seems to be failing on the bots.
+ DisableExtensionsExceptFlag) {
+ EXPECT_FALSE(extension_service()->extensions_enabled());
+
+ // Count the number of component extensions.
+ int component_extensions = 0;
+ for (const scoped_refptr<const extensions::Extension>& extension :
+ GetExtensionRegistry()->enabled_extensions()) {
+ component_extensions +=
+ extensions::Manifest::IsComponentLocation(extension->location()) ? 1
+ : 0;
+ }
+
+ // Number of enabled extensions should be the sum of the number of component
+ // extensions and the of number extensions installed with
+ // --disable-extensions-except.
+ size_t num_expected_extensions = component_extensions + 2;
+
+ EXPECT_EQ(num_expected_extensions,
+ GetExtensionRegistry()->enabled_extensions().size());
+
+ // Checks that the extensions loaded with the --disable-extensions-except flag
+ // are enabled.
+ bool is_app_dot_com_extension_enabled = false;
+ bool is_app_test_extension_enabled = false;
+ for (const scoped_refptr<const extensions::Extension>& extension :
Devlin 2016/07/27 17:01:00 Given we're looping over all extensions already, i
catmullings 2016/08/04 22:59:30 Done.
+ GetExtensionRegistry()->enabled_extensions()) {
+ if (extension->name() == "App Dot Com: The App") {
+ is_app_dot_com_extension_enabled = true;
+ }
+
+ if (extension->name() == "App Test") {
+ is_app_test_extension_enabled = true;
+ }
+ }
+ EXPECT_TRUE(is_app_dot_com_extension_enabled);
+ EXPECT_TRUE(is_app_test_extension_enabled);
+}

Powered by Google App Engine
This is Rietveld 408576698