| 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 "chrome/browser/extensions/component_loader.h" | 5 #include "chrome/browser/extensions/component_loader.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "chrome/browser/extensions/test_extension_service.h" | 13 #include "chrome/browser/extensions/test_extension_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/testing_pref_service_syncable.h" | 17 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
| 23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 24 #include "extensions/common/extension_set.h" | 24 #include "extensions/common/extension_set.h" |
| 25 #include "extensions/common/manifest_handlers/background_info.h" | 25 #include "extensions/common/manifest_handlers/background_info.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) |
| 29 #include "chromeos/audio/cras_audio_handler.h" |
| 30 #endif |
| 31 |
| 28 namespace extensions { | 32 namespace extensions { |
| 29 | 33 |
| 30 namespace { | 34 namespace { |
| 31 | 35 |
| 32 class MockExtensionService : public TestExtensionService { | 36 class MockExtensionService : public TestExtensionService { |
| 33 private: | 37 private: |
| 34 bool ready_; | 38 bool ready_; |
| 35 size_t unloaded_count_; | 39 size_t unloaded_count_; |
| 36 ExtensionRegistry* registry_; | 40 ExtensionRegistry* registry_; |
| 37 | 41 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 98 |
| 95 // Read in the extension manifest. | 99 // Read in the extension manifest. |
| 96 ASSERT_TRUE(base::ReadFileToString( | 100 ASSERT_TRUE(base::ReadFileToString( |
| 97 extension_path_.Append(kManifestFilename), | 101 extension_path_.Append(kManifestFilename), |
| 98 &manifest_contents_)); | 102 &manifest_contents_)); |
| 99 | 103 |
| 100 // Register the local state prefs. | 104 // Register the local state prefs. |
| 101 #if defined(OS_CHROMEOS) | 105 #if defined(OS_CHROMEOS) |
| 102 local_state_.registry()->RegisterBooleanPref( | 106 local_state_.registry()->RegisterBooleanPref( |
| 103 prefs::kAccessibilitySpokenFeedbackEnabled, false); | 107 prefs::kAccessibilitySpokenFeedbackEnabled, false); |
| 108 |
| 109 // Tests on chromeos need to have the handler initialized because the |
| 110 // Hotword component extension uses it to determine which extension to |
| 111 // load. |
| 112 if (!chromeos::CrasAudioHandler::IsInitialized()) |
| 113 chromeos::CrasAudioHandler::InitializeForTesting(); |
| 104 #endif | 114 #endif |
| 105 } | 115 } |
| 106 | 116 |
| 107 protected: | 117 protected: |
| 108 content::TestBrowserThreadBundle thread_bundle_; | 118 content::TestBrowserThreadBundle thread_bundle_; |
| 109 TestingProfile profile_; | 119 TestingProfile profile_; |
| 110 MockExtensionService extension_service_; | 120 MockExtensionService extension_service_; |
| 111 TestingPrefServiceSyncable prefs_; | 121 TestingPrefServiceSyncable prefs_; |
| 112 TestingPrefServiceSimple local_state_; | 122 TestingPrefServiceSimple local_state_; |
| 113 ComponentLoader component_loader_; | 123 ComponentLoader component_loader_; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 component_loader_.AddOrReplace(known_extension); | 283 component_loader_.AddOrReplace(known_extension); |
| 274 EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); | 284 EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); |
| 275 EXPECT_EQ(1u, extension_service_.unloaded_count()); | 285 EXPECT_EQ(1u, extension_service_.unloaded_count()); |
| 276 | 286 |
| 277 // Add an invalid component extension. | 287 // Add an invalid component extension. |
| 278 std::string extension_id = component_loader_.AddOrReplace(invalid_extension); | 288 std::string extension_id = component_loader_.AddOrReplace(invalid_extension); |
| 279 EXPECT_TRUE(extension_id.empty()); | 289 EXPECT_TRUE(extension_id.empty()); |
| 280 } | 290 } |
| 281 | 291 |
| 282 } // namespace extensions | 292 } // namespace extensions |
| OLD | NEW |