| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/views/frame/browser_view.h" | 23 #include "chrome/browser/views/frame/browser_view.h" |
| 24 #endif | 24 #endif |
| 25 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/main_function_params.h" | 28 #include "chrome/common/main_function_params.h" |
| 29 #include "chrome/common/notification_registrar.h" | 29 #include "chrome/common/notification_registrar.h" |
| 30 #include "chrome/common/notification_type.h" | 30 #include "chrome/common/notification_type.h" |
| 31 #include "chrome/test/testing_browser_process.h" | 31 #include "chrome/test/testing_browser_process.h" |
| 32 #include "chrome/test/ui_test_utils.h" | 32 #include "chrome/test/ui_test_utils.h" |
| 33 #include "net/base/mock_host_resolver.h" | |
| 34 #include "sandbox/src/dep.h" | 33 #include "sandbox/src/dep.h" |
| 35 | 34 |
| 36 extern int BrowserMain(const MainFunctionParams&); | 35 extern int BrowserMain(const MainFunctionParams&); |
| 37 | 36 |
| 38 const wchar_t kUnitTestShowWindows[] = L"show-windows"; | 37 const wchar_t kUnitTestShowWindows[] = L"show-windows"; |
| 39 | 38 |
| 40 // Default delay for the time-out at which we stop the | 39 // Default delay for the time-out at which we stop the |
| 41 // inner-message loop the first time. | 40 // inner-message loop the first time. |
| 42 const int kInitialTimeoutInMS = 30000; | 41 const int kInitialTimeoutInMS = 30000; |
| 43 | 42 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Enable warning level logging so that we can see when bad stuff happens. | 122 // Enable warning level logging so that we can see when bad stuff happens. |
| 124 command_line->AppendSwitch(switches::kEnableLogging); | 123 command_line->AppendSwitch(switches::kEnableLogging); |
| 125 command_line->AppendSwitchWithValue(switches::kLoggingLevel, | 124 command_line->AppendSwitchWithValue(switches::kLoggingLevel, |
| 126 IntToWString(1)); // warning | 125 IntToWString(1)); // warning |
| 127 | 126 |
| 128 SandboxInitWrapper sandbox_wrapper; | 127 SandboxInitWrapper sandbox_wrapper; |
| 129 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | 128 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
| 130 params.ui_task = | 129 params.ui_task = |
| 131 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); | 130 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); |
| 132 | 131 |
| 133 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc( | 132 host_resolver_ = new net::RuleBasedHostResolverProc(NULL); |
| 134 new net::RuleBasedHostResolverProc(NULL)); | 133 |
| 135 ConfigureHostResolverProc(host_resolver_proc); | 134 // Something inside the browser does this lookup implicitly. Make it fail |
| 135 // to avoid external dependency. It won't break the tests. |
| 136 host_resolver_->AddSimulatedFailure("*.google.com"); |
| 137 |
| 138 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 139 // We don't want the test code to use it. |
| 140 host_resolver_->AddSimulatedFailure("wpad"); |
| 141 |
| 136 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( | 142 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( |
| 137 host_resolver_proc); | 143 host_resolver_.get()); |
| 138 BrowserMain(params); | 144 BrowserMain(params); |
| 139 } | 145 } |
| 140 | 146 |
| 141 void InProcessBrowserTest::TearDown() { | 147 void InProcessBrowserTest::TearDown() { |
| 142 // Reinstall testing browser process. | 148 // Reinstall testing browser process. |
| 143 delete g_browser_process; | 149 delete g_browser_process; |
| 144 g_browser_process = new TestingBrowserProcess(); | 150 g_browser_process = new TestingBrowserProcess(); |
| 145 | 151 |
| 146 browser_shutdown::delete_resources_on_shutdown = true; | 152 browser_shutdown::delete_resources_on_shutdown = true; |
| 147 | 153 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // may need to wait for beforeunload and unload handlers to fire in a tab. | 235 // may need to wait for beforeunload and unload handlers to fire in a tab. |
| 230 // When all windows are closed, the last window will call Quit(). | 236 // When all windows are closed, the last window will call Quit(). |
| 231 BrowserList::const_iterator browser = BrowserList::begin(); | 237 BrowserList::const_iterator browser = BrowserList::begin(); |
| 232 for (; browser != BrowserList::end(); ++browser) | 238 for (; browser != BrowserList::end(); ++browser) |
| 233 (*browser)->CloseWindow(); | 239 (*browser)->CloseWindow(); |
| 234 | 240 |
| 235 // Stop the HTTP server. | 241 // Stop the HTTP server. |
| 236 http_server_ = NULL; | 242 http_server_ = NULL; |
| 237 } | 243 } |
| 238 | 244 |
| 239 void InProcessBrowserTest::ConfigureHostResolverProc( | |
| 240 net::RuleBasedHostResolverProc* host_resolver_proc) { | |
| 241 // Something inside the browser does this lookup implicitly. Make it fail | |
| 242 // to avoid external dependency. It won't break the tests. | |
| 243 host_resolver_proc->AddSimulatedFailure("*.google.com"); | |
| 244 | |
| 245 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | |
| 246 // We don't want the test code to use it. | |
| 247 host_resolver_proc->AddSimulatedFailure("wpad"); | |
| 248 } | |
| 249 | |
| 250 void InProcessBrowserTest::TimedOut() { | 245 void InProcessBrowserTest::TimedOut() { |
| 251 DCHECK(MessageLoopForUI::current()->IsNested()); | 246 DCHECK(MessageLoopForUI::current()->IsNested()); |
| 252 | 247 |
| 253 GTEST_NONFATAL_FAILURE_("Timed-out"); | 248 GTEST_NONFATAL_FAILURE_("Timed-out"); |
| 254 | 249 |
| 255 // Start the timeout timer to prevent hangs. | 250 // Start the timeout timer to prevent hangs. |
| 256 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, | 251 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, |
| 257 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 252 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
| 258 kSubsequentTimeoutInMS); | 253 kSubsequentTimeoutInMS); |
| 259 | 254 |
| 260 MessageLoopForUI::current()->Quit(); | 255 MessageLoopForUI::current()->Quit(); |
| 261 } | 256 } |
| 262 | 257 |
| 263 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { | 258 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { |
| 264 DCHECK_GT(timeout_value, 0); | 259 DCHECK_GT(timeout_value, 0); |
| 265 initial_timeout_ = timeout_value; | 260 initial_timeout_ = timeout_value; |
| 266 } | 261 } |
| OLD | NEW |