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