| OLD | NEW |
| 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 Loading... |
| 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 | 36 // Default delay for the time-out at which we stop the |
| 37 // time. | 37 // inner-message loop the first time. |
| 38 const int kInitialTimeoutInMS = 30000; | 38 const int kInitialTimeoutInMS = 30000; |
| 39 | 39 |
| 40 // Delay for sub-sequent time-outs once the initial time-out happened. | 40 // Delay for sub-sequent time-outs once the initial time-out happened. |
| 41 const int kSubsequentTimeoutInMS = 5000; | 41 const int kSubsequentTimeoutInMS = 5000; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 bool DieFileDie(const std::wstring& file, bool recurse) { | 45 bool DieFileDie(const std::wstring& file, bool recurse) { |
| 46 if (!file_util::PathExists(file)) | 46 if (!file_util::PathExists(file)) |
| 47 return true; | 47 return true; |
| 48 | 48 |
| 49 // Sometimes Delete fails, so try a few more times. | 49 // Sometimes Delete fails, so try a few more times. |
| 50 for (int i = 0; i < 10; ++i) { | 50 for (int i = 0; i < 10; ++i) { |
| 51 if (file_util::Delete(file, recurse)) | 51 if (file_util::Delete(file, recurse)) |
| 52 return true; | 52 return true; |
| 53 PlatformThread::Sleep(100); | 53 PlatformThread::Sleep(100); |
| 54 } | 54 } |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 InProcessBrowserTest::InProcessBrowserTest() | 60 InProcessBrowserTest::InProcessBrowserTest() |
| 61 : browser_(NULL), | 61 : browser_(NULL), |
| 62 show_window_(false), | 62 show_window_(false), |
| 63 dom_automation_enabled_(false), | 63 dom_automation_enabled_(false), |
| 64 single_process_(false), | 64 single_process_(false), |
| 65 original_single_process_(false) { | 65 original_single_process_(false), |
| 66 initial_timeout_(kInitialTimeoutInMS) { |
| 66 } | 67 } |
| 67 | 68 |
| 68 void InProcessBrowserTest::SetUp() { | 69 void InProcessBrowserTest::SetUp() { |
| 69 // Cleanup the user data dir. | 70 // Cleanup the user data dir. |
| 70 std::wstring user_data_dir; | 71 std::wstring user_data_dir; |
| 71 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 72 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 72 ASSERT_LT(10, static_cast<int>(user_data_dir.size())) << | 73 ASSERT_LT(10, static_cast<int>(user_data_dir.size())) << |
| 73 "The user data directory name passed into this test was too " | 74 "The user data directory name passed into this test was too " |
| 74 "short to delete safely. Please check the user-data-dir " | 75 "short to delete safely. Please check the user-data-dir " |
| 75 "argument and try again."; | 76 "argument and try again."; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 chrome_path = chrome_path.Append( | 217 chrome_path = chrome_path.Append( |
| 217 WideToASCII(chrome::kBrowserProcessExecutablePath)); | 218 WideToASCII(chrome::kBrowserProcessExecutablePath)); |
| 218 #endif | 219 #endif |
| 219 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); | 220 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
| 220 | 221 |
| 221 browser_ = CreateBrowser(profile); | 222 browser_ = CreateBrowser(profile); |
| 222 | 223 |
| 223 // Start the timeout timer to prevent hangs. | 224 // Start the timeout timer to prevent hangs. |
| 224 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, | 225 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, |
| 225 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 226 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
| 226 kInitialTimeoutInMS); | 227 initial_timeout_); |
| 227 | 228 |
| 228 RunTestOnMainThread(); | 229 RunTestOnMainThread(); |
| 229 CleanUpOnMainThread(); | 230 CleanUpOnMainThread(); |
| 230 | 231 |
| 231 BrowserList::const_iterator browser = BrowserList::begin(); | 232 BrowserList::const_iterator browser = BrowserList::begin(); |
| 232 for (; browser != BrowserList::end(); ++browser) | 233 for (; browser != BrowserList::end(); ++browser) |
| 233 (*browser)->CloseAllTabs(); | 234 (*browser)->CloseAllTabs(); |
| 234 | 235 |
| 235 // Stop the HTTP server. | 236 // Stop the HTTP server. |
| 236 http_server_ = NULL; | 237 http_server_ = NULL; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 251 | 252 |
| 252 GTEST_NONFATAL_FAILURE_("Timed-out"); | 253 GTEST_NONFATAL_FAILURE_("Timed-out"); |
| 253 | 254 |
| 254 // Start the timeout timer to prevent hangs. | 255 // Start the timeout timer to prevent hangs. |
| 255 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, | 256 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, |
| 256 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 257 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
| 257 kSubsequentTimeoutInMS); | 258 kSubsequentTimeoutInMS); |
| 258 | 259 |
| 259 MessageLoopForUI::current()->Quit(); | 260 MessageLoopForUI::current()->Quit(); |
| 260 } | 261 } |
| 262 |
| 263 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { |
| 264 DCHECK_GT(timeout_value, 0); |
| 265 initial_timeout_ = timeout_value; |
| 266 } |
| OLD | NEW |