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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/extensions/extension_browsertest.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_util.h" 21 #include "chrome/browser/extensions/extension_util.h"
21 #include "chrome/browser/extensions/shared_user_script_master.h" 22 #include "chrome/browser/extensions/shared_user_script_master.h"
22 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 23 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/test/base/in_process_browser_test.h" 30 #include "chrome/test/base/in_process_browser_test.h"
30 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
31 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
32 #include "content/public/browser/notification_details.h" 33 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
37 #include "extensions/browser/extension_registry.h" 38 #include "extensions/browser/extension_registry.h"
38 #include "extensions/browser/extension_system.h" 39 #include "extensions/browser/extension_system.h"
39 #include "extensions/common/extension.h" 40 #include "extensions/common/extension.h"
40 #include "extensions/common/extension_set.h" 41 #include "extensions/common/extension_set.h"
41 #include "extensions/common/feature_switch.h" 42 #include "extensions/common/feature_switch.h"
42 #include "net/base/filename_util.h" 43 #include "net/base/filename_util.h"
43 44
44 using extensions::FeatureSwitch; 45 using extensions::FeatureSwitch;
46 using extensions::ExtensionRegistry;
45 47
46 // This file contains high-level startup tests for the extensions system. We've 48 // This file contains high-level startup tests for the extensions system. We've
47 // had many silly bugs where command line flags did not get propagated correctly 49 // had many silly bugs where command line flags did not get propagated correctly
48 // into the services, so we didn't start correctly. 50 // into the services, so we didn't start correctly.
49 51
50 class ExtensionStartupTestBase : public InProcessBrowserTest { 52 class ExtensionStartupTestBase : public InProcessBrowserTest {
51 public: 53 public:
52 ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) { 54 ExtensionStartupTestBase() : unauthenticated_load_allowed_(true) {
53 num_expected_extensions_ = 3; 55 num_expected_extensions_ = 3;
54 } 56 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 .AppendASCII("extensions") 306 .AppendASCII("extensions")
305 .AppendASCII("app2"); 307 .AppendASCII("app2");
306 load_extensions_.push_back(fourth_extension_path.value()); 308 load_extensions_.push_back(fourth_extension_path.value());
307 } 309 }
308 }; 310 };
309 311
310 IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) { 312 IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
311 WaitForServicesToStart(4, true); 313 WaitForServicesToStart(4, true);
312 TestInjection(true, true); 314 TestInjection(true, true);
313 } 315 }
316
317 class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest {
318 public:
319 DisableExtensionsExceptBrowserTest() {}
320
321 void SetUpCommandLine(base::CommandLine* command_line) override;
322
323 ExtensionRegistry* GetExtensionRegistry() {
324 return ExtensionRegistry::Get(browser()->profile());
325 }
326 };
327
328 void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
329 base::CommandLine* command_line) {
330 ExtensionBrowserTest::SetUpCommandLine(command_line);
331 #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.
332 command_line->AppendSwitchASCII(switches::kDisableExtensionsExcept,
333 "chrome\\test\\data\\extensions\\app_dot_com_"
334 "app\\,"
335 "chrome\\test\\data\\extensions\\app\\");
336 #else
337 command_line->AppendSwitchASCII(switches::kDisableExtensionsExcept,
338 "chrome/test/data/extensions/app_dot_com_app/"
339 ",chrome/test/data/extensions/app/");
340 #endif
341 }
342
343 // Tests disabling all extensions except those listed
344 // (--disable-extensions-except).
345 IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
Devlin 2016/07/27 17:01:00 This test seems to be failing on the bots.
346 DisableExtensionsExceptFlag) {
347 EXPECT_FALSE(extension_service()->extensions_enabled());
348
349 // Count the number of component extensions.
350 int component_extensions = 0;
351 for (const scoped_refptr<const extensions::Extension>& extension :
352 GetExtensionRegistry()->enabled_extensions()) {
353 component_extensions +=
354 extensions::Manifest::IsComponentLocation(extension->location()) ? 1
355 : 0;
356 }
357
358 // Number of enabled extensions should be the sum of the number of component
359 // extensions and the of number extensions installed with
360 // --disable-extensions-except.
361 size_t num_expected_extensions = component_extensions + 2;
362
363 EXPECT_EQ(num_expected_extensions,
364 GetExtensionRegistry()->enabled_extensions().size());
365
366 // Checks that the extensions loaded with the --disable-extensions-except flag
367 // are enabled.
368 bool is_app_dot_com_extension_enabled = false;
369 bool is_app_test_extension_enabled = false;
370 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.
371 GetExtensionRegistry()->enabled_extensions()) {
372 if (extension->name() == "App Dot Com: The App") {
373 is_app_dot_com_extension_enabled = true;
374 }
375
376 if (extension->name() == "App Test") {
377 is_app_test_extension_enabled = true;
378 }
379 }
380 EXPECT_TRUE(is_app_dot_com_extension_enabled);
381 EXPECT_TRUE(is_app_test_extension_enabled);
382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698