| 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" |
| 11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
| 15 #include "chrome/browser/browser_window.h" | 15 #include "chrome/browser/browser_window.h" |
| 16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/profile_manager.h" | 17 #include "chrome/browser/profile_manager.h" |
| 18 #include "chrome/browser/renderer_host/render_process_host.h" | 18 #include "chrome/browser/renderer_host/render_process_host.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 #include "chrome/browser/views/frame/browser_view.h" | 21 #include "chrome/browser/views/frame/browser_view.h" |
| 22 #endif | 22 #endif |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 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/mock_host_resolver.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 // Default delay for the time-out at which we stop the | 36 // Default delay for the time-out at which we stop the |
| 37 // inner-message loop the first time. | 37 // inner-message loop the first time. |
| 38 const int kInitialTimeoutInMS = 30000; | 38 const int kInitialTimeoutInMS = 30000; |
| 39 | 39 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // Enable warning level logging so that we can see when bad stuff happens. | 133 // Enable warning level logging so that we can see when bad stuff happens. |
| 134 command_line->AppendSwitch(switches::kEnableLogging); | 134 command_line->AppendSwitch(switches::kEnableLogging); |
| 135 command_line->AppendSwitchWithValue(switches::kLoggingLevel, | 135 command_line->AppendSwitchWithValue(switches::kLoggingLevel, |
| 136 IntToWString(1)); // warning | 136 IntToWString(1)); // warning |
| 137 | 137 |
| 138 SandboxInitWrapper sandbox_wrapper; | 138 SandboxInitWrapper sandbox_wrapper; |
| 139 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | 139 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
| 140 params.ui_task = | 140 params.ui_task = |
| 141 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); | 141 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); |
| 142 | 142 |
| 143 scoped_refptr<net::RuleBasedHostMapper> host_mapper( | 143 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc( |
| 144 new net::RuleBasedHostMapper()); | 144 new net::RuleBasedHostResolverProc(NULL)); |
| 145 ConfigureHostMapper(host_mapper.get()); | 145 ConfigureHostResolverProc(host_resolver_proc); |
| 146 net::ScopedHostMapper scoped_host_mapper(host_mapper.get()); | 146 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( |
| 147 host_resolver_proc); |
| 147 BrowserMain(params); | 148 BrowserMain(params); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void InProcessBrowserTest::TearDown() { | 151 void InProcessBrowserTest::TearDown() { |
| 151 // Reinstall testing browser process. | 152 // Reinstall testing browser process. |
| 152 delete g_browser_process; | 153 delete g_browser_process; |
| 153 g_browser_process = new TestingBrowserProcess(); | 154 g_browser_process = new TestingBrowserProcess(); |
| 154 | 155 |
| 155 browser_shutdown::delete_resources_on_shutdown = true; | 156 browser_shutdown::delete_resources_on_shutdown = true; |
| 156 | 157 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 BrowserList::const_iterator browser = BrowserList::begin(); | 235 BrowserList::const_iterator browser = BrowserList::begin(); |
| 235 for (; browser != BrowserList::end(); ++browser) | 236 for (; browser != BrowserList::end(); ++browser) |
| 236 (*browser)->CloseAllTabs(); | 237 (*browser)->CloseAllTabs(); |
| 237 | 238 |
| 238 // Stop the HTTP server. | 239 // Stop the HTTP server. |
| 239 http_server_ = NULL; | 240 http_server_ = NULL; |
| 240 | 241 |
| 241 MessageLoopForUI::current()->Quit(); | 242 MessageLoopForUI::current()->Quit(); |
| 242 } | 243 } |
| 243 | 244 |
| 244 void InProcessBrowserTest::ConfigureHostMapper( | 245 void InProcessBrowserTest::ConfigureHostResolverProc( |
| 245 net::RuleBasedHostMapper* host_mapper) { | 246 net::RuleBasedHostResolverProc* host_resolver_proc) { |
| 246 host_mapper->AllowDirectLookup("*.google.com"); | 247 host_resolver_proc->AllowDirectLookup("*.google.com"); |
| 247 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | 248 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 248 // We don't want the test code to use it. | 249 // We don't want the test code to use it. |
| 249 host_mapper->AddSimulatedFailure("wpad"); | 250 host_resolver_proc->AddSimulatedFailure("wpad"); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void InProcessBrowserTest::TimedOut() { | 253 void InProcessBrowserTest::TimedOut() { |
| 253 DCHECK(MessageLoopForUI::current()->IsNested()); | 254 DCHECK(MessageLoopForUI::current()->IsNested()); |
| 254 | 255 |
| 255 GTEST_NONFATAL_FAILURE_("Timed-out"); | 256 GTEST_NONFATAL_FAILURE_("Timed-out"); |
| 256 | 257 |
| 257 // Start the timeout timer to prevent hangs. | 258 // Start the timeout timer to prevent hangs. |
| 258 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, | 259 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, |
| 259 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 260 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
| 260 kSubsequentTimeoutInMS); | 261 kSubsequentTimeoutInMS); |
| 261 | 262 |
| 262 MessageLoopForUI::current()->Quit(); | 263 MessageLoopForUI::current()->Quit(); |
| 263 } | 264 } |
| 264 | 265 |
| 265 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { | 266 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { |
| 266 DCHECK_GT(timeout_value, 0); | 267 DCHECK_GT(timeout_value, 0); |
| 267 initial_timeout_ = timeout_value; | 268 initial_timeout_ = timeout_value; |
| 268 } | 269 } |
| OLD | NEW |