Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/test/ui/ui_test.cc

Issue 18248: CommandLine API rework (Closed)
Patch Set: fixes Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome/test/ui/ui_test_suite.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/ui_test.h"
6
5 #include <set> 7 #include <set>
6 #include <vector> 8 #include <vector>
7 9
8 #include "chrome/test/ui/ui_test.h"
9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/platform_thread.h" 13 #include "base/platform_thread.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/test_file_util.h" 17 #include "base/test_file_util.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "chrome/app/chrome_dll_resource.h" 19 #include "chrome/app/chrome_dll_resource.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 for (int i = 0; i < 10; ++i) { 85 for (int i = 0; i < 10; ++i) {
86 if (file_util::Delete(file, recurse)) 86 if (file_util::Delete(file, recurse))
87 return true; 87 return true;
88 PlatformThread::Sleep(action_max_timeout_ms() / 10); 88 PlatformThread::Sleep(action_max_timeout_ms() / 10);
89 } 89 }
90 return false; 90 return false;
91 } 91 }
92 92
93 UITest::UITest() 93 UITest::UITest()
94 : testing::Test(), 94 : testing::Test(),
95 launch_arguments_(L""),
95 expected_errors_(0), 96 expected_errors_(0),
96 expected_crashes_(0), 97 expected_crashes_(0),
97 homepage_(L"about:blank"), 98 homepage_(L"about:blank"),
98 wait_for_initial_loads_(true), 99 wait_for_initial_loads_(true),
99 dom_automation_enabled_(false), 100 dom_automation_enabled_(false),
100 process_(0), // NULL on Windows, 0 PID on POSIX. 101 process_(0), // NULL on Windows, 0 PID on POSIX.
101 show_window_(false), 102 show_window_(false),
102 clear_profile_(true), 103 clear_profile_(true),
103 include_testing_id_(true), 104 include_testing_id_(true),
104 use_existing_browser_(default_use_existing_browser_), 105 use_existing_browser_(default_use_existing_browser_),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 171 }
171 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg; 172 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg;
172 #else 173 #else
173 // TODO(port): we don't catch crashes, nor have CountFilesCreatedAfter. 174 // TODO(port): we don't catch crashes, nor have CountFilesCreatedAfter.
174 NOTIMPLEMENTED(); 175 NOTIMPLEMENTED();
175 #endif 176 #endif
176 } 177 }
177 178
178 // Pick up the various test time out values from the command line. 179 // Pick up the various test time out values from the command line.
179 void UITest::InitializeTimeouts() { 180 void UITest::InitializeTimeouts() {
180 if (CommandLine().HasSwitch(kUiTestTimeout)) { 181 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
181 std::wstring timeout_str = CommandLine().GetSwitchValue(kUiTestTimeout); 182 if (command_line.HasSwitch(kUiTestTimeout)) {
183 std::wstring timeout_str = command_line.GetSwitchValue(kUiTestTimeout);
182 int timeout = StringToInt(timeout_str); 184 int timeout = StringToInt(timeout_str);
183 command_execution_timeout_ms_ = std::max(kMaxTestExecutionTime, timeout); 185 command_execution_timeout_ms_ = std::max(kMaxTestExecutionTime, timeout);
184 } 186 }
185 187
186 if (CommandLine().HasSwitch(kUiTestActionTimeout)) { 188 if (command_line.HasSwitch(kUiTestActionTimeout)) {
187 std::wstring act_str = CommandLine().GetSwitchValue(kUiTestActionTimeout); 189 std::wstring act_str = command_line.GetSwitchValue(kUiTestActionTimeout);
188 int act_timeout = StringToInt(act_str); 190 int act_timeout = StringToInt(act_str);
189 action_timeout_ms_ = std::max(kWaitForActionMsec, act_timeout); 191 action_timeout_ms_ = std::max(kWaitForActionMsec, act_timeout);
190 } 192 }
191 193
192 if (CommandLine().HasSwitch(kUiTestActionMaxTimeout)) { 194 if (command_line.HasSwitch(kUiTestActionMaxTimeout)) {
193 std::wstring action_max_str = 195 std::wstring action_max_str =
194 CommandLine().GetSwitchValue(kUiTestActionMaxTimeout); 196 command_line.GetSwitchValue(kUiTestActionMaxTimeout);
195 int max_timeout = StringToInt(action_max_str); 197 int max_timeout = StringToInt(action_max_str);
196 action_max_timeout_ms_ = std::max(kWaitForActionMaxMsec, max_timeout); 198 action_max_timeout_ms_ = std::max(kWaitForActionMaxMsec, max_timeout);
197 } 199 }
198 200
199 if (CommandLine().HasSwitch(kUiTestSleepTimeout)) { 201 if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestSleepTimeout)) {
200 std::wstring sleep_timeout_str = 202 std::wstring sleep_timeout_str =
201 CommandLine().GetSwitchValue(kUiTestSleepTimeout); 203 CommandLine::ForCurrentProcess()->GetSwitchValue(kUiTestSleepTimeout);
202 int sleep_timeout = StringToInt(sleep_timeout_str); 204 int sleep_timeout = StringToInt(sleep_timeout_str);
203 sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout); 205 sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout);
204 } 206 }
205 } 207 }
206 208
207 void UITest::LaunchBrowserAndServer() { 209 void UITest::LaunchBrowserAndServer() {
208 #if defined(OS_WIN) 210 #if defined(OS_WIN)
209 // Set up IPC testing interface server. 211 // Set up IPC testing interface server.
210 server_.reset(new AutomationProxy(command_execution_timeout_ms_)); 212 server_.reset(new AutomationProxy(command_execution_timeout_ms_));
211 213
(...skipping 16 matching lines...) Expand all
228 230
229 #if defined(OS_WIN) 231 #if defined(OS_WIN)
230 // Shut down IPC testing interface. 232 // Shut down IPC testing interface.
231 server_.reset(); 233 server_.reset();
232 #else 234 #else
233 // TODO(port): depends on AutomationProxy. 235 // TODO(port): depends on AutomationProxy.
234 NOTIMPLEMENTED(); 236 NOTIMPLEMENTED();
235 #endif 237 #endif
236 } 238 }
237 239
238 void UITest::LaunchBrowser(const std::wstring& arguments, bool clear_profile) { 240 void UITest::LaunchBrowser(const CommandLine& arguments, bool clear_profile) {
239 std::wstring command_line(browser_directory_); 241 std::wstring command = browser_directory_;
240 file_util::AppendToPath(&command_line, 242 file_util::AppendToPath(&command,
241 chrome::kBrowserProcessExecutableName); 243 chrome::kBrowserProcessExecutableName);
244 CommandLine command_line(command);
242 245
243 // Add any explict command line flags passed to the process. 246 // Add any explict command line flags passed to the process.
244 std::wstring extra_chrome_flags = 247 std::wstring extra_chrome_flags =
245 CommandLine().GetSwitchValue(kExtraChromeFlagsSwitch); 248 CommandLine::ForCurrentProcess()->GetSwitchValue(kExtraChromeFlagsSwitch);
246 if (!extra_chrome_flags.empty()) 249 if (!extra_chrome_flags.empty()) {
247 command_line.append(L" " + extra_chrome_flags); 250 #if defined(OS_WIN)
251 command_line.AppendLooseValue(extra_chrome_flags);
252 #else
253 // TODO(port): figure out how to pass through extra flags via a string.
254 NOTIMPLEMENTED();
255 #endif
256 }
248 257
249 // We need cookies on file:// for things like the page cycler. 258 // We need cookies on file:// for things like the page cycler.
250 CommandLine::AppendSwitch(&command_line, switches::kEnableFileCookies); 259 command_line.AppendSwitch(switches::kEnableFileCookies);
251 260
252 if (dom_automation_enabled_) 261 if (dom_automation_enabled_)
253 CommandLine::AppendSwitch(&command_line, 262 command_line.AppendSwitch(switches::kDomAutomationController);
254 switches::kDomAutomationController);
255 263
256 #if defined(OS_WIN) 264 #if defined(OS_WIN)
257 if (include_testing_id_) { 265 if (include_testing_id_) {
258 if (use_existing_browser_) { 266 if (use_existing_browser_) {
259 // TODO(erikkay): The new switch depends on a browser instance already 267 // TODO(erikkay): The new switch depends on a browser instance already
260 // running, it won't open a new browser window if it's not. We could fix 268 // running, it won't open a new browser window if it's not. We could fix
261 // this by passing an url (e.g. about:blank) on the command line, but 269 // this by passing an url (e.g. about:blank) on the command line, but
262 // I decided to keep using the old switch in the existing use case to 270 // I decided to keep using the old switch in the existing use case to
263 // minimize changes in behavior. 271 // minimize changes in behavior.
264 CommandLine::AppendSwitchWithValue(&command_line, 272 command_line.AppendSwitchWithValue(switches::kAutomationClientChannelID,
265 switches::kAutomationClientChannelID,
266 server_->channel_id()); 273 server_->channel_id());
267 } else { 274 } else {
268 CommandLine::AppendSwitchWithValue(&command_line, 275 command_line.AppendSwitchWithValue(switches::kTestingChannelID,
269 switches::kTestingChannelID,
270 server_->channel_id()); 276 server_->channel_id());
271 } 277 }
272 } 278 }
273 #else 279 #else
274 // TODO(port): depends on AutomationProxy. 280 // TODO(port): depends on AutomationProxy.
275 NOTIMPLEMENTED(); 281 NOTIMPLEMENTED();
276 #endif 282 #endif
277 283
278 if (!show_error_dialogs_) 284 if (!show_error_dialogs_)
279 CommandLine::AppendSwitch(&command_line, switches::kNoErrorDialogs); 285 command_line.AppendSwitch(switches::kNoErrorDialogs);
280 if (in_process_renderer_) 286 if (in_process_renderer_)
281 CommandLine::AppendSwitch(&command_line, switches::kSingleProcess); 287 command_line.AppendSwitch(switches::kSingleProcess);
282 if (in_process_plugins_) 288 if (in_process_plugins_)
283 CommandLine::AppendSwitch(&command_line, switches::kInProcessPlugins); 289 command_line.AppendSwitch(switches::kInProcessPlugins);
284 if (no_sandbox_) 290 if (no_sandbox_)
285 CommandLine::AppendSwitch(&command_line, switches::kNoSandbox); 291 command_line.AppendSwitch(switches::kNoSandbox);
286 if (full_memory_dump_) 292 if (full_memory_dump_)
287 CommandLine::AppendSwitch(&command_line, switches::kFullMemoryCrashReport); 293 command_line.AppendSwitch(switches::kFullMemoryCrashReport);
288 if (safe_plugins_) 294 if (safe_plugins_)
289 CommandLine::AppendSwitch(&command_line, switches::kSafePlugins); 295 command_line.AppendSwitch(switches::kSafePlugins);
290 if (enable_dcheck_) 296 if (enable_dcheck_)
291 CommandLine::AppendSwitch(&command_line, switches::kEnableDCHECK); 297 command_line.AppendSwitch(switches::kEnableDCHECK);
292 if (silent_dump_on_dcheck_) 298 if (silent_dump_on_dcheck_)
293 CommandLine::AppendSwitch(&command_line, switches::kSilentDumpOnDCHECK); 299 command_line.AppendSwitch(switches::kSilentDumpOnDCHECK);
294 if (disable_breakpad_) 300 if (disable_breakpad_)
295 CommandLine::AppendSwitch(&command_line, switches::kDisableBreakpad); 301 command_line.AppendSwitch(switches::kDisableBreakpad);
296 if (!homepage_.empty()) 302 if (!homepage_.empty())
297 CommandLine::AppendSwitchWithValue(&command_line, 303 command_line.AppendSwitchWithValue(switches::kHomePage,
298 switches::kHomePage,
299 homepage_); 304 homepage_);
300 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); 305 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
301 if (!user_data_dir_.empty()) 306 if (!user_data_dir_.empty())
302 CommandLine::AppendSwitchWithValue(&command_line, 307 command_line.AppendSwitchWithValue(switches::kUserDataDir,
303 switches::kUserDataDir,
304 user_data_dir_); 308 user_data_dir_);
305 if (!js_flags_.empty()) 309 if (!js_flags_.empty())
306 CommandLine::AppendSwitchWithValue(&command_line, 310 command_line.AppendSwitchWithValue(switches::kJavaScriptFlags,
307 switches::kJavaScriptFlags,
308 js_flags_); 311 js_flags_);
309 312
310 CommandLine::AppendSwitch(&command_line, switches::kMetricsRecordingOnly); 313 command_line.AppendSwitch(switches::kMetricsRecordingOnly);
311 314
312 // We always want to enable chrome logging 315 // We always want to enable chrome logging
313 CommandLine::AppendSwitch(&command_line, switches::kEnableLogging); 316 command_line.AppendSwitch(switches::kEnableLogging);
314 317
315 if (dump_histograms_on_exit_) 318 if (dump_histograms_on_exit_)
316 CommandLine::AppendSwitch(&command_line, switches::kDumpHistogramsOnExit); 319 command_line.AppendSwitch(switches::kDumpHistogramsOnExit);
317 320
318 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN 321 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN
319 CommandLine::AppendSwitch(&command_line, switches::kDebugOnStart); 322 command_line.AppendSwitch(switches::kDebugOnStart);
320 #endif 323 #endif
321 324
322 if (!ui_test_name_.empty()) 325 if (!ui_test_name_.empty())
323 CommandLine::AppendSwitchWithValue(&command_line, 326 command_line.AppendSwitchWithValue(switches::kTestName,
324 switches::kTestName,
325 ui_test_name_); 327 ui_test_name_);
326 328
327 DebugFlags::ProcessDebugFlags(&command_line, DebugFlags::UNKNOWN, false); 329 DebugFlags::ProcessDebugFlags(&command_line, DebugFlags::UNKNOWN, false);
328 command_line.append(L" " + arguments); 330 command_line.AppendArguments(arguments, false);
329 331
330 // Clear user data directory to make sure test environment is consistent 332 // Clear user data directory to make sure test environment is consistent
331 // We balk on really short (absolute) user_data_dir directory names, because 333 // We balk on really short (absolute) user_data_dir directory names, because
332 // we're worried that they'd accidentally be root or something. 334 // we're worried that they'd accidentally be root or something.
333 ASSERT_LT(10, static_cast<int>(user_data_dir_.size())) << 335 ASSERT_LT(10, static_cast<int>(user_data_dir_.size())) <<
334 "The user data directory name passed into this test was too " 336 "The user data directory name passed into this test was too "
335 "short to delete safely. Please check the user-data-dir " 337 "short to delete safely. Please check the user-data-dir "
336 "argument and try again."; 338 "argument and try again.";
337 if (clear_profile) 339 if (clear_profile)
338 ASSERT_TRUE(DieFileDie(user_data_dir_, true)); 340 ASSERT_TRUE(DieFileDie(user_data_dir_, true));
(...skipping 10 matching lines...) Expand all
349 bool started = base::LaunchApp(command_line, 351 bool started = base::LaunchApp(command_line,
350 false, // Don't wait for process object 352 false, // Don't wait for process object
351 // (doesn't work for us) 353 // (doesn't work for us)
352 !show_window_, 354 !show_window_,
353 &process_); 355 &process_);
354 ASSERT_EQ(started, true); 356 ASSERT_EQ(started, true);
355 357
356 if (use_existing_browser_) { 358 if (use_existing_browser_) {
357 DWORD pid = 0; 359 DWORD pid = 0;
358 HWND hwnd = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, 360 HWND hwnd = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass,
359 user_data_dir_.c_str()); 361 user_data_dir_.c_str());
360 GetWindowThreadProcessId(hwnd, &pid); 362 GetWindowThreadProcessId(hwnd, &pid);
361 // This mode doesn't work if we wound up launching a new browser ourselves. 363 // This mode doesn't work if we wound up launching a new browser ourselves.
362 ASSERT_NE(pid, base::GetProcId(process_)); 364 ASSERT_NE(pid, base::GetProcId(process_));
363 CloseHandle(process_); 365 CloseHandle(process_);
364 process_ = OpenProcess(SYNCHRONIZE, false, pid); 366 process_ = OpenProcess(SYNCHRONIZE, false, pid);
365 } 367 }
366 #else 368 #else
367 // TODO(port): above code is very Windows-specific; we need to 369 // TODO(port): above code is very Windows-specific; we need to
368 // figure out and abstract out how we'll handle finding any existing 370 // figure out and abstract out how we'll handle finding any existing
369 // running process, etc. on other platforms. 371 // running process, etc. on other platforms.
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // <*>RESULT <graph_name>: <trace_name>= <value> <units> 802 // <*>RESULT <graph_name>: <trace_name>= <value> <units>
801 // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units> 803 // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units>
802 // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units> 804 // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units>
803 wprintf(L"%lsRESULT %ls%ls: %ls= %ls%ls%ls %ls\n", 805 wprintf(L"%lsRESULT %ls%ls: %ls= %ls%ls%ls %ls\n",
804 important ? L"*" : L"", measurement.c_str(), modifier.c_str(), 806 important ? L"*" : L"", measurement.c_str(), modifier.c_str(),
805 trace.c_str(), prefix.c_str(), values.c_str(), suffix.c_str(), 807 trace.c_str(), prefix.c_str(), values.c_str(), suffix.c_str(),
806 units.c_str()); 808 units.c_str());
807 } 809 }
808 810
809 #endif // OS_WIN 811 #endif // OS_WIN
OLDNEW
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome/test/ui/ui_test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698