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..a05123f46e2d6e7ae2c58bebc477cf5d79793425 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,50 @@ IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) { |
WaitForServicesToStart(4, true); |
TestInjection(true, true); |
} |
+ |
+// DisableExtensionsExceptBrowserTest |
Devlin
2016/07/25 19:10:29
This line probably isn't necessary.
catmullings
2016/07/27 01:29:45
Done.
|
+// Ensures that the --disable-extesions-except command line flag disables |
Devlin
2016/07/25 19:10:30
This sounds like a test description, rather than a
catmullings
2016/07/27 01:29:45
Done.
catmullings
2016/07/27 01:29:46
I will just remove it.
|
+// all extensions except those listed. |
+class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest { |
+ public: |
+ DisableExtensionsExceptBrowserTest() {} |
+ |
+ void SetUpCommandLine(base::CommandLine* command_line) override; |
+ |
+ ExtensionRegistry* GetExtensionRegistry() { |
+ return ExtensionRegistry::Get(browser()->profile()); |
+ } |
+}; |
+ |
+// Adds --disable-extesions-except command line flag. |
Devlin
2016/07/25 19:10:29
Since this is pretty obvious from the code, I'd om
catmullings
2016/07/27 01:29:45
Done.
|
+void DisableExtensionsExceptBrowserTest::SetUpCommandLine( |
+ base::CommandLine* command_line) { |
+ ExtensionBrowserTest::SetUpCommandLine(command_line); |
+ |
+ command_line->AppendSwitchASCII( |
+ switches::kDisableExtensionsExcept, |
+ "chrome/test/data/extensions/app_dot_com_app/"); |
Devlin
2016/07/25 19:10:30
Can we test with multiple extensions, too?
Also,
catmullings
2016/07/27 01:29:46
Done.
|
+} |
+ |
+// Tests disabling all extensions except those listed |
+// (--disable-extensions-except). |
+IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest, |
+ 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()) { |
+ if (extension->location() == extensions::Manifest::COMPONENT) |
Devlin
2016/07/25 19:10:29
prefer Manifest::IsComponentLocation() over compar
Devlin
2016/07/25 19:10:30
optional fanciness:
component_extensions += Manife
catmullings
2016/07/27 01:29:46
Done.
catmullings
2016/07/27 01:29:46
Done.
|
+ component_extensions++; |
+ } |
+ |
+ // Number of enabled extensions should be the sum of the number of component |
+ // extensions and the of number extensions installed with |
+ // --disable-extensions-except. |
+ int num_expected_extensions = component_extensions + 1; |
+ |
+ EXPECT_EQ(static_cast<uint32_t>(num_expected_extensions), |
Devlin
2016/07/25 19:10:29
Why not instantiate num_expected_extensions as siz
catmullings
2016/07/27 01:29:46
Done.
|
+ GetExtensionRegistry()->enabled_extensions().size()); |
Devlin
2016/07/25 19:10:30
Can we also check that the other extension is the
catmullings
2016/07/27 01:29:46
Done.
|
+} |