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

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

Issue 10736064: Switch to TimeDelta interfaces in chrome automation test infrastructure. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/automation/proxy_launcher.h ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 7 #include <vector>
8 8
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #endif 123 #endif
124 } 124 }
125 125
126 return true; 126 return true;
127 } 127 }
128 128
129 bool ProxyLauncher::LaunchBrowserAndServer(const LaunchState& state, 129 bool ProxyLauncher::LaunchBrowserAndServer(const LaunchState& state,
130 bool wait_for_initial_loads) { 130 bool wait_for_initial_loads) {
131 // Set up IPC testing interface as a server. 131 // Set up IPC testing interface as a server.
132 automation_proxy_.reset(CreateAutomationProxy( 132 automation_proxy_.reset(CreateAutomationProxy(
133 TestTimeouts::action_max_timeout_ms())); 133 TestTimeouts::action_max_timeout()));
134 134
135 if (!LaunchBrowser(state)) 135 if (!LaunchBrowser(state))
136 return false; 136 return false;
137 137
138 if (!WaitForBrowserLaunch(wait_for_initial_loads)) 138 if (!WaitForBrowserLaunch(wait_for_initial_loads))
139 return false; 139 return false;
140 140
141 return true; 141 return true;
142 } 142 }
143 143
144 bool ProxyLauncher::ConnectToRunningBrowser(bool wait_for_initial_loads) { 144 bool ProxyLauncher::ConnectToRunningBrowser(bool wait_for_initial_loads) {
145 // Set up IPC testing interface as a client. 145 // Set up IPC testing interface as a client.
146 automation_proxy_.reset(CreateAutomationProxy( 146 automation_proxy_.reset(CreateAutomationProxy(
147 TestTimeouts::action_max_timeout_ms())); 147 TestTimeouts::action_max_timeout()));
148 148
149 return WaitForBrowserLaunch(wait_for_initial_loads); 149 return WaitForBrowserLaunch(wait_for_initial_loads);
150 } 150 }
151 151
152 void ProxyLauncher::CloseBrowserAndServer() { 152 void ProxyLauncher::CloseBrowserAndServer() {
153 QuitBrowser(); 153 QuitBrowser();
154 154
155 // Suppress spammy failures that seem to be occurring when running 155 // Suppress spammy failures that seem to be occurring when running
156 // the UI tests in single-process mode. 156 // the UI tests in single-process mode.
157 // TODO(jhughes): figure out why this is necessary at all, and fix it 157 // TODO(jhughes): figure out why this is necessary at all, and fix it
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 // Now, drop the automation IPC channel so that the automation provider in 265 // Now, drop the automation IPC channel so that the automation provider in
266 // the browser notices and drops its reference to the browser process. 266 // the browser notices and drops its reference to the browser process.
267 if (automation_proxy_.get()) 267 if (automation_proxy_.get())
268 automation_proxy_->Disconnect(); 268 automation_proxy_->Disconnect();
269 269
270 // Wait for the browser process to quit. It should quit once all tabs have 270 // Wait for the browser process to quit. It should quit once all tabs have
271 // been closed. 271 // been closed.
272 int exit_code = -1; 272 int exit_code = -1;
273 EXPECT_TRUE(WaitForBrowserProcessToQuit( 273 EXPECT_TRUE(WaitForBrowserProcessToQuit(
274 TestTimeouts::action_max_timeout_ms(), &exit_code)); 274 TestTimeouts::action_max_timeout(), &exit_code));
275 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. 275 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
276 276
277 browser_quit_time_ = base::TimeTicks::Now() - quit_start; 277 browser_quit_time_ = base::TimeTicks::Now() - quit_start;
278 } 278 }
279 279
280 void ProxyLauncher::TerminateBrowser() { 280 void ProxyLauncher::TerminateBrowser() {
281 // If we have already finished waiting for the browser to exit 281 // If we have already finished waiting for the browser to exit
282 // (or it hasn't launched at all), there's nothing to do here. 282 // (or it hasn't launched at all), there's nothing to do here.
283 if (process_ == base::kNullProcessHandle || !automation_proxy_.get()) 283 if (process_ == base::kNullProcessHandle || !automation_proxy_.get())
284 return; 284 return;
(...skipping 10 matching lines...) Expand all
295 // the browser notices and drops its reference to the browser process. 295 // the browser notices and drops its reference to the browser process.
296 if (automation_proxy_.get()) 296 if (automation_proxy_.get())
297 automation_proxy_->Disconnect(); 297 automation_proxy_->Disconnect();
298 298
299 #if defined(OS_POSIX) 299 #if defined(OS_POSIX)
300 EXPECT_EQ(kill(process_, SIGTERM), 0); 300 EXPECT_EQ(kill(process_, SIGTERM), 0);
301 #endif // OS_POSIX 301 #endif // OS_POSIX
302 302
303 int exit_code = -1; 303 int exit_code = -1;
304 EXPECT_TRUE(WaitForBrowserProcessToQuit( 304 EXPECT_TRUE(WaitForBrowserProcessToQuit(
305 TestTimeouts::action_max_timeout_ms(), &exit_code)); 305 TestTimeouts::action_max_timeout(), &exit_code));
306 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. 306 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
307 307
308 browser_quit_time_ = base::TimeTicks::Now() - quit_start; 308 browser_quit_time_ = base::TimeTicks::Now() - quit_start;
309 } 309 }
310 310
311 void ProxyLauncher::AssertAppNotRunning(const std::string& error_message) { 311 void ProxyLauncher::AssertAppNotRunning(const std::string& error_message) {
312 std::string final_error_message(error_message); 312 std::string final_error_message(error_message);
313 313
314 ChromeProcessList processes = GetRunningChromeProcesses(process_id_); 314 ChromeProcessList processes = GetRunningChromeProcesses(process_id_);
315 if (!processes.empty()) { 315 if (!processes.empty()) {
316 final_error_message += " Leftover PIDs: ["; 316 final_error_message += " Leftover PIDs: [";
317 for (ChromeProcessList::const_iterator it = processes.begin(); 317 for (ChromeProcessList::const_iterator it = processes.begin();
318 it != processes.end(); ++it) { 318 it != processes.end(); ++it) {
319 final_error_message += StringPrintf(" %d", *it); 319 final_error_message += StringPrintf(" %d", *it);
320 } 320 }
321 final_error_message += " ]"; 321 final_error_message += " ]";
322 } 322 }
323 ASSERT_TRUE(processes.empty()) << final_error_message; 323 ASSERT_TRUE(processes.empty()) << final_error_message;
324 } 324 }
325 325
326 bool ProxyLauncher::WaitForBrowserProcessToQuit(int timeout, int* exit_code) { 326 bool ProxyLauncher::WaitForBrowserProcessToQuit(
327 base::TimeDelta timeout,
328 int* exit_code) {
327 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN 329 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN
328 timeout = 500000; 330 timeout = base::TimeDelta::FromSeconds(500);
329 #endif 331 #endif
330 bool success = false; 332 bool success = false;
331 333
332 // Only wait for exit if the "browser, please terminate" message had a 334 // Only wait for exit if the "browser, please terminate" message had a
333 // chance of making it through. 335 // chance of making it through.
334 if (!automation_proxy_->channel_disconnected_on_failure()) 336 if (!automation_proxy_->channel_disconnected_on_failure())
335 success = base::WaitForExitCodeWithTimeout(process_, exit_code, timeout); 337 success = base::WaitForExitCodeWithTimeout(process_, exit_code, timeout);
336 338
337 if (!success) 339 if (!success)
338 TerminateAllChromeProcesses(process_id_); 340 TerminateAllChromeProcesses(process_id_);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 506
505 NamedProxyLauncher::NamedProxyLauncher(const std::string& channel_id, 507 NamedProxyLauncher::NamedProxyLauncher(const std::string& channel_id,
506 bool launch_browser, 508 bool launch_browser,
507 bool disconnect_on_failure) 509 bool disconnect_on_failure)
508 : channel_id_(channel_id), 510 : channel_id_(channel_id),
509 launch_browser_(launch_browser), 511 launch_browser_(launch_browser),
510 disconnect_on_failure_(disconnect_on_failure) { 512 disconnect_on_failure_(disconnect_on_failure) {
511 } 513 }
512 514
513 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( 515 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy(
514 int execution_timeout) { 516 base::TimeDelta execution_timeout) {
515 AutomationProxy* proxy = new AutomationProxy(execution_timeout, 517 AutomationProxy* proxy = new AutomationProxy(execution_timeout,
516 disconnect_on_failure_); 518 disconnect_on_failure_);
517 proxy->InitializeChannel(channel_id_, true); 519 proxy->InitializeChannel(channel_id_, true);
518 return proxy; 520 return proxy;
519 } 521 }
520 522
521 bool NamedProxyLauncher::InitializeConnection(const LaunchState& state, 523 bool NamedProxyLauncher::InitializeConnection(const LaunchState& state,
522 bool wait_for_initial_loads) { 524 bool wait_for_initial_loads) {
523 if (launch_browser_) { 525 if (launch_browser_) {
524 #if defined(OS_POSIX) 526 #if defined(OS_POSIX)
525 // Because we are waiting on the existence of the testing file below, 527 // Because we are waiting on the existence of the testing file below,
526 // make sure there isn't one already there before browser launch. 528 // make sure there isn't one already there before browser launch.
527 if (!file_util::Delete(FilePath(channel_id_), false)) { 529 if (!file_util::Delete(FilePath(channel_id_), false)) {
528 LOG(ERROR) << "Failed to delete " << channel_id_; 530 LOG(ERROR) << "Failed to delete " << channel_id_;
529 return false; 531 return false;
530 } 532 }
531 #endif 533 #endif
532 534
533 if (!LaunchBrowser(state)) { 535 if (!LaunchBrowser(state)) {
534 LOG(ERROR) << "Failed to LaunchBrowser"; 536 LOG(ERROR) << "Failed to LaunchBrowser";
535 return false; 537 return false;
536 } 538 }
537 } 539 }
538 540
539 // Wait for browser to be ready for connections. 541 // Wait for browser to be ready for connections.
540 bool channel_initialized = false; 542 bool channel_initialized = false;
541 for (int wait_time = 0; 543 base::TimeDelta sleep_time = base::TimeDelta::FromMilliseconds(
542 wait_time < TestTimeouts::action_max_timeout_ms(); 544 automation::kSleepTime);
543 wait_time += automation::kSleepTime) { 545 for (base::TimeDelta wait_time = base::TimeDelta();
546 wait_time < TestTimeouts::action_max_timeout();
547 wait_time += sleep_time) {
544 channel_initialized = IPC::Channel::IsNamedServerInitialized(channel_id_); 548 channel_initialized = IPC::Channel::IsNamedServerInitialized(channel_id_);
545 if (channel_initialized) 549 if (channel_initialized)
546 break; 550 break;
547 base::PlatformThread::Sleep( 551 base::PlatformThread::Sleep(sleep_time);
548 base::TimeDelta::FromMilliseconds(automation::kSleepTime));
549 } 552 }
550 if (!channel_initialized) { 553 if (!channel_initialized) {
551 LOG(ERROR) << "Failed to wait for testing channel presence."; 554 LOG(ERROR) << "Failed to wait for testing channel presence.";
552 return false; 555 return false;
553 } 556 }
554 557
555 if (!ConnectToRunningBrowser(wait_for_initial_loads)) { 558 if (!ConnectToRunningBrowser(wait_for_initial_loads)) {
556 LOG(ERROR) << "Failed to ConnectToRunningBrowser"; 559 LOG(ERROR) << "Failed to ConnectToRunningBrowser";
557 return false; 560 return false;
558 } 561 }
(...skipping 14 matching lines...) Expand all
573 } 576 }
574 577
575 // AnonymousProxyLauncher functions 578 // AnonymousProxyLauncher functions
576 579
577 AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure) 580 AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure)
578 : disconnect_on_failure_(disconnect_on_failure) { 581 : disconnect_on_failure_(disconnect_on_failure) {
579 channel_id_ = AutomationProxy::GenerateChannelID(); 582 channel_id_ = AutomationProxy::GenerateChannelID();
580 } 583 }
581 584
582 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( 585 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy(
583 int execution_timeout) { 586 base::TimeDelta execution_timeout) {
584 AutomationProxy* proxy = new AutomationProxy(execution_timeout, 587 AutomationProxy* proxy = new AutomationProxy(execution_timeout,
585 disconnect_on_failure_); 588 disconnect_on_failure_);
586 proxy->InitializeChannel(channel_id_, false); 589 proxy->InitializeChannel(channel_id_, false);
587 return proxy; 590 return proxy;
588 } 591 }
589 592
590 bool AnonymousProxyLauncher::InitializeConnection(const LaunchState& state, 593 bool AnonymousProxyLauncher::InitializeConnection(const LaunchState& state,
591 bool wait_for_initial_loads) { 594 bool wait_for_initial_loads) {
592 return LaunchBrowserAndServer(state, wait_for_initial_loads); 595 return LaunchBrowserAndServer(state, wait_for_initial_loads);
593 } 596 }
594 597
595 void AnonymousProxyLauncher::TerminateConnection() { 598 void AnonymousProxyLauncher::TerminateConnection() {
596 CloseBrowserAndServer(); 599 CloseBrowserAndServer();
597 } 600 }
598 601
599 std::string AnonymousProxyLauncher::PrefixedChannelID() const { 602 std::string AnonymousProxyLauncher::PrefixedChannelID() const {
600 return channel_id_; 603 return channel_id_;
601 } 604 }
OLDNEW
« no previous file with comments | « chrome/test/automation/proxy_launcher.h ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698