Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/extensions/extension_service_test_base.cc

Issue 948413005: [Extensions] Make chrome://extensions use management.uninstall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 15 matching lines...) Expand all
26 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
27 27
28 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/extensions/install_limiter.h" 29 #include "chrome/browser/chromeos/extensions/install_limiter.h"
30 #endif 30 #endif
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 namespace { 34 namespace {
35 35
36 // By default, we run on the IO loop.
37 const int kThreadOptions = content::TestBrowserThreadBundle::IO_MAINLOOP;
not at google - send to devlin 2015/02/25 21:37:57 UI thread makes more sense for a default test thre
Devlin 2015/02/25 23:12:47 But breaks tons of other stuff, as discussed offli
38
36 // Create a testing profile according to |params|. 39 // Create a testing profile according to |params|.
37 scoped_ptr<TestingProfile> BuildTestingProfile( 40 scoped_ptr<TestingProfile> BuildTestingProfile(
38 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { 41 const ExtensionServiceTestBase::ExtensionServiceInitParams& params) {
39 TestingProfile::Builder profile_builder; 42 TestingProfile::Builder profile_builder;
40 // Create a PrefService that only contains user defined preference values. 43 // Create a PrefService that only contains user defined preference values.
41 PrefServiceMockFactory factory; 44 PrefServiceMockFactory factory;
42 // If pref_file is empty, TestingProfile automatically creates 45 // If pref_file is empty, TestingProfile automatically creates
43 // TestingPrefServiceSyncable instance. 46 // TestingPrefServiceSyncable instance.
44 if (!params.pref_file.empty()) { 47 if (!params.pref_file.empty()) {
45 factory.SetUserPrefsFile(params.pref_file, 48 factory.SetUserPrefsFile(params.pref_file,
(...skipping 15 matching lines...) Expand all
61 64
62 } // namespace 65 } // namespace
63 66
64 ExtensionServiceTestBase::ExtensionServiceInitParams:: 67 ExtensionServiceTestBase::ExtensionServiceInitParams::
65 ExtensionServiceInitParams() 68 ExtensionServiceInitParams()
66 : autoupdate_enabled(false), 69 : autoupdate_enabled(false),
67 is_first_run(true), 70 is_first_run(true),
68 profile_is_supervised(false) { 71 profile_is_supervised(false) {
69 } 72 }
70 73
71 // Our message loop may be used in tests which require it to be an IO loop.
72 ExtensionServiceTestBase::ExtensionServiceTestBase() 74 ExtensionServiceTestBase::ExtensionServiceTestBase()
73 : service_(NULL), 75 : service_(NULL),
74 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 76 thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)),
77 did_reset_thread_bundle_(false),
75 registry_(NULL) { 78 registry_(NULL) {
76 base::FilePath test_data_dir; 79 base::FilePath test_data_dir;
77 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 80 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
78 ADD_FAILURE(); 81 ADD_FAILURE();
79 return; 82 return;
80 } 83 }
81 data_dir_ = test_data_dir.AppendASCII("extensions"); 84 data_dir_ = test_data_dir.AppendASCII("extensions");
82 } 85 }
83 86
84 ExtensionServiceTestBase::~ExtensionServiceTestBase() { 87 ExtensionServiceTestBase::~ExtensionServiceTestBase() {
88 // Parts of destruction have to happen on an IO thread, so if the thread
89 // bundle is reset, we need to change it back.
90 if (did_reset_thread_bundle_)
91 ResetThreadBundle(kThreadOptions);
92
85 // Why? Because |profile_| has to be destroyed before |at_exit_manager_|, but 93 // Why? Because |profile_| has to be destroyed before |at_exit_manager_|, but
86 // is declared above it in the class definition since it's protected. 94 // is declared above it in the class definition since it's protected.
87 profile_.reset(); 95 profile_.reset();
88 } 96 }
89 97
90 ExtensionServiceTestBase::ExtensionServiceInitParams 98 ExtensionServiceTestBase::ExtensionServiceInitParams
91 ExtensionServiceTestBase::CreateDefaultInitParams() { 99 ExtensionServiceTestBase::CreateDefaultInitParams() {
92 ExtensionServiceInitParams params; 100 ExtensionServiceInitParams params;
93 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 101 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
94 base::FilePath path = temp_dir_.path(); 102 base::FilePath path = temp_dir_.path();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 InitializeInstalledExtensionService(pref_path, source_install_dir); 171 InitializeInstalledExtensionService(pref_path, source_install_dir);
164 } 172 }
165 173
166 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { 174 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() {
167 ExtensionServiceInitParams params = CreateDefaultInitParams(); 175 ExtensionServiceInitParams params = CreateDefaultInitParams();
168 params.autoupdate_enabled = true; 176 params.autoupdate_enabled = true;
169 InitializeExtensionService(params); 177 InitializeExtensionService(params);
170 service_->updater()->Start(); 178 service_->updater()->Start();
171 } 179 }
172 180
181 void ExtensionServiceTestBase::ResetThreadBundle(int options) {
182 did_reset_thread_bundle_ = true;
183 thread_bundle_.reset();
184 thread_bundle_.reset(new content::TestBrowserThreadBundle(options));
185 }
186
173 void ExtensionServiceTestBase::SetUp() { 187 void ExtensionServiceTestBase::SetUp() {
174 ExtensionErrorReporter::GetInstance()->ClearErrors(); 188 ExtensionErrorReporter::GetInstance()->ClearErrors();
175 } 189 }
176 190
177 void ExtensionServiceTestBase::SetUpTestCase() { 191 void ExtensionServiceTestBase::SetUpTestCase() {
178 // Safe to call multiple times. 192 // Safe to call multiple times.
179 ExtensionErrorReporter::Init(false); // no noisy errors. 193 ExtensionErrorReporter::Init(false); // no noisy errors.
180 } 194 }
181 195
182 // These are declared in the .cc so that all inheritors don't need to know 196 // These are declared in the .cc so that all inheritors don't need to know
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // interfere with the tests. Those tests that need an external provider 230 // interfere with the tests. Those tests that need an external provider
217 // will register one specifically. 231 // will register one specifically.
218 service_->ClearProvidersForTesting(); 232 service_->ClearProvidersForTesting();
219 233
220 #if defined(OS_CHROMEOS) 234 #if defined(OS_CHROMEOS)
221 InstallLimiter::Get(profile_.get())->DisableForTest(); 235 InstallLimiter::Get(profile_.get())->DisableForTest();
222 #endif 236 #endif
223 } 237 }
224 238
225 } // namespace extensions 239 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698