| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ~LinuxHostInit() {} | 56 ~LinuxHostInit() {} |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 extern int BrowserMain(const MainFunctionParams&); | 62 extern int BrowserMain(const MainFunctionParams&); |
| 63 | 63 |
| 64 const wchar_t kUnitTestShowWindows[] = L"show-windows"; | 64 const wchar_t kUnitTestShowWindows[] = L"show-windows"; |
| 65 | 65 |
| 66 // Passed as value of kTestType. |
| 67 static const char kBrowserTestType[] = "browser"; |
| 68 |
| 66 // Default delay for the time-out at which we stop the | 69 // Default delay for the time-out at which we stop the |
| 67 // inner-message loop the first time. | 70 // inner-message loop the first time. |
| 68 const int kInitialTimeoutInMS = 30000; | 71 const int kInitialTimeoutInMS = 30000; |
| 69 | 72 |
| 70 // Delay for sub-sequent time-outs once the initial time-out happened. | 73 // Delay for sub-sequent time-outs once the initial time-out happened. |
| 71 const int kSubsequentTimeoutInMS = 5000; | 74 const int kSubsequentTimeoutInMS = 5000; |
| 72 | 75 |
| 73 InProcessBrowserTest::InProcessBrowserTest() | 76 InProcessBrowserTest::InProcessBrowserTest() |
| 74 : browser_(NULL), | 77 : browser_(NULL), |
| 75 show_window_(false), | 78 show_window_(false), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 command_line->AppendSwitchWithValue(switches::kUserDataDir, | 128 command_line->AppendSwitchWithValue(switches::kUserDataDir, |
| 126 user_data_dir.ToWStringHack()); | 129 user_data_dir.ToWStringHack()); |
| 127 | 130 |
| 128 // For some reason the sandbox wasn't happy running in test mode. These | 131 // For some reason the sandbox wasn't happy running in test mode. These |
| 129 // tests aren't intended to test the sandbox, so we turn it off. | 132 // tests aren't intended to test the sandbox, so we turn it off. |
| 130 command_line->AppendSwitch(switches::kNoSandbox); | 133 command_line->AppendSwitch(switches::kNoSandbox); |
| 131 | 134 |
| 132 // Don't show the first run ui. | 135 // Don't show the first run ui. |
| 133 command_line->AppendSwitch(switches::kNoFirstRun); | 136 command_line->AppendSwitch(switches::kNoFirstRun); |
| 134 | 137 |
| 138 // This is a Browser test. |
| 139 command_line->AppendSwitchWithValue(switches::kTestType, |
| 140 ASCIIToWide(kBrowserTestType)); |
| 141 |
| 135 // Single-process mode is not set in BrowserMain so it needs to be processed | 142 // Single-process mode is not set in BrowserMain so it needs to be processed |
| 136 // explicitlty. | 143 // explicitlty. |
| 137 original_single_process_ = RenderProcessHost::run_renderer_in_process(); | 144 original_single_process_ = RenderProcessHost::run_renderer_in_process(); |
| 138 if (command_line->HasSwitch(switches::kSingleProcess)) | 145 if (command_line->HasSwitch(switches::kSingleProcess)) |
| 139 RenderProcessHost::set_run_renderer_in_process(true); | 146 RenderProcessHost::set_run_renderer_in_process(true); |
| 140 | 147 |
| 141 // Explicitly set the path of the exe used for the renderer and plugin, | 148 // Explicitly set the path of the exe used for the renderer and plugin, |
| 142 // otherwise they'll try to use unit_test.exe. | 149 // otherwise they'll try to use unit_test.exe. |
| 143 FilePath subprocess_path; | 150 FilePath subprocess_path; |
| 144 PathService::Get(base::FILE_EXE, &subprocess_path); | 151 PathService::Get(base::FILE_EXE, &subprocess_path); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 244 |
| 238 browser->window()->Show(); | 245 browser->window()->Show(); |
| 239 | 246 |
| 240 return browser; | 247 return browser; |
| 241 } | 248 } |
| 242 | 249 |
| 243 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 250 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
| 244 // In the long term it would be great if we could use a TestingProfile | 251 // In the long term it would be great if we could use a TestingProfile |
| 245 // here and only enable services you want tested, but that requires all | 252 // here and only enable services you want tested, but that requires all |
| 246 // consumers of Profile to handle NULL services. | 253 // consumers of Profile to handle NULL services. |
| 247 FilePath user_data_dir; | 254 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 248 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
| 249 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 250 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); | |
| 251 if (!profile) { | 255 if (!profile) { |
| 252 // We should only be able to get here if the profile already exists and | 256 // We should only be able to get here if the profile already exists and |
| 253 // has been created. | 257 // has been created. |
| 254 NOTREACHED(); | 258 NOTREACHED(); |
| 255 MessageLoopForUI::current()->Quit(); | 259 MessageLoopForUI::current()->Quit(); |
| 256 return; | 260 return; |
| 257 } | 261 } |
| 258 | 262 |
| 259 ChromeThread::PostTask( | 263 ChromeThread::PostTask( |
| 260 ChromeThread::IO, FROM_HERE, | 264 ChromeThread::IO, FROM_HERE, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 308 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
| 305 kSubsequentTimeoutInMS); | 309 kSubsequentTimeoutInMS); |
| 306 | 310 |
| 307 MessageLoopForUI::current()->Quit(); | 311 MessageLoopForUI::current()->Quit(); |
| 308 } | 312 } |
| 309 | 313 |
| 310 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { | 314 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { |
| 311 DCHECK_GT(timeout_value, 0); | 315 DCHECK_GT(timeout_value, 0); |
| 312 initial_timeout_ = timeout_value; | 316 initial_timeout_ = timeout_value; |
| 313 } | 317 } |
| OLD | NEW |