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

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

Issue 1411773002: Move Sync-specific tests from ExtensionServiceTest into new file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@su_ext_reenable
Patch Set: . Created 5 years, 2 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/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_number_conversions.h"
11 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/extensions/component_loader.h" 13 #include "chrome/browser/extensions/component_loader.h"
13 #include "chrome/browser/extensions/extension_error_reporter.h" 14 #include "chrome/browser/extensions/extension_error_reporter.h"
14 #include "chrome/browser/extensions/extension_garbage_collector_factory.h" 15 #include "chrome/browser/extensions/extension_garbage_collector_factory.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/test_extension_system.h" 17 #include "chrome/browser/extensions/test_extension_system.h"
17 #include "chrome/browser/extensions/updater/extension_updater.h" 18 #include "chrome/browser/extensions/updater/extension_updater.h"
18 #include "chrome/browser/prefs/browser_prefs.h" 19 #include "chrome/browser/prefs/browser_prefs.h"
19 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 InitializeExtensionService(params); 181 InitializeExtensionService(params);
181 service_->updater()->Start(); 182 service_->updater()->Start();
182 } 183 }
183 184
184 void ExtensionServiceTestBase::ResetThreadBundle(int options) { 185 void ExtensionServiceTestBase::ResetThreadBundle(int options) {
185 did_reset_thread_bundle_ = true; 186 did_reset_thread_bundle_ = true;
186 thread_bundle_.reset(); 187 thread_bundle_.reset();
187 thread_bundle_.reset(new content::TestBrowserThreadBundle(options)); 188 thread_bundle_.reset(new content::TestBrowserThreadBundle(options));
188 } 189 }
189 190
191 size_t ExtensionServiceTestBase::GetPrefKeyCount() {
192 const base::DictionaryValue* dict =
193 profile()->GetPrefs()->GetDictionary("extensions.settings");
194 if (!dict) {
195 ADD_FAILURE();
196 return 0;
197 }
198 return dict->size();
199 }
200
201 void ExtensionServiceTestBase::ValidatePrefKeyCount(size_t count) {
202 EXPECT_EQ(count, GetPrefKeyCount());
203 }
204
205 testing::AssertionResult ExtensionServiceTestBase::ValidateBooleanPref(
206 const std::string& extension_id,
207 const std::string& pref_path,
208 bool expected_val) {
209 std::string msg = "while checking: ";
Devlin 2015/10/20 17:42:15 base::StringPrintf is a beautiful thing. :) (here
Marc Treib 2015/10/21 12:51:53 You really are a fan of that function, aren't you
210 msg += extension_id;
211 msg += " ";
212 msg += pref_path;
213 msg += " == ";
214 msg += expected_val ? "true" : "false";
215
216 PrefService* prefs = profile()->GetPrefs();
217 const base::DictionaryValue* dict =
218 prefs->GetDictionary("extensions.settings");
219 if (!dict) {
220 return testing::AssertionFailure()
221 << "extension.settings does not exist " << msg;
222 }
223
224 const base::DictionaryValue* pref = NULL;
225 if (!dict->GetDictionary(extension_id, &pref)) {
226 return testing::AssertionFailure()
227 << "extension pref does not exist " << msg;
228 }
229
230 bool val;
231 if (!pref->GetBoolean(pref_path, &val)) {
232 return testing::AssertionFailure()
233 << pref_path << " pref not found " << msg;
234 }
235
236 return expected_val == val
237 ? testing::AssertionSuccess()
238 : testing::AssertionFailure() << "base::Value is incorrect " << msg;
239 }
240
241 void ExtensionServiceTestBase::ValidateIntegerPref(
242 const std::string& extension_id,
243 const std::string& pref_path,
244 int expected_val) {
245 std::string msg = " while checking: ";
246 msg += extension_id;
247 msg += " ";
248 msg += pref_path;
249 msg += " == ";
250 msg += base::IntToString(expected_val);
251
252 PrefService* prefs = profile()->GetPrefs();
253 const base::DictionaryValue* dict =
254 prefs->GetDictionary("extensions.settings");
255 ASSERT_TRUE(dict != NULL) << msg;
256 const base::DictionaryValue* pref = NULL;
257 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
258 EXPECT_TRUE(pref != NULL) << msg;
259 int val;
260 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg;
261 EXPECT_EQ(expected_val, val) << msg;
262 }
263
264 void ExtensionServiceTestBase::ValidateStringPref(
265 const std::string& extension_id,
266 const std::string& pref_path,
267 const std::string& expected_val) {
268 std::string msg = " while checking: ";
269 msg += extension_id;
270 msg += ".manifest.";
271 msg += pref_path;
272 msg += " == ";
273 msg += expected_val;
274
275 const base::DictionaryValue* dict =
276 profile()->GetPrefs()->GetDictionary("extensions.settings");
277 ASSERT_TRUE(dict != NULL) << msg;
278 const base::DictionaryValue* pref = NULL;
279 std::string manifest_path = extension_id + ".manifest";
280 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg;
281 EXPECT_TRUE(pref != NULL) << msg;
282 std::string val;
283 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg;
284 EXPECT_EQ(expected_val, val) << msg;
285 }
286
190 void ExtensionServiceTestBase::SetUp() { 287 void ExtensionServiceTestBase::SetUp() {
191 ExtensionErrorReporter::GetInstance()->ClearErrors(); 288 ExtensionErrorReporter::GetInstance()->ClearErrors();
192 } 289 }
193 290
194 void ExtensionServiceTestBase::SetUpTestCase() { 291 void ExtensionServiceTestBase::SetUpTestCase() {
195 // Safe to call multiple times. 292 // Safe to call multiple times.
196 ExtensionErrorReporter::Init(false); // no noisy errors. 293 ExtensionErrorReporter::Init(false); // no noisy errors.
197 } 294 }
198 295
199 // These are declared in the .cc so that all inheritors don't need to know 296 // These are declared in the .cc so that all inheritors don't need to know
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // interfere with the tests. Those tests that need an external provider 328 // interfere with the tests. Those tests that need an external provider
232 // will register one specifically. 329 // will register one specifically.
233 service_->ClearProvidersForTesting(); 330 service_->ClearProvidersForTesting();
234 331
235 #if defined(OS_CHROMEOS) 332 #if defined(OS_CHROMEOS)
236 InstallLimiter::Get(profile_.get())->DisableForTest(); 333 InstallLimiter::Get(profile_.get())->DisableForTest();
237 #endif 334 #endif
238 } 335 }
239 336
240 } // namespace extensions 337 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698