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 base::DictionaryValue manifest; | |
| 265 manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); | |
| 266 manifest.SetString(extensions::manifest_keys::kName, name); | |
| 267 std::string error; | |
| 268 scoped_refptr<Extension> extension = | |
| 269 Extension::Create(path, location, manifest, Extension::NO_FLAGS, &error); | |
| 270 EXPECT_TRUE(extension.get() != nullptr) << error; | |
| 271 return extension; | |
| 272 } | |
| 273 | |
| 261 } // namespace | 274 } // namespace |
| 262 | 275 |
| 263 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 276 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 264 public: | 277 public: |
| 265 MockExtensionProvider( | 278 MockExtensionProvider( |
| 266 VisitorInterface* visitor, | 279 VisitorInterface* visitor, |
| 267 Manifest::Location location) | 280 Manifest::Location location) |
| 268 : location_(location), visitor_(visitor), visit_count_(0) { | 281 : location_(location), visitor_(visitor), visit_count_(0) { |
| 269 } | 282 } |
| 270 | 283 |
| (...skipping 6130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6401 const Extension* extension = | 6414 const Extension* extension = |
| 6402 registry()->disabled_extensions().GetByID(page_action); | 6415 registry()->disabled_extensions().GetByID(page_action); |
| 6403 EXPECT_TRUE(extension); | 6416 EXPECT_TRUE(extension); |
| 6404 EXPECT_EQ(page_action, extension->id()); | 6417 EXPECT_EQ(page_action, extension->id()); |
| 6405 | 6418 |
| 6406 service()->EnableExtension(page_action); | 6419 service()->EnableExtension(page_action); |
| 6407 EXPECT_FALSE(HasExternalInstallErrors(service())); | 6420 EXPECT_FALSE(HasExternalInstallErrors(service())); |
| 6408 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); | 6421 EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); |
| 6409 } | 6422 } |
| 6410 | 6423 |
| 6424 // As for components, only non-external component extensions can be disabled. | |
|
lazyboy
2017/01/24 03:30:01
external instead of non-external?
mtomasz
2017/01/26 08:47:06
Done.
| |
| 6425 TEST_F(ExtensionServiceTest, DisablingComponentExtensions) { | |
| 6426 InitializeEmptyExtensionService(); | |
| 6427 service_->Init(); | |
| 6428 | |
| 6429 base::ScopedTempDir temp_dir; | |
|
lazyboy
2017/01/24 03:30:01
Do you need this?
mtomasz
2017/01/26 08:47:06
Nope! Done.
| |
| 6430 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 6431 | |
| 6432 scoped_refptr<Extension> external_component_extension = CreateExtension( | |
| 6433 base::ASCIIToUTF16("external_component_extension"), | |
| 6434 base::FilePath(FILE_PATH_LITERAL("//external_component_extension")), | |
| 6435 Manifest::EXTERNAL_COMPONENT); | |
| 6436 service_->AddExtension(external_component_extension.get()); | |
| 6437 EXPECT_TRUE(registry()->enabled_extensions().Contains( | |
| 6438 external_component_extension->id())); | |
| 6439 service_->DisableExtension(external_component_extension->id(), | |
| 6440 extensions::Extension::DISABLE_USER_ACTION); | |
| 6441 EXPECT_TRUE(registry()->disabled_extensions().Contains( | |
| 6442 external_component_extension->id())); | |
| 6443 | |
| 6444 scoped_refptr<Extension> component_extension = CreateExtension( | |
| 6445 base::ASCIIToUTF16("component_extension"), | |
| 6446 base::FilePath(FILE_PATH_LITERAL("//component_extension")), | |
| 6447 Manifest::COMPONENT); | |
| 6448 service_->AddExtension(component_extension.get()); | |
| 6449 EXPECT_TRUE( | |
| 6450 registry()->enabled_extensions().Contains(component_extension->id())); | |
| 6451 service_->DisableExtension(component_extension->id(), | |
| 6452 extensions::Extension::DISABLE_USER_ACTION); | |
| 6453 EXPECT_FALSE( | |
| 6454 registry()->disabled_extensions().Contains(component_extension->id())); | |
| 6455 } | |
| 6456 | |
| 6411 // Test that installing multiple external extensions works. | 6457 // Test that installing multiple external extensions works. |
| 6412 // Flaky on windows; http://crbug.com/295757 . | 6458 // Flaky on windows; http://crbug.com/295757 . |
| 6413 // Causes race conditions with an in-process utility thread, so disable under | 6459 // Causes race conditions with an in-process utility thread, so disable under |
| 6414 // TSan: https://crbug.com/518957 | 6460 // TSan: https://crbug.com/518957 |
| 6415 #if defined(OS_WIN) || defined(THREAD_SANITIZER) | 6461 #if defined(OS_WIN) || defined(THREAD_SANITIZER) |
| 6416 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple | 6462 #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6417 #else | 6463 #else |
| 6418 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple | 6464 #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6419 #endif | 6465 #endif |
| 6420 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { | 6466 TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7091 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 7137 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 7092 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | 7138 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 7093 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); | 7139 EXPECT_TRUE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); |
| 7094 | 7140 |
| 7095 base::FilePath v2_path = data_dir().AppendASCII("good2.crx"); | 7141 base::FilePath v2_path = data_dir().AppendASCII("good2.crx"); |
| 7096 UpdateExtension(id, v2_path, ENABLED); | 7142 UpdateExtension(id, v2_path, ENABLED); |
| 7097 | 7143 |
| 7098 EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); | 7144 EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
| 7099 EXPECT_FALSE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); | 7145 EXPECT_FALSE(prefs->HasDisableReason(id, Extension::DISABLE_CORRUPTED)); |
| 7100 } | 7146 } |
| OLD | NEW |