summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 19:53:59 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 19:53:59 +0000
commitb5f95100c3fb57469f24a2dc7feb62b41c8f5098 (patch)
tree36e09bf0d2ab8076059dad1db4cb980b442bdf90 /chrome/test
parent38bbf0e97a45e150a147c051de9d4626b7d3e098 (diff)
downloadchromium_src-b5f95100c3fb57469f24a2dc7feb62b41c8f5098.zip
chromium_src-b5f95100c3fb57469f24a2dc7feb62b41c8f5098.tar.gz
chromium_src-b5f95100c3fb57469f24a2dc7feb62b41c8f5098.tar.bz2
Adds time-out to browser-tests to prevent a hanging test from hanging the entire test suite.
Bug=None TEST=None Review URL: http://codereview.chromium.org/151158 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/in_process_browser_test.cc25
-rw-r--r--chrome/test/in_process_browser_test.h3
2 files changed, 28 insertions, 0 deletions
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index 64007de..e698e27 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -33,6 +33,13 @@ extern int BrowserMain(const MainFunctionParams&);
const wchar_t kUnitTestShowWindows[] = L"show-windows";
+// 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;
+
namespace {
bool DieFileDie(const std::wstring& file, bool recurse) {
@@ -205,6 +212,11 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
browser_ = CreateBrowser(profile);
+ // Start the timeout timer to prevent hangs.
+ MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
+ NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
+ kInitialTimeoutInMS);
+
RunTestOnMainThread();
BrowserList::const_iterator browser = BrowserList::begin();
@@ -224,3 +236,16 @@ void InProcessBrowserTest::ConfigureHostMapper(
// We don't want the test code to use it.
host_mapper->AddSimulatedFailure("wpad");
}
+
+void InProcessBrowserTest::TimedOut() {
+ DCHECK(MessageLoopForUI::current()->IsNested());
+
+ GTEST_NONFATAL_FAILURE_("Timed-out");
+
+ // Start the timeout timer to prevent hangs.
+ MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
+ NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
+ kSubsequentTimeoutInMS);
+
+ MessageLoopForUI::current()->Quit();
+}
diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h
index 7795c8a..27f5bff 100644
--- a/chrome/test/in_process_browser_test.h
+++ b/chrome/test/in_process_browser_test.h
@@ -67,6 +67,9 @@ class InProcessBrowserTest : public testing::Test {
// do that during testing.
virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper);
+ // Invoked when a test is not finishing in a timely manner.
+ void TimedOut();
+
// Starts an HTTP server.
HTTPTestServer* StartHTTPServer();