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

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

Issue 7870008: Wait properly for renderer crashes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/automation/proxy_launcher.h ('k') | content/browser/browser_child_process_host.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) 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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/test/test_file_util.h" 12 #include "base/test/test_file_util.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/common/automation_constants.h" 16 #include "chrome/common/automation_constants.h"
17 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/logging_chrome.h" 19 #include "chrome/common/logging_chrome.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/test/automation/automation_proxy.h" 21 #include "chrome/test/automation/automation_proxy.h"
22 #include "chrome/test/base/chrome_process_util.h" 22 #include "chrome/test/base/chrome_process_util.h"
23 #include "chrome/test/base/test_launcher_utils.h" 23 #include "chrome/test/base/test_launcher_utils.h"
24 #include "chrome/test/base/test_switches.h" 24 #include "chrome/test/base/test_switches.h"
25 #include "chrome/test/ui/ui_test.h" 25 #include "chrome/test/ui/ui_test.h"
26 #include "content/common/child_process_info.h" 26 #include "content/common/child_process_info.h"
27 #include "content/common/debug_flags.h" 27 #include "content/common/debug_flags.h"
28 #include "ipc/ipc_channel.h" 28 #include "ipc/ipc_channel.h"
29 #include "ipc/ipc_descriptors.h"
29 #include "sql/connection.h" 30 #include "sql/connection.h"
30 31
31 namespace { 32 namespace {
32 33
33 // Passed as value of kTestType. 34 // Passed as value of kTestType.
34 const char kUITestType[] = "ui"; 35 const char kUITestType[] = "ui";
35 36
36 // We want to have a current history database when we start the browser so 37 // We want to have a current history database when we start the browser so
37 // things like the NTP will have thumbnails. This method updates the dates 38 // things like the NTP will have thumbnails. This method updates the dates
38 // in the history to be more recent. 39 // in the history to be more recent.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 << "Error while awaiting automation ping from browser process"; 103 << "Error while awaiting automation ping from browser process";
103 if (app_launched != AUTOMATION_SUCCESS) 104 if (app_launched != AUTOMATION_SUCCESS)
104 return false; 105 return false;
105 106
106 if (wait_for_initial_loads) { 107 if (wait_for_initial_loads) {
107 if (!automation_proxy_->WaitForInitialLoads()) { 108 if (!automation_proxy_->WaitForInitialLoads()) {
108 LOG(ERROR) << "WaitForInitialLoads failed."; 109 LOG(ERROR) << "WaitForInitialLoads failed.";
109 return false; 110 return false;
110 } 111 }
111 } else { 112 } else {
112 // TODO(phajdan.jr): We should get rid of this sleep, but some tests 113 #if defined(OS_WIN)
113 // "rely" on it, e.g. AssertionTest.Assertion and CheckFalseTest.CheckFails. 114 // TODO(phajdan.jr): Get rid of this Sleep when logging_chrome_uitest
114 // Those tests do not wait in any way until the crash gets noticed, 115 // stops "relying" on it.
115 // so it's possible for the browser to exit before the tested crash happens.
116 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); 116 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
117 #endif
117 } 118 }
118 119
119 if (!automation()->SetFilteredInet(ShouldFilterInet())) { 120 if (!automation()->SetFilteredInet(ShouldFilterInet())) {
120 LOG(ERROR) << "SetFilteredInet failed."; 121 LOG(ERROR) << "SetFilteredInet failed.";
121 return false; 122 return false;
122 } 123 }
123 124
124 return true; 125 return true;
125 } 126 }
126 127
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 192 }
192 193
193 // Update the history file to include recent dates. 194 // Update the history file to include recent dates.
194 UpdateHistoryDates(user_data_dir()); 195 UpdateHistoryDates(user_data_dir());
195 } 196 }
196 197
197 // Optionally do any final setup of the test environment. 198 // Optionally do any final setup of the test environment.
198 if (!state.setup_profile_callback.is_null()) 199 if (!state.setup_profile_callback.is_null())
199 state.setup_profile_callback.Run(); 200 state.setup_profile_callback.Run();
200 201
201 if (!LaunchBrowserHelper(state, false, &process_)) { 202 if (!LaunchBrowserHelper(state, true, false, &process_)) {
202 LOG(ERROR) << "LaunchBrowserHelper failed."; 203 LOG(ERROR) << "LaunchBrowserHelper failed.";
203 return false; 204 return false;
204 } 205 }
205 process_id_ = base::GetProcId(process_); 206 process_id_ = base::GetProcId(process_);
206 207
207 return true; 208 return true;
208 } 209 }
209 210
210 #if !defined(OS_MACOSX) 211 #if !defined(OS_MACOSX)
211 bool ProxyLauncher::LaunchAnotherBrowserBlockUntilClosed( 212 bool ProxyLauncher::LaunchAnotherBrowserBlockUntilClosed(
212 const LaunchState& state) { 213 const LaunchState& state) {
213 return LaunchBrowserHelper(state, true, NULL); 214 return LaunchBrowserHelper(state, false, true, NULL);
214 } 215 }
215 #endif 216 #endif
216 217
217 void ProxyLauncher::QuitBrowser() { 218 void ProxyLauncher::QuitBrowser() {
218 // If we have already finished waiting for the browser to exit 219 // If we have already finished waiting for the browser to exit
219 // (or it hasn't launched at all), there's nothing to do here. 220 // (or it hasn't launched at all), there's nothing to do here.
220 if (process_ == base::kNullProcessHandle) 221 if (process_ == base::kNullProcessHandle)
221 return; 222 return;
222 223
223 if (SESSION_ENDING == shutdown_type_) { 224 if (SESSION_ENDING == shutdown_type_) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // Disable TabCloseableStateWatcher for tests. 428 // Disable TabCloseableStateWatcher for tests.
428 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); 429 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher);
429 430
430 // Allow file:// access on ChromeOS. 431 // Allow file:// access on ChromeOS.
431 command_line->AppendSwitch(switches::kAllowFileAccess); 432 command_line->AppendSwitch(switches::kAllowFileAccess);
432 433
433 // Allow testing File API over http. 434 // Allow testing File API over http.
434 command_line->AppendSwitch(switches::kUnlimitedQuotaForFiles); 435 command_line->AppendSwitch(switches::kUnlimitedQuotaForFiles);
435 } 436 }
436 437
437 bool ProxyLauncher::LaunchBrowserHelper(const LaunchState& state, bool wait, 438 bool ProxyLauncher::LaunchBrowserHelper(const LaunchState& state,
439 bool main_launch,
440 bool wait,
438 base::ProcessHandle* process) { 441 base::ProcessHandle* process) {
439 CommandLine command_line(state.command); 442 CommandLine command_line(state.command);
440 443
441 // Add command line arguments that should be applied to all UI tests. 444 // Add command line arguments that should be applied to all UI tests.
442 PrepareTestCommandline(&command_line, state.include_testing_id); 445 PrepareTestCommandline(&command_line, state.include_testing_id);
443 DebugFlags::ProcessDebugFlags( 446 DebugFlags::ProcessDebugFlags(
444 &command_line, ChildProcessInfo::UNKNOWN_PROCESS, false); 447 &command_line, ChildProcessInfo::UNKNOWN_PROCESS, false);
445 448
446 // Sometimes one needs to run the browser under a special environment 449 // Sometimes one needs to run the browser under a special environment
447 // (e.g. valgrind) without also running the test harness (e.g. python) 450 // (e.g. valgrind) without also running the test harness (e.g. python)
448 // under the special environment. Provide a way to wrap the browser 451 // under the special environment. Provide a way to wrap the browser
449 // commandline with a special prefix to invoke the special environment. 452 // commandline with a special prefix to invoke the special environment.
450 const char* browser_wrapper = getenv("BROWSER_WRAPPER"); 453 const char* browser_wrapper = getenv("BROWSER_WRAPPER");
451 if (browser_wrapper) { 454 if (browser_wrapper) {
452 #if defined(OS_WIN) 455 #if defined(OS_WIN)
453 command_line.PrependWrapper(ASCIIToWide(browser_wrapper)); 456 command_line.PrependWrapper(ASCIIToWide(browser_wrapper));
454 #elif defined(OS_POSIX) 457 #elif defined(OS_POSIX)
455 command_line.PrependWrapper(browser_wrapper); 458 command_line.PrependWrapper(browser_wrapper);
456 #endif 459 #endif
457 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with " 460 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with "
458 << browser_wrapper; 461 << browser_wrapper;
459 } 462 }
460 463
461 // TODO(phajdan.jr): Only run it for "main" browser launch. 464 if (main_launch)
462 browser_launch_time_ = base::TimeTicks::Now(); 465 browser_launch_time_ = base::TimeTicks::Now();
463 466
464 base::LaunchOptions options; 467 base::LaunchOptions options;
465 options.wait = wait; 468 options.wait = wait;
466 469
467 #if defined(OS_WIN) 470 #if defined(OS_WIN)
468 options.start_hidden = !state.show_window; 471 options.start_hidden = !state.show_window;
469 #elif defined(OS_POSIX) 472 #elif defined(OS_POSIX)
473 int ipcfd = -1;
474 file_util::ScopedFD ipcfd_closer(&ipcfd);
470 base::file_handle_mapping_vector fds; 475 base::file_handle_mapping_vector fds;
471 if (automation_proxy_.get()) 476 if (main_launch && automation_proxy_.get()) {
472 fds = automation_proxy_->fds_to_map(); 477 ipcfd = automation_proxy_->channel()->TakeClientFileDescriptor();
473 options.fds_to_remap = &fds; 478 fds.push_back(std::make_pair(ipcfd, kPrimaryIPCChannel + 3));
darin (slow to review) 2011/09/19 15:18:54 looks like this worked out well...
479 options.fds_to_remap = &fds;
480 }
474 #endif 481 #endif
475 482
476 return base::LaunchProcess(command_line, options, process); 483 return base::LaunchProcess(command_line, options, process);
477 } 484 }
478 485
479 AutomationProxy* ProxyLauncher::automation() const { 486 AutomationProxy* ProxyLauncher::automation() const {
480 EXPECT_TRUE(automation_proxy_.get()); 487 EXPECT_TRUE(automation_proxy_.get());
481 return automation_proxy_.get(); 488 return automation_proxy_.get();
482 } 489 }
483 490
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 return LaunchBrowserAndServer(state, wait_for_initial_loads); 600 return LaunchBrowserAndServer(state, wait_for_initial_loads);
594 } 601 }
595 602
596 void AnonymousProxyLauncher::TerminateConnection() { 603 void AnonymousProxyLauncher::TerminateConnection() {
597 CloseBrowserAndServer(); 604 CloseBrowserAndServer();
598 } 605 }
599 606
600 std::string AnonymousProxyLauncher::PrefixedChannelID() const { 607 std::string AnonymousProxyLauncher::PrefixedChannelID() const {
601 return channel_id_; 608 return channel_id_;
602 } 609 }
OLDNEW
« no previous file with comments | « chrome/test/automation/proxy_launcher.h ('k') | content/browser/browser_child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698