OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromedriver/chrome_launcher.h" | 5 #include "chrome/test/chromedriver/chrome_launcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 options.stdin_handle = GetStdHandle(STD_INPUT_HANDLE); | 345 options.stdin_handle = GetStdHandle(STD_INPUT_HANDLE); |
346 options.inherit_handles = true; | 346 options.inherit_handles = true; |
347 #endif | 347 #endif |
348 | 348 |
349 #if defined(OS_WIN) | 349 #if defined(OS_WIN) |
350 std::string command_string = base::WideToUTF8(command.GetCommandLineString()); | 350 std::string command_string = base::WideToUTF8(command.GetCommandLineString()); |
351 #else | 351 #else |
352 std::string command_string = command.GetCommandLineString(); | 352 std::string command_string = command.GetCommandLineString(); |
353 #endif | 353 #endif |
354 VLOG(0) << "Launching chrome: " << command_string; | 354 VLOG(0) << "Launching chrome: " << command_string; |
355 base::ProcessHandle process; | 355 base::Process process = base::LaunchProcess(command, options); |
356 if (!base::LaunchProcess(command, options, &process)) | 356 if (!process.IsValid()) |
357 return Status(kUnknownError, "chrome failed to start"); | 357 return Status(kUnknownError, "chrome failed to start"); |
358 | 358 |
359 scoped_ptr<DevToolsHttpClient> devtools_http_client; | 359 scoped_ptr<DevToolsHttpClient> devtools_http_client; |
360 status = WaitForDevToolsAndCheckVersion( | 360 status = WaitForDevToolsAndCheckVersion( |
361 NetAddress(port), context_getter, socket_factory, &capabilities, | 361 NetAddress(port), context_getter, socket_factory, &capabilities, |
362 &devtools_http_client); | 362 &devtools_http_client); |
363 | 363 |
364 if (status.IsError()) { | 364 if (status.IsError()) { |
365 int exit_code; | 365 int exit_code; |
366 base::TerminationStatus chrome_status = | 366 base::TerminationStatus chrome_status = |
367 base::GetTerminationStatus(process, &exit_code); | 367 base::GetTerminationStatus(process.Handle(), &exit_code); |
368 if (chrome_status != base::TERMINATION_STATUS_STILL_RUNNING) { | 368 if (chrome_status != base::TERMINATION_STATUS_STILL_RUNNING) { |
369 std::string termination_reason; | 369 std::string termination_reason; |
370 switch (chrome_status) { | 370 switch (chrome_status) { |
371 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 371 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
372 termination_reason = "exited normally"; | 372 termination_reason = "exited normally"; |
373 break; | 373 break; |
374 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 374 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
375 termination_reason = "exited abnormally"; | 375 termination_reason = "exited abnormally"; |
376 break; | 376 break; |
377 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 377 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
378 termination_reason = "was killed"; | 378 termination_reason = "was killed"; |
379 break; | 379 break; |
380 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 380 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
381 termination_reason = "crashed"; | 381 termination_reason = "crashed"; |
382 break; | 382 break; |
383 default: | 383 default: |
384 termination_reason = "unknown"; | 384 termination_reason = "unknown"; |
385 break; | 385 break; |
386 } | 386 } |
387 return Status(kUnknownError, | 387 return Status(kUnknownError, |
388 "Chrome failed to start: " + termination_reason); | 388 "Chrome failed to start: " + termination_reason); |
389 } | 389 } |
390 if (!base::KillProcess(process, 0, true)) { | 390 if (!base::KillProcess(process.Handle(), 0, true)) { |
391 int exit_code; | 391 int exit_code; |
392 if (base::GetTerminationStatus(process, &exit_code) == | 392 if (base::GetTerminationStatus(process.Handle(), &exit_code) == |
393 base::TERMINATION_STATUS_STILL_RUNNING) | 393 base::TERMINATION_STATUS_STILL_RUNNING) |
394 return Status(kUnknownError, "cannot kill Chrome", status); | 394 return Status(kUnknownError, "cannot kill Chrome", status); |
395 } | 395 } |
396 return status; | 396 return status; |
397 } | 397 } |
398 | 398 |
399 scoped_ptr<DevToolsClient> devtools_websocket_client; | 399 scoped_ptr<DevToolsClient> devtools_websocket_client; |
400 status = CreateBrowserwideDevToolsClientAndConnect( | 400 status = CreateBrowserwideDevToolsClientAndConnect( |
401 NetAddress(port), capabilities.perf_logging_prefs, socket_factory, | 401 NetAddress(port), capabilities.perf_logging_prefs, socket_factory, |
402 *devtools_event_listeners, &devtools_websocket_client); | 402 *devtools_event_listeners, &devtools_websocket_client); |
403 if (status.IsError()) { | 403 if (status.IsError()) { |
404 LOG(WARNING) << "Browser-wide DevTools client failed to connect: " | 404 LOG(WARNING) << "Browser-wide DevTools client failed to connect: " |
405 << status.message(); | 405 << status.message(); |
406 } | 406 } |
407 | 407 |
408 scoped_ptr<ChromeDesktopImpl> chrome_desktop( | 408 scoped_ptr<ChromeDesktopImpl> chrome_desktop( |
409 new ChromeDesktopImpl(devtools_http_client.Pass(), | 409 new ChromeDesktopImpl(devtools_http_client.Pass(), |
410 devtools_websocket_client.Pass(), | 410 devtools_websocket_client.Pass(), |
411 *devtools_event_listeners, | 411 *devtools_event_listeners, |
412 port_reservation.Pass(), | 412 port_reservation.Pass(), |
413 process, | 413 process.Pass(), |
414 command, | 414 command, |
415 &user_data_dir, | 415 &user_data_dir, |
416 &extension_dir)); | 416 &extension_dir)); |
417 for (size_t i = 0; i < extension_bg_pages.size(); ++i) { | 417 for (size_t i = 0; i < extension_bg_pages.size(); ++i) { |
418 VLOG(0) << "Waiting for extension bg page load: " << extension_bg_pages[i]; | 418 VLOG(0) << "Waiting for extension bg page load: " << extension_bg_pages[i]; |
419 scoped_ptr<WebView> web_view; | 419 scoped_ptr<WebView> web_view; |
420 Status status = chrome_desktop->WaitForPageToLoad( | 420 Status status = chrome_desktop->WaitForPageToLoad( |
421 extension_bg_pages[i], base::TimeDelta::FromSeconds(10), &web_view); | 421 extension_bg_pages[i], base::TimeDelta::FromSeconds(10), &web_view); |
422 if (status.IsError()) { | 422 if (status.IsError()) { |
423 return Status(kUnknownError, | 423 return Status(kUnknownError, |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // Write empty "First Run" file, otherwise Chrome will wipe the default | 835 // Write empty "First Run" file, otherwise Chrome will wipe the default |
836 // profile that was written. | 836 // profile that was written. |
837 if (base::WriteFile( | 837 if (base::WriteFile( |
838 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { | 838 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { |
839 return Status(kUnknownError, "failed to write first run file"); | 839 return Status(kUnknownError, "failed to write first run file"); |
840 } | 840 } |
841 return Status(kOk); | 841 return Status(kOk); |
842 } | 842 } |
843 | 843 |
844 } // namespace internal | 844 } // namespace internal |
OLD | NEW |