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