OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/environment.h" | 7 #include "base/environment.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 return browser_launch_time_; | 492 return browser_launch_time_; |
493 } | 493 } |
494 | 494 |
495 base::TimeDelta ProxyLauncher::browser_quit_time() const { | 495 base::TimeDelta ProxyLauncher::browser_quit_time() const { |
496 return browser_quit_time_; | 496 return browser_quit_time_; |
497 } | 497 } |
498 | 498 |
499 // NamedProxyLauncher functions | 499 // NamedProxyLauncher functions |
500 | 500 |
501 NamedProxyLauncher::NamedProxyLauncher(const std::string& channel_id, | 501 NamedProxyLauncher::NamedProxyLauncher(const std::string& channel_id, |
502 bool launch_browser, | 502 const InitParams& params) |
503 bool disconnect_on_failure) | |
504 : channel_id_(channel_id), | 503 : channel_id_(channel_id), |
505 launch_browser_(launch_browser), | 504 launch_browser_(params.launch_browser), |
506 disconnect_on_failure_(disconnect_on_failure) { | 505 disconnect_on_failure_(params.disconnect_on_failure), |
| 506 wait_for_server_channel_(params.wait_for_server_channel) { |
507 } | 507 } |
508 | 508 |
509 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( | 509 AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( |
510 int execution_timeout) { | 510 int execution_timeout) { |
511 AutomationProxy* proxy = new AutomationProxy(execution_timeout, | 511 AutomationProxy* proxy = new AutomationProxy(execution_timeout, |
512 disconnect_on_failure_); | 512 disconnect_on_failure_); |
513 proxy->InitializeChannel(channel_id_, true); | 513 proxy->InitializeChannel(channel_id_, true); |
514 return proxy; | 514 return proxy; |
515 } | 515 } |
516 | 516 |
517 void NamedProxyLauncher::InitializeConnection(const LaunchState& state, | 517 bool NamedProxyLauncher::InitializeConnection(const LaunchState& state, |
518 bool wait_for_initial_loads) { | 518 bool wait_for_initial_loads) { |
519 FilePath testing_channel_path; | 519 FilePath testing_channel_path; |
520 #if defined(OS_WIN) | 520 #if defined(OS_WIN) |
521 testing_channel_path = FilePath(ASCIIToWide(channel_id_)); | 521 testing_channel_path = FilePath(ASCIIToWide(channel_id_)); |
522 #else | 522 #else |
523 testing_channel_path = FilePath(channel_id_); | 523 testing_channel_path = FilePath(channel_id_); |
524 #endif | 524 #endif |
525 | 525 |
526 if (launch_browser_) { | 526 if (launch_browser_) { |
527 // 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, |
528 // make sure there isn't one already there before browser launch. | 528 // make sure there isn't one already there before browser launch. |
529 EXPECT_TRUE(file_util::Delete(testing_channel_path, false)); | 529 if (!file_util::Delete(testing_channel_path, false)) { |
| 530 LOG(ERROR) << "Failed to delete " << testing_channel_path.value(); |
| 531 return false; |
| 532 } |
530 | 533 |
531 // Set up IPC testing interface as a client. | 534 if (!LaunchBrowser(state)) { |
532 ASSERT_TRUE(LaunchBrowser(state)); | 535 LOG(ERROR) << "Failed to LaunchBrowser"; |
| 536 return false; |
| 537 } |
533 } | 538 } |
534 | 539 |
535 // Wait for browser to be ready for connections. | 540 if (wait_for_server_channel_) { |
536 bool testing_channel_exists = false; | 541 // Wait for browser to be ready for connections. |
537 for (int wait_time = 0; | 542 bool testing_channel_exists = false; |
538 wait_time < TestTimeouts::action_max_timeout_ms(); | 543 for (int wait_time = 0; |
539 wait_time += automation::kSleepTime) { | 544 wait_time < TestTimeouts::action_max_timeout_ms(); |
540 testing_channel_exists = file_util::PathExists(testing_channel_path); | 545 wait_time += automation::kSleepTime) { |
541 if (testing_channel_exists) | 546 testing_channel_exists = file_util::PathExists(testing_channel_path); |
542 break; | 547 if (testing_channel_exists) |
543 base::PlatformThread::Sleep(automation::kSleepTime); | 548 break; |
| 549 base::PlatformThread::Sleep(automation::kSleepTime); |
| 550 } |
| 551 if (!testing_channel_exists) { |
| 552 LOG(ERROR) << "Failed to wait for testing channel presence."; |
| 553 return false; |
| 554 } |
544 } | 555 } |
545 EXPECT_TRUE(testing_channel_exists); | |
546 | 556 |
547 ASSERT_TRUE(ConnectToRunningBrowser(wait_for_initial_loads)); | 557 if (!ConnectToRunningBrowser(wait_for_initial_loads)) { |
| 558 LOG(ERROR) << "Failed to ConnectToRunningBrowser"; |
| 559 return false; |
| 560 } |
| 561 |
| 562 return true; |
548 } | 563 } |
549 | 564 |
550 void NamedProxyLauncher::TerminateConnection() { | 565 void NamedProxyLauncher::TerminateConnection() { |
551 if (launch_browser_) | 566 if (launch_browser_) |
552 CloseBrowserAndServer(); | 567 CloseBrowserAndServer(); |
553 else | 568 else |
554 DisconnectFromRunningBrowser(); | 569 DisconnectFromRunningBrowser(); |
555 } | 570 } |
556 | 571 |
557 std::string NamedProxyLauncher::PrefixedChannelID() const { | 572 std::string NamedProxyLauncher::PrefixedChannelID() const { |
(...skipping 10 matching lines...) Expand all Loading... |
568 } | 583 } |
569 | 584 |
570 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( | 585 AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( |
571 int execution_timeout) { | 586 int execution_timeout) { |
572 AutomationProxy* proxy = new AutomationProxy(execution_timeout, | 587 AutomationProxy* proxy = new AutomationProxy(execution_timeout, |
573 disconnect_on_failure_); | 588 disconnect_on_failure_); |
574 proxy->InitializeChannel(channel_id_, false); | 589 proxy->InitializeChannel(channel_id_, false); |
575 return proxy; | 590 return proxy; |
576 } | 591 } |
577 | 592 |
578 void AnonymousProxyLauncher::InitializeConnection(const LaunchState& state, | 593 bool AnonymousProxyLauncher::InitializeConnection(const LaunchState& state, |
579 bool wait_for_initial_loads) { | 594 bool wait_for_initial_loads) { |
580 ASSERT_TRUE(LaunchBrowserAndServer(state, wait_for_initial_loads)); | 595 return LaunchBrowserAndServer(state, wait_for_initial_loads); |
581 } | 596 } |
582 | 597 |
583 void AnonymousProxyLauncher::TerminateConnection() { | 598 void AnonymousProxyLauncher::TerminateConnection() { |
584 CloseBrowserAndServer(); | 599 CloseBrowserAndServer(); |
585 } | 600 } |
586 | 601 |
587 std::string AnonymousProxyLauncher::PrefixedChannelID() const { | 602 std::string AnonymousProxyLauncher::PrefixedChannelID() const { |
588 return channel_id_; | 603 return channel_id_; |
589 } | 604 } |
OLD | NEW |