Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 251 |
| 252 size_t GetExternalInstallBubbleCount(ExtensionService* service) { | 252 size_t GetExternalInstallBubbleCount(ExtensionService* service) { |
| 253 size_t bubble_count = 0u; | 253 size_t bubble_count = 0u; |
| 254 std::vector<ExternalInstallError*> errors = | 254 std::vector<ExternalInstallError*> errors = |
| 255 service->external_install_manager()->GetErrorsForTesting(); | 255 service->external_install_manager()->GetErrorsForTesting(); |
| 256 for (auto* error : errors) | 256 for (auto* error : errors) |
| 257 bubble_count += error->alert_type() == ExternalInstallError::BUBBLE_ALERT; | 257 bubble_count += error->alert_type() == ExternalInstallError::BUBBLE_ALERT; |
| 258 return bubble_count; | 258 return bubble_count; |
| 259 } | 259 } |
| 260 | 260 |
| 261 scoped_refptr<Extension> CreateExtension(const base::string16& name, | |
| 262 const base::FilePath& path, | |
| 263 Manifest::Location location, | |
| 264 extensions::Manifest::Type type, | |
| 265 bool installed_by_default) { | |
|
battre
2017/01/20 07:17:05
type and installed_by_default are not used. I sugg
mtomasz
2017/01/20 07:24:49
Done.
| |
| 266 base::DictionaryValue manifest; | |
| 267 manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); | |
| 268 manifest.SetString(extensions::manifest_keys::kName, name); | |
| 269 std::string error; | |
| 270 scoped_refptr<Extension> extension = | |
| 271 Extension::Create(path, location, manifest, Extension::NO_FLAGS, &error); | |
| 272 EXPECT_TRUE(extension.get() != NULL) << error; | |
|
battre
2017/01/20 07:17:05
nullptr
mtomasz
2017/01/20 07:24:49
Done.
| |
| 273 return extension; | |
| 274 } | |
| 275 | |
| 261 } // namespace | 276 } // namespace |
| 262 | 277 |
| 263 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 278 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 264 public: | 279 public: |
| 265 MockExtensionProvider( | 280 MockExtensionProvider( |
| 266 VisitorInterface* visitor, | 281 VisitorInterface* visitor, |
| 267 Manifest::Location location) | 282 Manifest::Location location) |
| 268 : location_(location), visitor_(visitor), visit_count_(0) { | 283 : location_(location), visitor_(visitor), visit_count_(0) { |
| 269 } | 284 } |
| 270 | 285 |
| (...skipping 6130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6401 const Extension* extension = | 6416 const Extension* extension = |
| 6402 registry()->disabled_extensions().GetByID(page_action); | 6417 registry()->disabled_extensions().GetByID(page_action); |
| 6403 EXPECT_TRUE(extension); | 6418 EXPECT_TRUE(extension); |
| 6404 EXPECT_EQ(page_action, extension->id()); | 6419 EXPECT_EQ(page_action, extension->id()); |
| 6405 | 6420 |
| 6406 service()->EnableExtension(page_action); | 6421 service()->EnableExtension(page_action); |
| 6407 EXPECT_FALSE(HasExternalInstallErrors(service())); | 6422 EXPECT_FALSE(HasExternalInstallErrors(service())); |
| 6408 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); | 6423 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); |
| 6409 } | 6424 } |
| 6410 | 6425 |
| 6426 // As for components, only non-external component extensions can be disabled. | |
| 6427 TEST_F(ExtensionServiceTest, DisablingComponentExtensions) { | |
| 6428 InitializeEmptyExtensionService(); | |
| 6429 service_->Init(); | |
| 6430 | |
| 6431 base::ScopedTempDir temp_dir; | |
| 6432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 6433 | |
| 6434 scoped_refptr<Extension> external_component_extension = CreateExtension( | |
| 6435 base::ASCIIToUTF16("external_component_extension"), | |
| 6436 base::FilePath(FILE_PATH_LITERAL("//external_component_extension")), | |
| 6437 Manifest::EXTERNAL_COMPONENT, extensions::Manifest::TYPE_EXTENSION, | |
| 6438 false); | |
| 6439 service_->AddExtension(external_component_extension.get()); | |
| 6440 EXPECT_TRUE(registry()->enabled_extensions().Contains( | |
| 6441 external_component_extension->id())); | |
| 6442 service_->DisableExtension(external_component_extension->id(), | |
| 6443 extensions::Extension::DISABLE_USER_ACTION); | |
| 6444 EXPECT_TRUE(registry()->disabled_extensions().Contains( | |
| 6445 external_component_extension->id())); | |
| 6446 | |
| 6447 scoped_refptr<Extension> component_extension = CreateExtension( | |
| 6448 base::ASCIIToUTF16("component_extension"), | |
| 6449 base::FilePath(FILE_PATH_LITERAL("//component_extension")), | |
| 6450 Manifest::COMPONENT, extensions::Manifest::TYPE_EXTENSION, false); | |
| 6451 service_->AddExtension(component_extension.get()); | |
| 6452 EXPECT_TRUE( | |
| 6453 registry()->enabled_extensions().Contains(component_extension->id())); | |
| 6454 service_->DisableExtension(component_extension->id(), | |
| 6455 extensions::Extension::DISABLE_USER_ACTION); | |
| 6456 EXPECT_FALSE( | |
| 6457 registry()->disabled_extensions().Contains(component_extension->id())); | |
| 6458 } | |
| 6459 | |
| 6411 // Test that installing multiple external extensions works. | 6460 // Test that installing multiple external extensions works. |
| 6412 // Flaky on windows; http://crbug.com/295757 . | 6461 // Flaky on windows; http://crbug.com/295757 . |
| 6413 // Causes race conditions with an in-process utility thread, so disable under | 6462 // Causes race conditions with an in-process utility thread, so disable under |
| 6414 // TSan: https://crbug.com/518957 | 6463 // TSan: https://crbug.com/518957 |
| 6415 #if defined(OS_WIN) || defined(THREAD_SANITIZER) | 6464 #if defined(OS_WIN) || defined(THREAD_SANITIZER) |
| 6416 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple | 6465 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6417 #else | 6466 #else |
| 6418 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple | 6467 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6419 #endif | 6468 #endif |
| 6420 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { | 6469 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7091 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 7140 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 7092 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | 7141 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 7093 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); | 7142 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); |
| 7094 | 7143 |
| 7095 base::FilePath v2_path = data_dir().AppendASCII("good2.crx"); | 7144 base::FilePath v2_path = data_dir().AppendASCII("good2.crx"); |
| 7096 UpdateExtension(id, v2_path, ENABLED); | 7145 UpdateExtension(id, v2_path, ENABLED); |
| 7097 | 7146 |
| 7098 EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); | 7147 EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
| 7099 EXPECT_FALSE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); | 7148 EXPECT_FALSE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); |
| 7100 } | 7149 } |
| OLD | NEW |