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

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 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
« no previous file with comments | « chrome/test/base/javascript_browser_test.cc ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/base/testing_profile.h" 5 #include "chrome/test/base/testing_profile.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/threading/thread_restrictions.h"
19 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h" 22 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 24 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
24 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 25 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
25 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 28 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
28 #include "chrome/browser/favicon/chrome_fallback_icon_client_factory.h" 29 #include "chrome/browser/favicon/chrome_fallback_icon_client_factory.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 FROM_HERE, 385 FROM_HERE,
385 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 386 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
386 } else { 387 } else {
387 FinishInit(); 388 FinishInit();
388 } 389 }
389 390
390 SetSupervisedUserId(supervised_user_id); 391 SetSupervisedUserId(supervised_user_id);
391 } 392 }
392 393
393 void TestingProfile::CreateTempProfileDir() { 394 void TestingProfile::CreateTempProfileDir() {
395 base::ThreadRestrictions::ScopedAllowIO allow_io;
394 if (!temp_dir_.CreateUniqueTempDir()) { 396 if (!temp_dir_.CreateUniqueTempDir()) {
395 LOG(ERROR) << "Failed to create unique temporary directory."; 397 LOG(ERROR) << "Failed to create unique temporary directory.";
396 398
397 // Fallback logic in case we fail to create unique temporary directory. 399 // Fallback logic in case we fail to create unique temporary directory.
398 base::FilePath system_tmp_dir; 400 base::FilePath system_tmp_dir;
399 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); 401 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
400 402
401 // We're severly screwed if we can't get the system temporary 403 // We're severly screwed if we can't get the system temporary
402 // directory. Die now to avoid writing to the filesystem root 404 // directory. Die now to avoid writing to the filesystem root
403 // or other bad places. 405 // or other bad places.
404 CHECK(success); 406 CHECK(success);
405 407
406 base::FilePath fallback_dir( 408 base::FilePath fallback_dir(
407 system_tmp_dir.AppendASCII("TestingProfilePath")); 409 system_tmp_dir.AppendASCII("TestingProfilePath"));
408 base::DeleteFile(fallback_dir, true); 410 base::DeleteFile(fallback_dir, true);
409 base::CreateDirectory(fallback_dir); 411 base::CreateDirectory(fallback_dir);
410 if (!temp_dir_.Set(fallback_dir)) { 412 if (!temp_dir_.Set(fallback_dir)) {
411 // That shouldn't happen, but if it does, try to recover. 413 // That shouldn't happen, but if it does, try to recover.
412 LOG(ERROR) << "Failed to use a fallback temporary directory."; 414 LOG(ERROR) << "Failed to use a fallback temporary directory.";
413 415
414 // We're screwed if this fails, see CHECK above. 416 // We're screwed if this fails, see CHECK above.
415 CHECK(temp_dir_.Set(system_tmp_dir)); 417 CHECK(temp_dir_.Set(system_tmp_dir));
416 } 418 }
417 } 419 }
418 } 420 }
419 421
420 void TestingProfile::Init() { 422 void TestingProfile::Init() {
423 base::ThreadRestrictions::ScopedAllowIO allow_io;
421 // If threads have been initialized, we should be on the UI thread. 424 // If threads have been initialized, we should be on the UI thread.
422 DCHECK(!content::BrowserThread::IsThreadInitialized( 425 DCHECK(!content::BrowserThread::IsThreadInitialized(
423 content::BrowserThread::UI) || 426 content::BrowserThread::UI) ||
424 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 427 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
425 428
426 set_is_guest_profile(guest_session_); 429 set_is_guest_profile(guest_session_);
427 430
428 BrowserContext::Initialize(this, profile_path_); 431 BrowserContext::Initialize(this, profile_path_);
429 432
430 browser_context_dependency_manager_->MarkBrowserContextLive(this); 433 browser_context_dependency_manager_->MarkBrowserContextLive(this);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 ShutdownStoragePartitions(); 557 ShutdownStoragePartitions();
555 558
556 // Failing a post == leaks == heapcheck failure. Make that an immediate test 559 // Failing a post == leaks == heapcheck failure. Make that an immediate test
557 // failure. 560 // failure.
558 if (resource_context_) { 561 if (resource_context_) {
559 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 562 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
560 resource_context_)); 563 resource_context_));
561 resource_context_ = NULL; 564 resource_context_ = NULL;
562 content::RunAllPendingInMessageLoop(BrowserThread::IO); 565 content::RunAllPendingInMessageLoop(BrowserThread::IO);
563 } 566 }
567
568 base::ThreadRestrictions::ScopedAllowIO allow_io;
569 ignore_result(temp_dir_.Delete());
564 } 570 }
565 571
566 void TestingProfile::CreateFaviconService() { 572 void TestingProfile::CreateFaviconService() {
567 // It is up to the caller to create the history service if one is needed. 573 // It is up to the caller to create the history service if one is needed.
568 FaviconServiceFactory::GetInstance()->SetTestingFactory( 574 FaviconServiceFactory::GetInstance()->SetTestingFactory(
569 this, FaviconServiceFactory::GetDefaultFactory()); 575 this, FaviconServiceFactory::GetDefaultFactory());
570 } 576 }
571 577
572 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { 578 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
573 DestroyHistoryService(); 579 DestroyHistoryService();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 // Note: Owned by |original_profile|. 1099 // Note: Owned by |original_profile|.
1094 return new TestingProfile(path_, delegate_, 1100 return new TestingProfile(path_, delegate_,
1095 #if BUILDFLAG(ENABLE_EXTENSIONS) 1101 #if BUILDFLAG(ENABLE_EXTENSIONS)
1096 extension_policy_, 1102 extension_policy_,
1097 #endif 1103 #endif
1098 std::move(pref_service_), original_profile, 1104 std::move(pref_service_), original_profile,
1099 guest_session_, supervised_user_id_, 1105 guest_session_, supervised_user_id_,
1100 std::move(policy_service_), testing_factories_, 1106 std::move(policy_service_), testing_factories_,
1101 profile_name_); 1107 profile_name_);
1102 } 1108 }
OLDNEW
« no previous file with comments | « chrome/test/base/javascript_browser_test.cc ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698