| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 252 |
| 253 size_t GetExternalInstallBubbleCount(ExtensionService* service) { | 253 size_t GetExternalInstallBubbleCount(ExtensionService* service) { |
| 254 size_t bubble_count = 0u; | 254 size_t bubble_count = 0u; |
| 255 std::vector<ExternalInstallError*> errors = | 255 std::vector<ExternalInstallError*> errors = |
| 256 service->external_install_manager()->GetErrorsForTesting(); | 256 service->external_install_manager()->GetErrorsForTesting(); |
| 257 for (auto* error : errors) | 257 for (auto* error : errors) |
| 258 bubble_count += error->alert_type() == ExternalInstallError::BUBBLE_ALERT; | 258 bubble_count += error->alert_type() == ExternalInstallError::BUBBLE_ALERT; |
| 259 return bubble_count; | 259 return bubble_count; |
| 260 } | 260 } |
| 261 | 261 |
| 262 scoped_refptr<Extension> CreateExtension(const base::string16& name, | |
| 263 const base::FilePath& path, | |
| 264 Manifest::Location location) { | |
| 265 base::DictionaryValue manifest; | |
| 266 manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); | |
| 267 manifest.SetString(extensions::manifest_keys::kName, name); | |
| 268 std::string error; | |
| 269 scoped_refptr<Extension> extension = | |
| 270 Extension::Create(path, location, manifest, Extension::NO_FLAGS, &error); | |
| 271 EXPECT_TRUE(extension.get() != nullptr) << error; | |
| 272 return extension; | |
| 273 } | |
| 274 | |
| 275 } // namespace | 262 } // namespace |
| 276 | 263 |
| 277 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 264 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 278 public: | 265 public: |
| 279 MockExtensionProvider( | 266 MockExtensionProvider( |
| 280 VisitorInterface* visitor, | 267 VisitorInterface* visitor, |
| 281 Manifest::Location location) | 268 Manifest::Location location) |
| 282 : location_(location), visitor_(visitor), visit_count_(0) { | 269 : location_(location), visitor_(visitor), visit_count_(0) { |
| 283 } | 270 } |
| 284 | 271 |
| (...skipping 6130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6415 const Extension* extension = | 6402 const Extension* extension = |
| 6416 registry()->disabled_extensions().GetByID(page_action); | 6403 registry()->disabled_extensions().GetByID(page_action); |
| 6417 EXPECT_TRUE(extension); | 6404 EXPECT_TRUE(extension); |
| 6418 EXPECT_EQ(page_action, extension->id()); | 6405 EXPECT_EQ(page_action, extension->id()); |
| 6419 | 6406 |
| 6420 service()->EnableExtension(page_action); | 6407 service()->EnableExtension(page_action); |
| 6421 EXPECT_FALSE(HasExternalInstallErrors(service())); | 6408 EXPECT_FALSE(HasExternalInstallErrors(service())); |
| 6422 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); | 6409 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); |
| 6423 } | 6410 } |
| 6424 | 6411 |
| 6425 // As for components, only external component extensions can be disabled. | |
| 6426 TEST_F(ExtensionServiceTest, DisablingComponentExtensions) { | |
| 6427 InitializeEmptyExtensionService(); | |
| 6428 service_->Init(); | |
| 6429 | |
| 6430 scoped_refptr<Extension> external_component_extension = CreateExtension( | |
| 6431 base::ASCIIToUTF16("external_component_extension"), | |
| 6432 base::FilePath(FILE_PATH_LITERAL("//external_component_extension")), | |
| 6433 Manifest::EXTERNAL_COMPONENT); | |
| 6434 service_->AddExtension(external_component_extension.get()); | |
| 6435 EXPECT_TRUE(registry()->enabled_extensions().Contains( | |
| 6436 external_component_extension->id())); | |
| 6437 service_->DisableExtension(external_component_extension->id(), | |
| 6438 extensions::Extension::DISABLE_USER_ACTION); | |
| 6439 EXPECT_TRUE(registry()->disabled_extensions().Contains( | |
| 6440 external_component_extension->id())); | |
| 6441 | |
| 6442 scoped_refptr<Extension> component_extension = CreateExtension( | |
| 6443 base::ASCIIToUTF16("component_extension"), | |
| 6444 base::FilePath(FILE_PATH_LITERAL("//component_extension")), | |
| 6445 Manifest::COMPONENT); | |
| 6446 service_->AddExtension(component_extension.get()); | |
| 6447 EXPECT_TRUE( | |
| 6448 registry()->enabled_extensions().Contains(component_extension->id())); | |
| 6449 service_->DisableExtension(component_extension->id(), | |
| 6450 extensions::Extension::DISABLE_USER_ACTION); | |
| 6451 EXPECT_FALSE( | |
| 6452 registry()->disabled_extensions().Contains(component_extension->id())); | |
| 6453 } | |
| 6454 | |
| 6455 // Test that installing multiple external extensions works. | 6412 // Test that installing multiple external extensions works. |
| 6456 // Flaky on windows; http://crbug.com/295757 . | 6413 // Flaky on windows; http://crbug.com/295757 . |
| 6457 // Causes race conditions with an in-process utility thread, so disable under | 6414 // Causes race conditions with an in-process utility thread, so disable under |
| 6458 // TSan: https://crbug.com/518957 | 6415 // TSan: https://crbug.com/518957 |
| 6459 #if defined(OS_WIN) || defined(THREAD_SANITIZER) | 6416 #if defined(OS_WIN) || defined(THREAD_SANITIZER) |
| 6460 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple | 6417 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6461 #else | 6418 #else |
| 6462 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple | 6419 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6463 #endif | 6420 #endif |
| 6464 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { | 6421 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7168 | 7125 |
| 7169 // Wait for the reload to complete. This previously crashed (see | 7126 // Wait for the reload to complete. This previously crashed (see |
| 7170 // crbug.com/676815). | 7127 // crbug.com/676815). |
| 7171 base::RunLoop().RunUntilIdle(); | 7128 base::RunLoop().RunUntilIdle(); |
| 7172 // The extension should be enabled again... | 7129 // The extension should be enabled again... |
| 7173 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); | 7130 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7174 // ...and should have reloaded (for ease, we just compare the extension | 7131 // ...and should have reloaded (for ease, we just compare the extension |
| 7175 // objects). | 7132 // objects). |
| 7176 EXPECT_NE(extension, registry()->enabled_extensions().GetByID(kExtensionId)); | 7133 EXPECT_NE(extension, registry()->enabled_extensions().GetByID(kExtensionId)); |
| 7177 } | 7134 } |
| OLD | NEW |