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/automation/proxy_launcher.h" | 5 #include "chrome/test/automation/proxy_launcher.h" |
6 | 6 |
7 #include "base/threading/platform_thread.h" | 7 #include "app/sql/connection.h" |
8 #include "base/file_util.h" | |
9 #include "base/string_number_conversions.h" | |
10 #include "base/string_split.h" | |
11 #include "base/string_util.h" | |
12 #include "base/stringprintf.h" | |
13 #include "base/test/test_file_util.h" | |
14 #include "base/test/test_timeouts.h" | |
15 #include "base/utf_string_conversions.h" | |
16 #include "chrome/app/chrome_command_ids.h" | |
8 #include "chrome/common/automation_constants.h" | 17 #include "chrome/common/automation_constants.h" |
18 #include "chrome/common/child_process_info.h" | |
19 #include "chrome/common/chrome_constants.h" | |
20 #include "chrome/common/chrome_switches.h" | |
21 #include "chrome/common/debug_flags.h" | |
9 #include "chrome/common/logging_chrome.h" | 22 #include "chrome/common/logging_chrome.h" |
23 #include "chrome/common/url_constants.h" | |
24 #include "chrome/test/chrome_process_util.h" | |
25 #include "chrome/test/test_launcher_utils.h" | |
26 #include "chrome/test/test_switches.h" | |
10 #include "chrome/test/automation/automation_proxy.h" | 27 #include "chrome/test/automation/automation_proxy.h" |
11 #include "chrome/test/ui/ui_test.h" | 28 #include "chrome/test/ui/ui_test.h" |
12 | 29 |
30 // Passed as value of kTestType. | |
31 static const char kUITestType[] = "ui"; | |
32 | |
13 // Default path of named testing interface. | 33 // Default path of named testing interface. |
14 static const char kInterfacePath[] = "/var/tmp/ChromeTestingInterface"; | 34 static const char kInterfacePath[] = "/var/tmp/ChromeTestingInterface"; |
15 | 35 |
36 namespace { | |
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Add empty line below.
dtu
2011/01/07 01:46:17
Done.
| |
37 void RewritePreferencesFile(const FilePath& user_data_dir) { | |
38 const FilePath pref_template_path( | |
39 user_data_dir.AppendASCII("Default").AppendASCII("PreferencesTemplate")); | |
40 const FilePath pref_path( | |
41 user_data_dir.AppendASCII("Default").AppendASCII("Preferences")); | |
42 | |
43 // Read in preferences template. | |
44 std::string pref_string; | |
45 EXPECT_TRUE(file_util::ReadFileToString(pref_template_path, &pref_string)); | |
46 string16 format_string = ASCIIToUTF16(pref_string); | |
47 | |
48 // Make sure temp directory has the proper format for writing to prefs file. | |
49 #if defined(OS_POSIX) | |
50 std::wstring user_data_dir_w(ASCIIToWide(user_data_dir.value())); | |
51 #elif defined(OS_WIN) | |
52 std::wstring user_data_dir_w(user_data_dir.value()); | |
53 // In Windows, the FilePath will write '\' for the path separators; change | |
54 // these to a separator that won't trigger escapes. | |
55 std::replace(user_data_dir_w.begin(), | |
56 user_data_dir_w.end(), '\\', '/'); | |
57 #endif | |
58 | |
59 // Rewrite prefs file. | |
60 std::vector<string16> subst; | |
61 subst.push_back(WideToUTF16(user_data_dir_w)); | |
62 const std::string prefs_string = | |
63 UTF16ToASCII(ReplaceStringPlaceholders(format_string, subst, NULL)); | |
64 EXPECT_TRUE(file_util::WriteFile(pref_path, prefs_string.c_str(), | |
65 prefs_string.size())); | |
66 file_util::EvictFileFromSystemCache(pref_path); | |
67 } | |
68 | |
69 void UpdateHistoryDates(const FilePath& user_data_dir) { | |
70 // Migrate the times in the segment_usage table to yesterday so we get | |
71 // actual thumbnails on the NTP. | |
72 sql::Connection db; | |
73 FilePath history = | |
74 user_data_dir.AppendASCII("Default").AppendASCII("History"); | |
75 // Not all test profiles have a history file. | |
76 if (!file_util::PathExists(history)) | |
77 return; | |
78 | |
79 ASSERT_TRUE(db.Open(history)); | |
80 base::Time yesterday = base::Time::Now() - base::TimeDelta::FromDays(1); | |
81 std::string yesterday_str = base::Int64ToString(yesterday.ToInternalValue()); | |
82 std::string query = StringPrintf( | |
83 "UPDATE segment_usage " | |
84 "SET time_slot = %s " | |
85 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);", | |
86 yesterday_str.c_str()); | |
87 ASSERT_TRUE(db.Execute(query.c_str())); | |
88 db.Close(); | |
89 file_util::EvictFileFromSystemCache(history); | |
90 } | |
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Add empty line below.
dtu
2011/01/07 01:46:17
Done.
| |
91 } // namespace | |
92 | |
93 // ProxyLauncher functions | |
94 | |
95 bool ProxyLauncher::in_process_renderer_ = false; | |
96 bool ProxyLauncher::no_sandbox_ = false; | |
97 bool ProxyLauncher::full_memory_dump_ = false; | |
98 bool ProxyLauncher::safe_plugins_ = false; | |
99 bool ProxyLauncher::show_error_dialogs_ = true; | |
100 bool ProxyLauncher::dump_histograms_on_exit_ = false; | |
101 bool ProxyLauncher::enable_dcheck_ = false; | |
102 bool ProxyLauncher::silent_dump_on_dcheck_ = false; | |
103 bool ProxyLauncher::disable_breakpad_ = false; | |
104 std::string ProxyLauncher::js_flags_ = ""; | |
105 std::string ProxyLauncher::log_level_ = ""; | |
106 | |
107 ProxyLauncher::ProxyLauncher() | |
108 : temp_profile_dir_(), | |
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: I think there's no need to put an initializer
dtu
2011/01/07 01:46:17
Done.
| |
109 homepage_(chrome::kAboutBlankURL) { | |
110 } | |
111 | |
112 ProxyLauncher::~ProxyLauncher() { | |
113 } | |
114 | |
115 void ProxyLauncher::WaitForBrowserLaunch(bool wait_for_initial_loads) { | |
116 ASSERT_EQ(AUTOMATION_SUCCESS, automation_proxy_->WaitForAppLaunch()) | |
117 << "Error while awaiting automation ping from browser process"; | |
118 if (wait_for_initial_loads) | |
119 ASSERT_TRUE(automation_proxy_->WaitForInitialLoads()); | |
120 else | |
121 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | |
122 | |
123 EXPECT_TRUE(automation()->SetFilteredInet(ShouldFilterInet())); | |
124 } | |
125 | |
126 void ProxyLauncher::LaunchBrowserAndServer(const CommandLine& arguments, | |
127 bool include_testing_id, | |
128 bool clear_profile, | |
129 FilePath& template_user_data, | |
130 ProfileType profile_type, | |
131 FilePath browser_directory, | |
132 bool show_window, | |
133 bool wait_for_initial_loads, | |
134 base::TimeTicks* launch_time, | |
135 base::ProcessHandle* process, | |
136 base::ProcessId* process_id) { | |
137 // Set up IPC testing interface as a server. | |
138 automation_proxy_.reset(CreateAutomationProxy( | |
139 TestTimeouts::command_execution_timeout_ms())); | |
140 | |
141 LaunchBrowser(arguments, include_testing_id, clear_profile, | |
142 template_user_data, profile_type, browser_directory, | |
143 show_window, launch_time, process, process_id); | |
144 WaitForBrowserLaunch(wait_for_initial_loads); | |
145 } | |
146 | |
147 void ProxyLauncher::ConnectToRunningBrowser(bool wait_for_initial_loads) { | |
148 // Set up IPC testing interface as a client. | |
149 automation_proxy_.reset(CreateAutomationProxy( | |
150 TestTimeouts::command_execution_timeout_ms())); | |
151 WaitForBrowserLaunch(wait_for_initial_loads); | |
152 } | |
153 | |
154 void ProxyLauncher::CloseBrowserAndServer(ShutdownType shutdown_type, | |
155 base::TimeDelta* quit_time, | |
156 base::ProcessHandle* process, | |
157 base::ProcessId* process_id) { | |
158 QuitBrowser(shutdown_type, quit_time, process, process_id); | |
159 CleanupAppProcesses(*process_id); | |
160 | |
161 // Suppress spammy failures that seem to be occurring when running | |
162 // the UI tests in single-process mode. | |
163 // TODO(jhughes): figure out why this is necessary at all, and fix it | |
164 if (!in_process_renderer_) | |
165 AssertAppNotRunning( | |
166 StringPrintf(L"Unable to quit all browser processes. Original PID %d", | |
167 process_id), *process_id); | |
168 | |
169 automation_proxy_.reset(); // Shut down IPC testing interface. | |
170 } | |
171 | |
172 void ProxyLauncher::LaunchBrowser(const CommandLine& arguments, | |
173 bool include_testing_id, | |
174 bool clear_profile, | |
175 FilePath& template_user_data, | |
176 ProfileType profile_type, | |
177 FilePath browser_directory, | |
178 bool show_window, | |
179 base::TimeTicks* launch_time, | |
180 base::ProcessHandle* process, | |
181 base::ProcessId* process_id) { | |
182 if (clear_profile || !temp_profile_dir_.IsValid()) { | |
183 temp_profile_dir_.Delete(); | |
184 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | |
185 | |
186 ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir())); | |
187 } | |
188 | |
189 if (!template_user_data.empty()) { | |
190 // Recursively copy the template directory to the user_data_dir. | |
191 ASSERT_TRUE(file_util::CopyRecursiveDirNoCache( | |
192 template_user_data, | |
193 user_data_dir())); | |
194 // If we're using the complex theme data, we need to write the | |
195 // user_data_dir_ to our preferences file. | |
196 if (profile_type == COMPLEX_THEME) { | |
197 RewritePreferencesFile(user_data_dir()); | |
198 } | |
199 | |
200 // Update the history file to include recent dates. | |
201 UpdateHistoryDates(user_data_dir()); | |
202 } | |
203 | |
204 ASSERT_TRUE(LaunchBrowserHelper(arguments, include_testing_id, | |
205 browser_directory, false, show_window, | |
206 launch_time, process)); | |
207 *process_id = base::GetProcId(*process); | |
208 } | |
209 | |
210 #if !defined(OS_MACOSX) | |
211 bool ProxyLauncher::LaunchAnotherBrowserBlockUntilClosed( | |
212 const CommandLine& cmdline, bool include_testing_id, | |
213 FilePath browser_directory, bool show_window, | |
214 base::TimeTicks* launch_time) { | |
215 return LaunchBrowserHelper(cmdline, include_testing_id, browser_directory, | |
216 true, show_window, launch_time, NULL); | |
217 } | |
218 #endif | |
219 | |
220 void ProxyLauncher::QuitBrowser(ShutdownType shutdown_type, | |
221 base::TimeDelta* quit_time, | |
222 base::ProcessHandle* process, | |
223 base::ProcessId* process_id) { | |
224 if (SESSION_ENDING == shutdown_type) { | |
225 TerminateBrowser(quit_time, process, process_id); | |
226 return; | |
227 } | |
228 | |
229 // There's nothing to do here if the browser is not running. | |
230 // WARNING: There is a race condition here where the browser may shut down | |
231 // after this check but before some later automation call. Your test should | |
232 // use WaitForBrowserProcessToQuit() if it intentionally | |
233 // causes the browser to shut down. | |
234 if (IsBrowserRunning(*process)) { | |
235 base::TimeTicks quit_start = base::TimeTicks::Now(); | |
236 EXPECT_TRUE(automation()->SetFilteredInet(false)); | |
237 | |
238 if (WINDOW_CLOSE == shutdown_type) { | |
239 int window_count = 0; | |
240 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
241 | |
242 // Synchronously close all but the last browser window. Closing them | |
243 // one-by-one may help with stability. | |
244 while (window_count > 1) { | |
245 scoped_refptr<BrowserProxy> browser_proxy = | |
246 automation()->GetBrowserWindow(0); | |
247 EXPECT_TRUE(browser_proxy.get()); | |
248 if (browser_proxy.get()) { | |
249 EXPECT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); | |
250 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
251 } else { | |
252 break; | |
253 } | |
254 } | |
255 | |
256 // Close the last window asynchronously, because the browser may | |
257 // shutdown faster than it will be able to send a synchronous response | |
258 // to our message. | |
259 scoped_refptr<BrowserProxy> browser_proxy = | |
260 automation()->GetBrowserWindow(0); | |
261 EXPECT_TRUE(browser_proxy.get()); | |
262 if (browser_proxy.get()) { | |
263 EXPECT_TRUE(browser_proxy->ApplyAccelerator(IDC_CLOSE_WINDOW)); | |
264 browser_proxy = NULL; | |
265 } | |
266 } else if (USER_QUIT == shutdown_type) { | |
267 scoped_refptr<BrowserProxy> browser_proxy = | |
268 automation()->GetBrowserWindow(0); | |
269 EXPECT_TRUE(browser_proxy.get()); | |
270 if (browser_proxy.get()) { | |
271 EXPECT_TRUE(browser_proxy->RunCommandAsync(IDC_EXIT)); | |
272 } | |
273 } else { | |
274 NOTREACHED() << "Invalid shutdown type " << shutdown_type; | |
275 } | |
276 | |
277 // Now, drop the automation IPC channel so that the automation provider in | |
278 // the browser notices and drops its reference to the browser process. | |
279 automation()->Disconnect(); | |
280 | |
281 // Wait for the browser process to quit. It should quit once all tabs have | |
282 // been closed. | |
283 if (!WaitForBrowserProcessToQuit(*process)) { | |
284 // We need to force the browser to quit because it didn't quit fast | |
285 // enough. Take no chance and kill every chrome processes. | |
286 CleanupAppProcesses(*process_id); | |
287 } | |
288 *quit_time = base::TimeTicks::Now() - quit_start; | |
289 } | |
290 | |
291 // Don't forget to close the handle | |
292 base::CloseProcessHandle(*process); | |
293 *process = base::kNullProcessHandle; | |
294 *process_id = -1; | |
295 } | |
296 | |
297 void ProxyLauncher::TerminateBrowser(base::TimeDelta* quit_time, | |
298 base::ProcessHandle* process, | |
299 base::ProcessId* process_id) { | |
300 if (IsBrowserRunning(*process)) { | |
301 base::TimeTicks quit_start = base::TimeTicks::Now(); | |
302 EXPECT_TRUE(automation()->SetFilteredInet(false)); | |
303 #if defined(OS_WIN) | |
304 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
305 ASSERT_TRUE(browser.get()); | |
306 ASSERT_TRUE(browser->TerminateSession()); | |
307 #endif // defined(OS_WIN) | |
308 | |
309 // Now, drop the automation IPC channel so that the automation provider in | |
310 // the browser notices and drops its reference to the browser process. | |
311 automation()->Disconnect(); | |
312 | |
313 #if defined(OS_POSIX) | |
314 EXPECT_EQ(kill(*process, SIGTERM), 0); | |
315 #endif // OS_POSIX | |
316 | |
317 if (!WaitForBrowserProcessToQuit(*process)) { | |
318 // We need to force the browser to quit because it didn't quit fast | |
319 // enough. Take no chance and kill every chrome processes. | |
320 CleanupAppProcesses(*process_id); | |
321 } | |
322 *quit_time = base::TimeTicks::Now() - quit_start; | |
323 } | |
324 | |
325 // Don't forget to close the handle | |
326 base::CloseProcessHandle(*process); | |
327 *process = base::kNullProcessHandle; | |
328 *process_id = -1; | |
329 } | |
330 | |
331 void ProxyLauncher::AssertAppNotRunning(const std::wstring& error_message, | |
332 base::ProcessId process_id) { | |
333 std::wstring final_error_message(error_message); | |
334 | |
335 ChromeProcessList processes = GetRunningChromeProcesses(process_id); | |
336 if (!processes.empty()) { | |
337 final_error_message += L" Leftover PIDs: ["; | |
338 for (ChromeProcessList::const_iterator it = processes.begin(); | |
339 it != processes.end(); ++it) { | |
340 final_error_message += StringPrintf(L" %d", *it); | |
341 } | |
342 final_error_message += L" ]"; | |
343 } | |
344 ASSERT_TRUE(processes.empty()) << final_error_message; | |
345 } | |
346 | |
347 void ProxyLauncher::CleanupAppProcesses(base::ProcessId process_id) { | |
348 TerminateAllChromeProcesses(process_id); | |
349 } | |
350 | |
351 bool ProxyLauncher::WaitForBrowserProcessToQuit(base::ProcessHandle process) { | |
352 // Wait for the browser process to quit. | |
353 int timeout = TestTimeouts::wait_for_terminate_timeout_ms(); | |
354 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN | |
355 timeout = 500000; | |
356 #endif | |
357 return base::WaitForSingleProcess(process, timeout); | |
358 } | |
359 | |
360 bool ProxyLauncher::IsBrowserRunning(base::ProcessHandle process) { | |
361 return CrashAwareSleep(process, 0); | |
362 } | |
363 | |
364 bool ProxyLauncher::CrashAwareSleep(base::ProcessHandle process, | |
365 int timeout_ms) { | |
366 return base::CrashAwareSleep(process, timeout_ms); | |
367 } | |
368 | |
369 void ProxyLauncher::PrepareTestCommandline(CommandLine* command_line, | |
370 bool include_testing_id) { | |
371 // Propagate commandline settings from test_launcher_utils. | |
372 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | |
373 | |
374 // Add any explicit command line flags passed to the process. | |
375 CommandLine::StringType extra_chrome_flags = | |
376 CommandLine::ForCurrentProcess()->GetSwitchValueNative( | |
377 switches::kExtraChromeFlags); | |
378 if (!extra_chrome_flags.empty()) { | |
379 // Split by spaces and append to command line | |
380 std::vector<CommandLine::StringType> flags; | |
381 base::SplitString(extra_chrome_flags, ' ', &flags); | |
382 for (size_t i = 0; i < flags.size(); ++i) | |
383 command_line->AppendArgNative(flags[i]); | |
384 } | |
385 | |
386 // No default browser check, it would create an info-bar (if we are not the | |
387 // default browser) that could conflicts with some tests expectations. | |
388 command_line->AppendSwitch(switches::kNoDefaultBrowserCheck); | |
389 | |
390 // This is a UI test. | |
391 command_line->AppendSwitchASCII(switches::kTestType, kUITestType); | |
392 | |
393 // Tell the browser to use a temporary directory just for this test. | |
394 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir()); | |
395 | |
396 if (include_testing_id) | |
397 command_line->AppendSwitchASCII(switches::kTestingChannelID, | |
398 PrefixedChannelID()); | |
399 | |
400 if (!show_error_dialogs_ && | |
401 !CommandLine::ForCurrentProcess()->HasSwitch( | |
402 switches::kEnableErrorDialogs)) { | |
403 command_line->AppendSwitch(switches::kNoErrorDialogs); | |
404 } | |
405 if (in_process_renderer_) | |
406 command_line->AppendSwitch(switches::kSingleProcess); | |
407 if (no_sandbox_) | |
408 command_line->AppendSwitch(switches::kNoSandbox); | |
409 if (full_memory_dump_) | |
410 command_line->AppendSwitch(switches::kFullMemoryCrashReport); | |
411 if (safe_plugins_) | |
412 command_line->AppendSwitch(switches::kSafePlugins); | |
413 if (enable_dcheck_) | |
414 command_line->AppendSwitch(switches::kEnableDCHECK); | |
415 if (silent_dump_on_dcheck_) | |
416 command_line->AppendSwitch(switches::kSilentDumpOnDCHECK); | |
417 if (disable_breakpad_) | |
418 command_line->AppendSwitch(switches::kDisableBreakpad); | |
419 if (!homepage_.empty()) | |
420 command_line->AppendSwitchASCII(switches::kHomePage, homepage_); | |
421 | |
422 if (!js_flags_.empty()) | |
423 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, js_flags_); | |
424 if (!log_level_.empty()) | |
425 command_line->AppendSwitchASCII(switches::kLoggingLevel, log_level_); | |
426 | |
427 command_line->AppendSwitch(switches::kMetricsRecordingOnly); | |
428 | |
429 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
430 switches::kEnableErrorDialogs)) | |
431 command_line->AppendSwitch(switches::kEnableLogging); | |
432 | |
433 if (dump_histograms_on_exit_) | |
434 command_line->AppendSwitch(switches::kDumpHistogramsOnExit); | |
435 | |
436 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN | |
437 command_line->AppendSwitch(switches::kDebugOnStart); | |
438 #endif | |
439 | |
440 if (!test_name_.empty()) | |
441 command_line->AppendSwitchASCII(switches::kTestName, test_name_); | |
442 | |
443 // The tests assume that file:// URIs can freely access other file:// URIs. | |
444 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); | |
445 | |
446 // Disable TabCloseableStateWatcher for tests. | |
447 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); | |
448 | |
449 // Allow file:// access on ChromeOS. | |
450 command_line->AppendSwitch(switches::kAllowFileAccess); | |
451 } | |
452 | |
453 bool ProxyLauncher::LaunchBrowserHelper(const CommandLine& arguments, | |
454 bool include_testing_id, | |
455 FilePath browser_directory, | |
456 bool wait, | |
457 bool show_window, | |
458 base::TimeTicks* launch_time, | |
459 base::ProcessHandle* process) { | |
460 FilePath command = browser_directory.Append( | |
461 chrome::kBrowserProcessExecutablePath); | |
462 | |
463 CommandLine command_line(command); | |
464 | |
465 // Add command line arguments that should be applied to all UI tests. | |
466 PrepareTestCommandline(&command_line, include_testing_id); | |
467 DebugFlags::ProcessDebugFlags( | |
468 &command_line, ChildProcessInfo::UNKNOWN_PROCESS, false); | |
469 command_line.AppendArguments(arguments, false); | |
470 | |
471 // TODO(phajdan.jr): Only run it for "main" browser launch. | |
472 *launch_time = base::TimeTicks::Now(); | |
473 | |
474 #if defined(OS_WIN) | |
475 bool started = base::LaunchApp(command_line, | |
476 wait, | |
477 !show_window, | |
478 process); | |
479 #elif defined(OS_POSIX) | |
480 // Sometimes one needs to run the browser under a special environment | |
481 // (e.g. valgrind) without also running the test harness (e.g. python) | |
482 // under the special environment. Provide a way to wrap the browser | |
483 // commandline with a special prefix to invoke the special environment. | |
484 const char* browser_wrapper = getenv("BROWSER_WRAPPER"); | |
485 if (browser_wrapper) { | |
486 command_line.PrependWrapper(browser_wrapper); | |
487 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with " | |
488 << browser_wrapper; | |
489 } | |
490 | |
491 base::file_handle_mapping_vector fds; | |
492 if (automation_proxy_.get()) | |
493 fds = automation_proxy_->fds_to_map(); | |
494 | |
495 bool started = base::LaunchApp(command_line.argv(), fds, wait, process); | |
496 #endif | |
497 | |
498 return started; | |
499 } | |
500 | |
501 AutomationProxy* ProxyLauncher::automation() const { | |
502 EXPECT_TRUE(automation_proxy_.get()); | |
503 return automation_proxy_.get(); | |
504 } | |
505 | |
506 FilePath ProxyLauncher::user_data_dir() const { | |
507 EXPECT_TRUE(temp_profile_dir_.IsValid()); | |
508 return temp_profile_dir_.path(); | |
509 } | |
510 | |
16 // NamedProxyLauncher functions | 511 // NamedProxyLauncher functions |
17 | 512 |
18 NamedProxyLauncher::NamedProxyLauncher(bool launch_browser, | 513 NamedProxyLauncher::NamedProxyLauncher(bool launch_browser, |
19 bool disconnect_on_failure) | 514 bool disconnect_on_failure) |
20 : launch_browser_(launch_browser), | 515 : ProxyLauncher(), |
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: I think there's no need to call ProxyLauncher
dtu
2011/01/07 01:46:17
Done.
| |
516 launch_browser_(launch_browser), | |
21 disconnect_on_failure_(disconnect_on_failure) { | 517 disconnect_on_failure_(disconnect_on_failure) { |
22 channel_id_ = kInterfacePath; | 518 channel_id_ = kInterfacePath; |
23 } | 519 } |
24 | 520 |
25 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( | 521 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( |
26 int execution_timeout) { | 522 int execution_timeout) { |
27 AutomationProxy* proxy = new AutomationProxy(execution_timeout, | 523 AutomationProxy* proxy = new AutomationProxy(execution_timeout, |
28 disconnect_on_failure_); | 524 disconnect_on_failure_); |
29 proxy->InitializeChannel(channel_id_, true); | 525 proxy->InitializeChannel(channel_id_, true); |
30 return proxy; | 526 return proxy; |
31 } | 527 } |
32 | 528 |
33 void NamedProxyLauncher::InitializeConnection(UITestBase* ui_test_base) const { | 529 void NamedProxyLauncher::InitializeConnection(const CommandLine& arguments, |
530 bool include_testing_id, | |
531 bool clear_profile, | |
532 FilePath& template_user_data, | |
533 ProfileType profile_type, | |
534 FilePath browser_directory, | |
535 bool show_window, | |
536 bool wait_for_initial_loads, | |
537 base::TimeTicks* launch_time, | |
538 base::ProcessHandle* process, | |
539 base::ProcessId* process_id) { | |
34 if (launch_browser_) { | 540 if (launch_browser_) { |
35 // Set up IPC testing interface as a client. | 541 // Set up IPC testing interface as a client. |
36 ui_test_base->LaunchBrowser(); | 542 LaunchBrowser(arguments, include_testing_id, clear_profile, |
543 template_user_data, profile_type, browser_directory, | |
544 show_window, launch_time, process, process_id); | |
37 | 545 |
38 // Wait for browser to be ready for connections. | 546 // Wait for browser to be ready for connections. |
39 struct stat file_info; | 547 struct stat file_info; |
40 while (stat(kInterfacePath, &file_info)) | 548 while (stat(kInterfacePath, &file_info)) |
41 base::PlatformThread::Sleep(automation::kSleepTime); | 549 base::PlatformThread::Sleep(automation::kSleepTime); |
42 } | 550 } |
43 | 551 |
44 ui_test_base->ConnectToRunningBrowser(); | 552 ConnectToRunningBrowser(wait_for_initial_loads); |
45 } | 553 } |
46 | 554 |
47 std::string NamedProxyLauncher::PrefixedChannelID() const { | 555 std::string NamedProxyLauncher::PrefixedChannelID() const { |
48 std::string channel_id; | 556 std::string channel_id; |
49 channel_id.append(automation::kNamedInterfacePrefix).append(channel_id_); | 557 channel_id.append(automation::kNamedInterfacePrefix).append(channel_id_); |
50 return channel_id; | 558 return channel_id; |
51 } | 559 } |
52 | 560 |
53 // AnonymousProxyLauncher functions | 561 // AnonymousProxyLauncher functions |
54 | 562 |
55 AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure) | 563 AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure) |
56 : disconnect_on_failure_(disconnect_on_failure) { | 564 : ProxyLauncher(), |
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: I think there's no need to call ProxyLauncher
dtu
2011/01/07 01:46:17
Done.
| |
565 disconnect_on_failure_(disconnect_on_failure) { | |
57 channel_id_ = AutomationProxy::GenerateChannelID(); | 566 channel_id_ = AutomationProxy::GenerateChannelID(); |
58 } | 567 } |
59 | 568 |
60 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( | 569 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( |
61 int execution_timeout) { | 570 int execution_timeout) { |
62 AutomationProxy* proxy = new AutomationProxy(execution_timeout, | 571 AutomationProxy* proxy = new AutomationProxy(execution_timeout, |
63 disconnect_on_failure_); | 572 disconnect_on_failure_); |
64 proxy->InitializeChannel(channel_id_, false); | 573 proxy->InitializeChannel(channel_id_, false); |
65 return proxy; | 574 return proxy; |
66 } | 575 } |
67 | 576 |
68 void AnonymousProxyLauncher::InitializeConnection( | 577 void AnonymousProxyLauncher::InitializeConnection(const CommandLine& arguments, |
69 UITestBase* ui_test_base) const { | 578 bool include_testing_id, |
70 ui_test_base->LaunchBrowserAndServer(); | 579 bool clear_profile, |
580 FilePath& template_user_data, | |
581 ProfileType profile_type, | |
582 FilePath browser_directory, | |
583 bool show_window, | |
584 bool wait_for_initial_loads, | |
585 base::TimeTicks* launch_time, | |
586 base::ProcessHandle* process, | |
587 base::ProcessId* process_id) { | |
588 LaunchBrowserAndServer(arguments, include_testing_id, clear_profile, | |
589 template_user_data, profile_type, browser_directory, | |
590 show_window, wait_for_initial_loads, | |
591 launch_time, process, process_id); | |
71 } | 592 } |
72 | 593 |
73 std::string AnonymousProxyLauncher::PrefixedChannelID() const { | 594 std::string AnonymousProxyLauncher::PrefixedChannelID() const { |
74 return channel_id_; | 595 return channel_id_; |
75 } | 596 } |
76 | |
OLD | NEW |