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

Side by Side Diff: chrome/browser/profiles/profile_browsertest.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
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/browser/profiles/profile.h" 5 #include "chrome/browser/profiles/profile.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
20 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
21 #include "base/task_scheduler/task_scheduler.h" 21 #include "base/task_scheduler/task_scheduler.h"
22 #include "base/threading/thread_restrictions.h"
22 #include "base/values.h" 23 #include "base/values.h"
23 #include "base/version.h" 24 #include "base/version.h"
24 #include "build/build_config.h" 25 #include "build/build_config.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/net/url_request_mock_util.h" 28 #include "chrome/browser/net/url_request_mock_util.h"
28 #include "chrome/browser/profiles/chrome_version_service.h" 29 #include "chrome/browser/profiles/chrome_version_service.h"
29 #include "chrome/browser/profiles/profile_impl.h" 30 #include "chrome/browser/profiles/profile_impl.h"
30 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 336
336 scoped_refptr<base::SequencedTaskRunner> profile_io_task_runner_; 337 scoped_refptr<base::SequencedTaskRunner> profile_io_task_runner_;
337 338
338 // URLFetcherDelegate that outlives the Profile, to test shutdown. 339 // URLFetcherDelegate that outlives the Profile, to test shutdown.
339 std::unique_ptr<TestURLFetcherDelegate> url_fetcher_delegate_; 340 std::unique_ptr<TestURLFetcherDelegate> url_fetcher_delegate_;
340 }; 341 };
341 342
342 // Test OnProfileCreate is called with is_new_profile set to true when 343 // Test OnProfileCreate is called with is_new_profile set to true when
343 // creating a new profile synchronously. 344 // creating a new profile synchronously.
344 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) { 345 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) {
346 base::ThreadRestrictions::ScopedAllowIO allow_io;
345 base::ScopedTempDir temp_dir; 347 base::ScopedTempDir temp_dir;
346 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 348 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
347 349
348 MockProfileDelegate delegate; 350 MockProfileDelegate delegate;
349 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 351 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
350 352
351 { 353 {
352 std::unique_ptr<Profile> profile(CreateProfile( 354 std::unique_ptr<Profile> profile(CreateProfile(
353 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); 355 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
354 CheckChromeVersion(profile.get(), true); 356 CheckChromeVersion(profile.get(), true);
355 357
356 #if defined(OS_CHROMEOS) 358 #if defined(OS_CHROMEOS)
357 // Make sure session is marked as initialized. 359 // Make sure session is marked as initialized.
358 user_manager::User* user = 360 user_manager::User* user =
359 chromeos::ProfileHelper::Get()->GetUserByProfile(profile.get()); 361 chromeos::ProfileHelper::Get()->GetUserByProfile(profile.get());
360 EXPECT_TRUE(user->profile_ever_initialized()); 362 EXPECT_TRUE(user->profile_ever_initialized());
361 #endif 363 #endif
362 } 364 }
363 365
364 FlushIoTaskRunnerAndSpinThreads(); 366 FlushIoTaskRunnerAndSpinThreads();
365 } 367 }
366 368
367 // Test OnProfileCreate is called with is_new_profile set to false when 369 // Test OnProfileCreate is called with is_new_profile set to false when
368 // creating a profile synchronously with an existing prefs file. 370 // creating a profile synchronously with an existing prefs file.
369 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileSynchronous) { 371 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileSynchronous) {
372 base::ThreadRestrictions::ScopedAllowIO allow_io;
370 base::ScopedTempDir temp_dir; 373 base::ScopedTempDir temp_dir;
371 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 374 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
372 CreatePrefsFileInDirectory(temp_dir.GetPath()); 375 CreatePrefsFileInDirectory(temp_dir.GetPath());
373 376
374 MockProfileDelegate delegate; 377 MockProfileDelegate delegate;
375 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); 378 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false));
376 379
377 { 380 {
378 std::unique_ptr<Profile> profile(CreateProfile( 381 std::unique_ptr<Profile> profile(CreateProfile(
379 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); 382 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
380 CheckChromeVersion(profile.get(), false); 383 CheckChromeVersion(profile.get(), false);
381 } 384 }
382 385
383 FlushIoTaskRunnerAndSpinThreads(); 386 FlushIoTaskRunnerAndSpinThreads();
384 } 387 }
385 388
386 // Flaky: http://crbug.com/393177 389 // Flaky: http://crbug.com/393177
387 // Test OnProfileCreate is called with is_new_profile set to true when 390 // Test OnProfileCreate is called with is_new_profile set to true when
388 // creating a new profile asynchronously. 391 // creating a new profile asynchronously.
389 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, 392 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
390 DISABLED_CreateNewProfileAsynchronous) { 393 DISABLED_CreateNewProfileAsynchronous) {
394 base::ThreadRestrictions::ScopedAllowIO allow_io;
391 base::ScopedTempDir temp_dir; 395 base::ScopedTempDir temp_dir;
392 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 396 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
393 397
394 MockProfileDelegate delegate; 398 MockProfileDelegate delegate;
395 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 399 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
396 400
397 { 401 {
398 content::WindowedNotificationObserver observer( 402 content::WindowedNotificationObserver observer(
399 chrome::NOTIFICATION_PROFILE_CREATED, 403 chrome::NOTIFICATION_PROFILE_CREATED,
400 content::NotificationService::AllSources()); 404 content::NotificationService::AllSources());
(...skipping 14 matching lines...) Expand all
415 419
416 FlushIoTaskRunnerAndSpinThreads(); 420 FlushIoTaskRunnerAndSpinThreads();
417 } 421 }
418 422
419 423
420 // Flaky: http://crbug.com/393177 424 // Flaky: http://crbug.com/393177
421 // Test OnProfileCreate is called with is_new_profile set to false when 425 // Test OnProfileCreate is called with is_new_profile set to false when
422 // creating a profile asynchronously with an existing prefs file. 426 // creating a profile asynchronously with an existing prefs file.
423 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, 427 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
424 DISABLED_CreateOldProfileAsynchronous) { 428 DISABLED_CreateOldProfileAsynchronous) {
429 base::ThreadRestrictions::ScopedAllowIO allow_io;
425 base::ScopedTempDir temp_dir; 430 base::ScopedTempDir temp_dir;
426 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 431 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
427 CreatePrefsFileInDirectory(temp_dir.GetPath()); 432 CreatePrefsFileInDirectory(temp_dir.GetPath());
428 433
429 MockProfileDelegate delegate; 434 MockProfileDelegate delegate;
430 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); 435 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false));
431 436
432 { 437 {
433 content::WindowedNotificationObserver observer( 438 content::WindowedNotificationObserver observer(
434 chrome::NOTIFICATION_PROFILE_CREATED, 439 chrome::NOTIFICATION_PROFILE_CREATED,
435 content::NotificationService::AllSources()); 440 content::NotificationService::AllSources());
436 441
437 std::unique_ptr<Profile> profile(CreateProfile( 442 std::unique_ptr<Profile> profile(CreateProfile(
438 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); 443 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS));
439 444
440 // Wait for the profile to be created. 445 // Wait for the profile to be created.
441 observer.Wait(); 446 observer.Wait();
442 CheckChromeVersion(profile.get(), false); 447 CheckChromeVersion(profile.get(), false);
443 } 448 }
444 449
445 FlushIoTaskRunnerAndSpinThreads(); 450 FlushIoTaskRunnerAndSpinThreads();
446 } 451 }
447 452
448 // Flaky: http://crbug.com/393177 453 // Flaky: http://crbug.com/393177
449 // Test that a README file is created for profiles that didn't have it. 454 // Test that a README file is created for profiles that didn't have it.
450 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) { 455 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) {
456 base::ThreadRestrictions::ScopedAllowIO allow_io;
451 base::ScopedTempDir temp_dir; 457 base::ScopedTempDir temp_dir;
452 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 458 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
453 459
454 MockProfileDelegate delegate; 460 MockProfileDelegate delegate;
455 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 461 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
456 462
457 { 463 {
458 content::WindowedNotificationObserver observer( 464 content::WindowedNotificationObserver observer(
459 chrome::NOTIFICATION_PROFILE_CREATED, 465 chrome::NOTIFICATION_PROFILE_CREATED,
460 content::NotificationService::AllSources()); 466 content::NotificationService::AllSources());
461 467
462 std::unique_ptr<Profile> profile(CreateProfile( 468 std::unique_ptr<Profile> profile(CreateProfile(
463 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); 469 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS));
464 470
465 // Wait for the profile to be created. 471 // Wait for the profile to be created.
466 observer.Wait(); 472 observer.Wait();
467 473
468 // Verify that README exists. 474 // Verify that README exists.
469 EXPECT_TRUE( 475 EXPECT_TRUE(
470 base::PathExists(temp_dir.GetPath().Append(chrome::kReadmeFilename))); 476 base::PathExists(temp_dir.GetPath().Append(chrome::kReadmeFilename)));
471 } 477 }
472 478
473 FlushIoTaskRunnerAndSpinThreads(); 479 FlushIoTaskRunnerAndSpinThreads();
474 } 480 }
475 481
476 // Test that repeated setting of exit type is handled correctly. 482 // Test that repeated setting of exit type is handled correctly.
477 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) { 483 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) {
484 base::ThreadRestrictions::ScopedAllowIO allow_io;
478 base::ScopedTempDir temp_dir; 485 base::ScopedTempDir temp_dir;
479 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 486 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
480 487
481 MockProfileDelegate delegate; 488 MockProfileDelegate delegate;
482 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 489 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
483 { 490 {
484 std::unique_ptr<Profile> profile(CreateProfile( 491 std::unique_ptr<Profile> profile(CreateProfile(
485 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); 492 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
486 493
487 PrefService* prefs = profile->GetPrefs(); 494 PrefService* prefs = profile->GetPrefs();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 EXPECT_EQ(main_context->http_transaction_factory() 566 EXPECT_EQ(main_context->http_transaction_factory()
560 ->GetSession() 567 ->GetSession()
561 ->params() 568 ->params()
562 .channel_id_service, 569 .channel_id_service,
563 main_context->channel_id_service()); 570 main_context->channel_id_service());
564 } 571 }
565 572
566 } // namespace 573 } // namespace
567 574
568 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) { 575 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) {
576 base::ThreadRestrictions::ScopedAllowIO allow_io;
569 base::ScopedTempDir temp_dir; 577 base::ScopedTempDir temp_dir;
570 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 578 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
571 579
572 MockProfileDelegate delegate; 580 MockProfileDelegate delegate;
573 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 581 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
574 582
575 { 583 {
576 std::unique_ptr<Profile> profile(CreateProfile( 584 std::unique_ptr<Profile> profile(CreateProfile(
577 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); 585 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
578 586
(...skipping 15 matching lines...) Expand all
594 main_context_getter), 602 main_context_getter),
595 run_loop.QuitClosure()); 603 run_loop.QuitClosure());
596 run_loop.Run(); 604 run_loop.Run();
597 } 605 }
598 606
599 FlushIoTaskRunnerAndSpinThreads(); 607 FlushIoTaskRunnerAndSpinThreads();
600 } 608 }
601 609
602 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, 610 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
603 OffTheRecordURLRequestContextIsolation) { 611 OffTheRecordURLRequestContextIsolation) {
612 base::ThreadRestrictions::ScopedAllowIO allow_io;
604 base::ScopedTempDir temp_dir; 613 base::ScopedTempDir temp_dir;
605 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 614 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
606 615
607 MockProfileDelegate delegate; 616 MockProfileDelegate delegate;
608 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); 617 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
609 618
610 { 619 {
611 std::unique_ptr<Profile> profile(CreateProfile( 620 std::unique_ptr<Profile> profile(CreateProfile(
612 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); 621 temp_dir.GetPath(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
613 Profile* otr_profile = profile->GetOffTheRecordProfile(); 622 Profile* otr_profile = profile->GetOffTheRecordProfile();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 if (!dict->GetString("profile.exit_type", &exit_type)) 668 if (!dict->GetString("profile.exit_type", &exit_type))
660 return std::string(); 669 return std::string();
661 670
662 return exit_type; 671 return exit_type;
663 } 672 }
664 673
665 } // namespace 674 } // namespace
666 675
667 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, 676 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
668 WritesProfilesSynchronouslyOnEndSession) { 677 WritesProfilesSynchronouslyOnEndSession) {
678 base::ThreadRestrictions::ScopedAllowIO allow_io;
669 base::ScopedTempDir temp_dir; 679 base::ScopedTempDir temp_dir;
670 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 680 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
671 681
672 ProfileManager* profile_manager = g_browser_process->profile_manager(); 682 ProfileManager* profile_manager = g_browser_process->profile_manager();
673 ASSERT_TRUE(profile_manager); 683 ASSERT_TRUE(profile_manager);
674 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); 684 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles();
675 685
676 ASSERT_NE(loaded_profiles.size(), 0UL); 686 ASSERT_NE(loaded_profiles.size(), 0UL);
677 Profile* profile = loaded_profiles[0]; 687 Profile* profile = loaded_profiles[0];
678 688
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); 780 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
771 781
772 RunURLFetcherActiveDuringIncognitoTeardownTest( 782 RunURLFetcherActiveDuringIncognitoTeardownTest(
773 incognito_browser, 783 incognito_browser,
774 incognito_browser->profile()->GetRequestContextForExtensions()); 784 incognito_browser->profile()->GetRequestContextForExtensions());
775 } 785 }
776 786
777 // Verifies the cache directory supports multiple profiles when it's overriden 787 // Verifies the cache directory supports multiple profiles when it's overriden
778 // by group policy or command line switches. 788 // by group policy or command line switches.
779 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DiskCacheDirOverride) { 789 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DiskCacheDirOverride) {
790 base::ThreadRestrictions::ScopedAllowIO allow_io;
780 int size; 791 int size;
781 const base::FilePath::StringPieceType profile_name = 792 const base::FilePath::StringPieceType profile_name =
782 FILE_PATH_LITERAL("Profile 1"); 793 FILE_PATH_LITERAL("Profile 1");
783 base::ScopedTempDir mock_user_data_dir; 794 base::ScopedTempDir mock_user_data_dir;
784 ASSERT_TRUE(mock_user_data_dir.CreateUniqueTempDir()); 795 ASSERT_TRUE(mock_user_data_dir.CreateUniqueTempDir());
785 base::FilePath profile_path = 796 base::FilePath profile_path =
786 mock_user_data_dir.GetPath().Append(profile_name); 797 mock_user_data_dir.GetPath().Append(profile_name);
787 ProfileImpl* profile_impl = static_cast<ProfileImpl*>(browser()->profile()); 798 ProfileImpl* profile_impl = static_cast<ProfileImpl*>(browser()->profile());
788 799
789 { 800 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 base::Bind(&SendReportHttpResponse, embedded_test_server()->base_url())); 877 base::Bind(&SendReportHttpResponse, embedded_test_server()->base_url()));
867 ASSERT_TRUE(hpkp_test_server.Start()); 878 ASSERT_TRUE(hpkp_test_server.Start());
868 879
869 // To send a report, must use a non-numeric host name for the original 880 // To send a report, must use a non-numeric host name for the original
870 // request. This must not match the host name of the server that reports are 881 // request. This must not match the host name of the server that reports are
871 // sent to. 882 // sent to.
872 ui_test_utils::NavigateToURL(browser(), 883 ui_test_utils::NavigateToURL(browser(),
873 hpkp_test_server.GetURL("localhost", "/")); 884 hpkp_test_server.GetURL("localhost", "/"));
874 wait_for_report_loop.Run(); 885 wait_for_report_loop.Run();
875 } 886 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698