Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // DisableExtensionsExceptBrowserTest | |
|
Devlin
2016/07/25 19:10:29
This line probably isn't necessary.
catmullings
2016/07/27 01:29:45
Done.
| |
| 318 // 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.
| |
| 319 // all extensions except those listed. | |
| 320 class DisableExtensionsExceptBrowserTest : public ExtensionBrowserTest { | |
| 321 public: | |
| 322 DisableExtensionsExceptBrowserTest() {} | |
| 323 | |
| 324 void SetUpCommandLine(base::CommandLine* command_line) override; | |
| 325 | |
| 326 ExtensionRegistry* GetExtensionRegistry() { | |
| 327 return ExtensionRegistry::Get(browser()->profile()); | |
| 328 } | |
| 329 }; | |
| 330 | |
| 331 // 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.
| |
| 332 void DisableExtensionsExceptBrowserTest::SetUpCommandLine( | |
| 333 base::CommandLine* command_line) { | |
| 334 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
| 335 | |
| 336 command_line->AppendSwitchASCII( | |
| 337 switches::kDisableExtensionsExcept, | |
| 338 "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.
| |
| 339 } | |
| 340 | |
| 341 // Tests disabling all extensions except those listed | |
| 342 // (--disable-extensions-except). | |
| 343 IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest, | |
| 344 DisableExtensionsExceptFlag) { | |
| 345 EXPECT_FALSE(extension_service()->extensions_enabled()); | |
| 346 | |
| 347 // Count the number of component extensions. | |
| 348 int component_extensions = 0; | |
| 349 for (const scoped_refptr<const extensions::Extension>& extension : | |
| 350 GetExtensionRegistry()->enabled_extensions()) { | |
| 351 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.
| |
| 352 component_extensions++; | |
| 353 } | |
| 354 | |
| 355 // Number of enabled extensions should be the sum of the number of component | |
| 356 // extensions and the of number extensions installed with | |
| 357 // --disable-extensions-except. | |
| 358 int num_expected_extensions = component_extensions + 1; | |
| 359 | |
| 360 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.
| |
| 361 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.
| |
| 362 } | |
| OLD | NEW |