Chromium Code Reviews

Side by Side Diff: chrome/test/automation/proxy_launcher.cc

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

Powered by Google App Engine