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

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

Issue 2832153003: Move calling of shared browser test methods like SetUpOnMainThread/TearDownOnMainThread/RunTestOn... (Closed)
Patch Set: sync 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/test/base/in_process_browser_test.h" 5 #include "chrome/test/base/in_process_browser_test.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 new_command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); 512 new_command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir);
513 513
514 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin(); 514 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin();
515 iter != switches.end(); ++iter) { 515 iter != switches.end(); ++iter) {
516 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); 516 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
517 } 517 }
518 return new_command_line; 518 return new_command_line;
519 } 519 }
520 #endif 520 #endif
521 521
522 void InProcessBrowserTest::RunTestOnMainThreadLoop() { 522 void InProcessBrowserTest::PreRunTestOnMainThread() {
523 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); 523 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
524 524
525 // Pump startup related events. 525 // Pump startup related events.
526 content::RunAllPendingInMessageLoop(); 526 content::RunAllPendingInMessageLoop();
527 527
528 const BrowserList* active_browser_list = BrowserList::GetInstance(); 528 const BrowserList* active_browser_list = BrowserList::GetInstance();
529 if (!active_browser_list->empty()) { 529 if (!active_browser_list->empty()) {
530 browser_ = active_browser_list->get(0); 530 browser_ = active_browser_list->get(0);
531 #if defined(USE_ASH) 531 #if defined(USE_ASH)
532 // There are cases where windows get created maximized by default. 532 // There are cases where windows get created maximized by default.
(...skipping 26 matching lines...) Expand all
559 content::RunAllPendingInMessageLoop(); 559 content::RunAllPendingInMessageLoop();
560 560
561 // run_accessibility_checks_for_test_case_ must be set before calling 561 // run_accessibility_checks_for_test_case_ must be set before calling
562 // SetUpOnMainThread or RunTestOnMainThread so that one or all tests can 562 // SetUpOnMainThread or RunTestOnMainThread so that one or all tests can
563 // enable/disable the accessibility audit. 563 // enable/disable the accessibility audit.
564 run_accessibility_checks_for_test_case_ = false; 564 run_accessibility_checks_for_test_case_ = false;
565 565
566 if (browser_ && global_browser_set_up_function_) 566 if (browser_ && global_browser_set_up_function_)
567 ASSERT_TRUE(global_browser_set_up_function_(browser_)); 567 ASSERT_TRUE(global_browser_set_up_function_(browser_));
568 568
569 SetUpOnMainThread();
570 #if defined(OS_MACOSX) 569 #if defined(OS_MACOSX)
571 autorelease_pool_->Recycle(); 570 autorelease_pool_->Recycle();
572 #endif 571 #endif
573 572
574 if (!HasFatalFailure()) 573 // TODO(jam): remove this.
575 RunTestOnMainThread(); 574 disable_io_checks();
575 }
576
577 void InProcessBrowserTest::PostRunTestOnMainThread() {
576 #if defined(OS_MACOSX) 578 #if defined(OS_MACOSX)
577 autorelease_pool_->Recycle(); 579 autorelease_pool_->Recycle();
578 #endif 580 #endif
579 581
580 if (run_accessibility_checks_for_test_case_) { 582 if (run_accessibility_checks_for_test_case_) {
581 std::string error_message; 583 std::string error_message;
582 EXPECT_TRUE(RunAccessibilityChecks(&error_message)); 584 EXPECT_TRUE(RunAccessibilityChecks(&error_message));
583 EXPECT_EQ("", error_message); 585 EXPECT_EQ("", error_message);
584 } 586 }
585 587
586 // Invoke cleanup and quit even if there are failures. This is similar to
587 // gtest in that it invokes TearDown even if Setup fails.
588 TearDownOnMainThread();
589 #if defined(OS_MACOSX) 588 #if defined(OS_MACOSX)
590 autorelease_pool_->Recycle(); 589 autorelease_pool_->Recycle();
591 #endif 590 #endif
592 591
593 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's 592 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's
594 // run all pending messages here to avoid preempting the QuitBrowsers tasks. 593 // run all pending messages here to avoid preempting the QuitBrowsers tasks.
595 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it 594 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it
596 // will not be possible to post Quit tasks. 595 // will not be possible to post Quit tasks.
597 content::RunAllPendingInMessageLoop(); 596 content::RunAllPendingInMessageLoop();
598 597
(...skipping 23 matching lines...) Expand all
622 // On the Mac, this eventually reaches 621 // On the Mac, this eventually reaches
623 // -[BrowserWindowController windowWillClose:], which will post a deferred 622 // -[BrowserWindowController windowWillClose:], which will post a deferred
624 // -autorelease on itself to ultimately destroy the Browser object. The line 623 // -autorelease on itself to ultimately destroy the Browser object. The line
625 // below is necessary to pump these pending messages to ensure all Browsers 624 // below is necessary to pump these pending messages to ensure all Browsers
626 // get deleted. 625 // get deleted.
627 content::RunAllPendingInMessageLoop(); 626 content::RunAllPendingInMessageLoop();
628 delete autorelease_pool_; 627 delete autorelease_pool_;
629 autorelease_pool_ = NULL; 628 autorelease_pool_ = NULL;
630 #endif 629 #endif
631 } 630 }
OLDNEW
« no previous file with comments | « chrome/test/base/in_process_browser_test.h ('k') | chromecast/browser/renderer_prelauncher_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698