Revert 59409 - GTTF: Move browser_tests test launcher timeout to chrome/test/test_timeouts

BUG=none
TEST=browser_tests

Review URL: http://codereview.chromium.org/3327023

[email protected]
Review URL: http://codereview.chromium.org/3440002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59426 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index 276556d..870cf95 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -69,6 +69,13 @@
 // Passed as value of kTestType.
 static const char kBrowserTestType[] = "browser";
 
+// Default delay for the time-out at which we stop the
+// inner-message loop the first time.
+const int kInitialTimeoutInMS = 30000;
+
+// Delay for sub-sequent time-outs once the initial time-out happened.
+const int kSubsequentTimeoutInMS = 5000;
+
 InProcessBrowserTest::InProcessBrowserTest()
     : browser_(NULL),
       test_server_(net::TestServer::TYPE_HTTP,
@@ -76,7 +83,8 @@
       show_window_(false),
       dom_automation_enabled_(false),
       tab_closeable_state_watcher_enabled_(false),
-      original_single_process_(false) {
+      original_single_process_(false),
+      initial_timeout_(kInitialTimeoutInMS) {
 }
 
 InProcessBrowserTest::~InProcessBrowserTest() {
@@ -294,6 +302,11 @@
   browser_ = CreateBrowser(profile);
   pool.Recycle();
 
+  // Start the timeout timer to prevent hangs.
+  MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
+      NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
+      initial_timeout_);
+
   // Pump any pending events that were created as a result of creating a
   // browser.
   MessageLoopForUI::current()->RunAllPending();
@@ -320,3 +333,19 @@
       NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit));
   ui_test_utils::RunMessageLoop();
 }
+
+void InProcessBrowserTest::TimedOut() {
+  std::string error_message = "Test timed out. Each test runs for a max of ";
+  error_message += base::IntToString(initial_timeout_);
+  error_message += " ms (kInitialTimeoutInMS).";
+
+  MessageLoopForUI::current()->Quit();
+
+  // WARNING: This must be after Quit as it returns.
+  FAIL() << error_message;
+}
+
+void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) {
+  DCHECK_GT(timeout_value, 0);
+  initial_timeout_ = timeout_value;
+}