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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 | 87 |
88 void InProcessBrowserTest::SetUp() { | 88 void InProcessBrowserTest::SetUp() { |
89 // Cleanup the user data dir. | 89 // Cleanup the user data dir. |
90 FilePath user_data_dir; | 90 FilePath user_data_dir; |
91 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 91 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
92 ASSERT_LT(10, static_cast<int>(user_data_dir.value().size())) << | 92 ASSERT_LT(10, static_cast<int>(user_data_dir.value().size())) << |
93 "The user data directory name passed into this test was too " | 93 "The user data directory name passed into this test was too " |
94 "short to delete safely. Please check the user-data-dir " | 94 "short to delete safely. Please check the user-data-dir " |
95 "argument and try again."; | 95 "argument and try again."; |
96 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true)); | 96 if (ShouldDeleteProfile()) |
| 97 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true)); |
97 | 98 |
98 // The unit test suite creates a testingbrowser, but we want the real thing. | 99 // The unit test suite creates a testingbrowser, but we want the real thing. |
99 // Delete the current one. We'll install the testing one in TearDown. | 100 // Delete the current one. We'll install the testing one in TearDown. |
100 delete g_browser_process; | 101 delete g_browser_process; |
101 g_browser_process = NULL; | |
102 | |
103 SetUpUserDataDirectory(); | |
104 | 102 |
105 // Don't delete the resources when BrowserMain returns. Many ui classes | 103 // Don't delete the resources when BrowserMain returns. Many ui classes |
106 // cache SkBitmaps in a static field so that if we delete the resource | 104 // cache SkBitmaps in a static field so that if we delete the resource |
107 // bundle we'll crash. | 105 // bundle we'll crash. |
108 browser_shutdown::delete_resources_on_shutdown = false; | 106 browser_shutdown::delete_resources_on_shutdown = false; |
109 | 107 |
110 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 108 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
111 original_command_line_.reset(new CommandLine(*command_line)); | 109 original_command_line_.reset(new CommandLine(*command_line)); |
112 | 110 |
113 SetUpCommandLine(command_line); | 111 SetUpCommandLine(command_line); |
(...skipping 21 matching lines...) Expand all Loading... |
135 command_line->AppendSwitch(switches::kNoSandbox); | 133 command_line->AppendSwitch(switches::kNoSandbox); |
136 | 134 |
137 // Don't show the first run ui. | 135 // Don't show the first run ui. |
138 command_line->AppendSwitch(switches::kNoFirstRun); | 136 command_line->AppendSwitch(switches::kNoFirstRun); |
139 | 137 |
140 // This is a Browser test. | 138 // This is a Browser test. |
141 command_line->AppendSwitchWithValue(switches::kTestType, | 139 command_line->AppendSwitchWithValue(switches::kTestType, |
142 ASCIIToWide(kBrowserTestType)); | 140 ASCIIToWide(kBrowserTestType)); |
143 | 141 |
144 // 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 |
145 // explicitly. | 143 // explicitlty. |
146 original_single_process_ = RenderProcessHost::run_renderer_in_process(); | 144 original_single_process_ = RenderProcessHost::run_renderer_in_process(); |
147 if (command_line->HasSwitch(switches::kSingleProcess)) | 145 if (command_line->HasSwitch(switches::kSingleProcess)) |
148 RenderProcessHost::set_run_renderer_in_process(true); | 146 RenderProcessHost::set_run_renderer_in_process(true); |
149 | 147 |
150 // 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, |
151 // otherwise they'll try to use unit_test.exe. | 149 // otherwise they'll try to use unit_test.exe. |
152 FilePath subprocess_path; | 150 FilePath subprocess_path; |
153 PathService::Get(base::FILE_EXE, &subprocess_path); | 151 PathService::Get(base::FILE_EXE, &subprocess_path); |
154 subprocess_path = subprocess_path.DirName(); | 152 subprocess_path = subprocess_path.DirName(); |
155 subprocess_path = subprocess_path.AppendASCII(WideToASCII( | 153 subprocess_path = subprocess_path.AppendASCII(WideToASCII( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ChromeThread::IO, FROM_HERE, | 272 ChromeThread::IO, FROM_HERE, |
275 NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 273 NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
276 | 274 |
277 browser_ = CreateBrowser(profile); | 275 browser_ = CreateBrowser(profile); |
278 | 276 |
279 // Start the timeout timer to prevent hangs. | 277 // Start the timeout timer to prevent hangs. |
280 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, | 278 MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, |
281 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), | 279 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), |
282 initial_timeout_); | 280 initial_timeout_); |
283 | 281 |
284 // If an ASSERT_ failed during SetUp, skip the InProcessBrowserTest test body. | 282 RunTestOnMainThread(); |
285 if (!HasFatalFailure()) | |
286 RunTestOnMainThread(); | |
287 CleanUpOnMainThread(); | 283 CleanUpOnMainThread(); |
288 | 284 |
289 // Close all browser windows. This might not happen immediately, since some | 285 // Close all browser windows. This might not happen immediately, since some |
290 // may need to wait for beforeunload and unload handlers to fire in a tab. | 286 // may need to wait for beforeunload and unload handlers to fire in a tab. |
291 // When all windows are closed, the last window will call Quit(). Call | 287 // When all windows are closed, the last window will call Quit(). Call |
292 // Quit() explicitly if no windows are open. | 288 // Quit() explicitly if no windows are open. |
293 #if defined(OS_MACOSX) | 289 #if defined(OS_MACOSX) |
294 // When the browser window closes, Cocoa will generate an inner-loop that | 290 // When the browser window closes, Cocoa will generate an inner-loop that |
295 // processes the RenderProcessHost delete task, so allow task nesting. | 291 // processes the RenderProcessHost delete task, so allow task nesting. |
296 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); | 292 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 368 |
373 GTEST_NONFATAL_FAILURE_(error_message.c_str()); | 369 GTEST_NONFATAL_FAILURE_(error_message.c_str()); |
374 | 370 |
375 MessageLoopForUI::current()->Quit(); | 371 MessageLoopForUI::current()->Quit(); |
376 } | 372 } |
377 | 373 |
378 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { | 374 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { |
379 DCHECK_GT(timeout_value, 0); | 375 DCHECK_GT(timeout_value, 0); |
380 initial_timeout_ = timeout_value; | 376 initial_timeout_ = timeout_value; |
381 } | 377 } |
OLD | NEW |