| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_test_base.h" | 5 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ExtensionServiceInitParams() {} | 76 ExtensionServiceInitParams() {} |
| 77 | 77 |
| 78 ExtensionServiceTestBase::ExtensionServiceInitParams:: | 78 ExtensionServiceTestBase::ExtensionServiceInitParams:: |
| 79 ExtensionServiceInitParams(const ExtensionServiceInitParams& other) = | 79 ExtensionServiceInitParams(const ExtensionServiceInitParams& other) = |
| 80 default; | 80 default; |
| 81 | 81 |
| 82 ExtensionServiceTestBase::ExtensionServiceTestBase() | 82 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 83 : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)), | 83 : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)), |
| 84 service_(NULL), | 84 service_(NULL), |
| 85 testing_local_state_(TestingBrowserProcess::GetGlobal()), | 85 testing_local_state_(TestingBrowserProcess::GetGlobal()), |
| 86 did_reset_thread_bundle_(false), | |
| 87 registry_(NULL) { | 86 registry_(NULL) { |
| 88 base::FilePath test_data_dir; | 87 base::FilePath test_data_dir; |
| 89 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 88 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 90 ADD_FAILURE(); | 89 ADD_FAILURE(); |
| 91 return; | 90 return; |
| 92 } | 91 } |
| 93 data_dir_ = test_data_dir.AppendASCII("extensions"); | 92 data_dir_ = test_data_dir.AppendASCII("extensions"); |
| 94 } | 93 } |
| 95 | 94 |
| 96 ExtensionServiceTestBase::~ExtensionServiceTestBase() { | 95 ExtensionServiceTestBase::~ExtensionServiceTestBase() { |
| 97 // Parts of destruction have to happen on an IO thread, so if the thread | |
| 98 // bundle is reset, we need to change it back. | |
| 99 if (did_reset_thread_bundle_) | |
| 100 ResetThreadBundle(kThreadOptions); | |
| 101 | |
| 102 // Why? Because |profile_| has to be destroyed before |at_exit_manager_|, but | 96 // Why? Because |profile_| has to be destroyed before |at_exit_manager_|, but |
| 103 // is declared above it in the class definition since it's protected. | 97 // is declared above it in the class definition since it's protected. |
| 104 profile_.reset(); | 98 profile_.reset(); |
| 105 } | 99 } |
| 106 | 100 |
| 107 ExtensionServiceTestBase::ExtensionServiceInitParams | 101 ExtensionServiceTestBase::ExtensionServiceInitParams |
| 108 ExtensionServiceTestBase::CreateDefaultInitParams() { | 102 ExtensionServiceTestBase::CreateDefaultInitParams() { |
| 109 ExtensionServiceInitParams params; | 103 ExtensionServiceInitParams params; |
| 110 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 104 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 111 base::FilePath path = temp_dir_.GetPath(); | 105 base::FilePath path = temp_dir_.GetPath(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 service_->updater()->Start(); | 181 service_->updater()->Start(); |
| 188 } | 182 } |
| 189 | 183 |
| 190 void ExtensionServiceTestBase:: | 184 void ExtensionServiceTestBase:: |
| 191 InitializeExtensionServiceWithExtensionsDisabled() { | 185 InitializeExtensionServiceWithExtensionsDisabled() { |
| 192 ExtensionServiceInitParams params = CreateDefaultInitParams(); | 186 ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 193 params.extensions_enabled = false; | 187 params.extensions_enabled = false; |
| 194 InitializeExtensionService(params); | 188 InitializeExtensionService(params); |
| 195 } | 189 } |
| 196 | 190 |
| 197 void ExtensionServiceTestBase::ResetThreadBundle(int options) { | |
| 198 did_reset_thread_bundle_ = true; | |
| 199 thread_bundle_.reset(); | |
| 200 thread_bundle_.reset(new content::TestBrowserThreadBundle(options)); | |
| 201 } | |
| 202 | |
| 203 size_t ExtensionServiceTestBase::GetPrefKeyCount() { | 191 size_t ExtensionServiceTestBase::GetPrefKeyCount() { |
| 204 const base::DictionaryValue* dict = | 192 const base::DictionaryValue* dict = |
| 205 profile()->GetPrefs()->GetDictionary("extensions.settings"); | 193 profile()->GetPrefs()->GetDictionary("extensions.settings"); |
| 206 if (!dict) { | 194 if (!dict) { |
| 207 ADD_FAILURE(); | 195 ADD_FAILURE(); |
| 208 return 0; | 196 return 0; |
| 209 } | 197 } |
| 210 return dict->size(); | 198 return dict->size(); |
| 211 } | 199 } |
| 212 | 200 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 323 |
| 336 service_->RegisterInstallGate(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, | 324 service_->RegisterInstallGate(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 337 service_->shared_module_service()); | 325 service_->shared_module_service()); |
| 338 | 326 |
| 339 #if defined(OS_CHROMEOS) | 327 #if defined(OS_CHROMEOS) |
| 340 InstallLimiter::Get(profile_.get())->DisableForTest(); | 328 InstallLimiter::Get(profile_.get())->DisableForTest(); |
| 341 #endif | 329 #endif |
| 342 } | 330 } |
| 343 | 331 |
| 344 } // namespace extensions | 332 } // namespace extensions |
| OLD | NEW |