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

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

Issue 151158: Adding time-out to browser tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/in_process_browser_test.h" 5 #include "chrome/test/in_process_browser_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 15 matching lines...) Expand all
26 #include "chrome/common/main_function_params.h" 26 #include "chrome/common/main_function_params.h"
27 #include "chrome/test/testing_browser_process.h" 27 #include "chrome/test/testing_browser_process.h"
28 #include "chrome/test/ui_test_utils.h" 28 #include "chrome/test/ui_test_utils.h"
29 #include "net/base/host_resolver_unittest.h" 29 #include "net/base/host_resolver_unittest.h"
30 #include "sandbox/src/dep.h" 30 #include "sandbox/src/dep.h"
31 31
32 extern int BrowserMain(const MainFunctionParams&); 32 extern int BrowserMain(const MainFunctionParams&);
33 33
34 const wchar_t kUnitTestShowWindows[] = L"show-windows"; 34 const wchar_t kUnitTestShowWindows[] = L"show-windows";
35 35
36 // Delay for the time-out at which we stop the inner-message loop the first
37 // time.
38 const int kInitialTimeoutInMS = 30000;
39
40 // Delay for sub-sequent time-outs once the initial time-out happened.
41 const int kSubsequentTimeoutInMS = 5000;
42
36 namespace { 43 namespace {
37 44
38 bool DieFileDie(const std::wstring& file, bool recurse) { 45 bool DieFileDie(const std::wstring& file, bool recurse) {
39 if (!file_util::PathExists(file)) 46 if (!file_util::PathExists(file))
40 return true; 47 return true;
41 48
42 // Sometimes Delete fails, so try a few more times. 49 // Sometimes Delete fails, so try a few more times.
43 for (int i = 0; i < 10; ++i) { 50 for (int i = 0; i < 10; ++i) {
44 if (file_util::Delete(file, recurse)) 51 if (file_util::Delete(file, recurse))
45 return true; 52 return true;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 #if defined(OS_WIN) 205 #if defined(OS_WIN)
199 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); 206 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath);
200 #elif defined(OS_POSIX) 207 #elif defined(OS_POSIX)
201 chrome_path = chrome_path.Append( 208 chrome_path = chrome_path.Append(
202 WideToASCII(chrome::kBrowserProcessExecutablePath)); 209 WideToASCII(chrome::kBrowserProcessExecutablePath));
203 #endif 210 #endif
204 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); 211 CHECK(PathService::Override(base::FILE_EXE, chrome_path));
205 212
206 browser_ = CreateBrowser(profile); 213 browser_ = CreateBrowser(profile);
207 214
215 // Start the timeout timer to prevent hangs.
216 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
217 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
218 kInitialTimeoutInMS);
219
208 RunTestOnMainThread(); 220 RunTestOnMainThread();
209 221
210 BrowserList::const_iterator browser = BrowserList::begin(); 222 BrowserList::const_iterator browser = BrowserList::begin();
211 for (; browser != BrowserList::end(); ++browser) 223 for (; browser != BrowserList::end(); ++browser)
212 (*browser)->CloseAllTabs(); 224 (*browser)->CloseAllTabs();
213 225
214 // Stop the HTTP server. 226 // Stop the HTTP server.
215 http_server_ = NULL; 227 http_server_ = NULL;
216 228
217 MessageLoopForUI::current()->Quit(); 229 MessageLoopForUI::current()->Quit();
218 } 230 }
219 231
220 void InProcessBrowserTest::ConfigureHostMapper( 232 void InProcessBrowserTest::ConfigureHostMapper(
221 net::RuleBasedHostMapper* host_mapper) { 233 net::RuleBasedHostMapper* host_mapper) {
222 host_mapper->AllowDirectLookup("*.google.com"); 234 host_mapper->AllowDirectLookup("*.google.com");
223 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol 235 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
224 // We don't want the test code to use it. 236 // We don't want the test code to use it.
225 host_mapper->AddSimulatedFailure("wpad"); 237 host_mapper->AddSimulatedFailure("wpad");
226 } 238 }
239
240 void InProcessBrowserTest::TimedOut() {
241 DCHECK(MessageLoopForUI::current()->IsNested());
242
243 GTEST_NONFATAL_FAILURE_("Timed-out");
244
245 // Start the timeout timer to prevent hangs.
246 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE,
247 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
248 kSubsequentTimeoutInMS);
249
250 MessageLoopForUI::current()->Quit();
251 }
OLDNEW
« no previous file with comments | « chrome/test/in_process_browser_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698