Chromium Code Reviews| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 DeviceManager* device_manager, | 346 DeviceManager* device_manager, |
| 347 scoped_ptr<Chrome>* chrome) { | 347 scoped_ptr<Chrome>* chrome) { |
| 348 Status status(kOk); | 348 Status status(kOk); |
| 349 scoped_ptr<Device> device; | 349 scoped_ptr<Device> device; |
| 350 if (capabilities.android_device_serial.empty()) { | 350 if (capabilities.android_device_serial.empty()) { |
| 351 status = device_manager->AcquireDevice(&device); | 351 status = device_manager->AcquireDevice(&device); |
| 352 } else { | 352 } else { |
| 353 status = device_manager->AcquireSpecificDevice( | 353 status = device_manager->AcquireSpecificDevice( |
| 354 capabilities.android_device_serial, &device); | 354 capabilities.android_device_serial, &device); |
| 355 } | 355 } |
| 356 if (!status.IsOk()) | 356 if (status.IsError()) |
| 357 return status; | 357 return status; |
| 358 | 358 |
| 359 Switches switches(capabilities.switches); | 359 Switches switches(capabilities.switches); |
| 360 for (size_t i = 0; i < arraysize(kCommonSwitches); ++i) | 360 for (size_t i = 0; i < arraysize(kCommonSwitches); ++i) |
| 361 switches.SetSwitch(kCommonSwitches[i]); | 361 switches.SetSwitch(kCommonSwitches[i]); |
| 362 switches.SetSwitch("disable-fre"); | 362 switches.SetSwitch("disable-fre"); |
| 363 switches.SetSwitch("enable-remote-debugging"); | 363 switches.SetSwitch("enable-remote-debugging"); |
| 364 status = device->SetUp(capabilities.android_package, | 364 status = device->SetUp(capabilities.android_package, |
| 365 capabilities.android_activity, | 365 capabilities.android_activity, |
| 366 capabilities.android_process, | 366 capabilities.android_process, |
| 367 switches.ToString(), | 367 switches.ToString(), |
| 368 capabilities.android_use_running_app, | 368 capabilities.android_use_running_app, |
| 369 port); | 369 port); |
| 370 if (!status.IsOk()) { | 370 if (status.IsError()) { |
| 371 device->TearDown(); | 371 device->TearDown(); |
| 372 return status; | 372 return status; |
| 373 } | 373 } |
| 374 | 374 |
| 375 scoped_ptr<DevToolsHttpClient> devtools_client; | 375 scoped_ptr<DevToolsHttpClient> devtools_client; |
| 376 status = WaitForDevToolsAndCheckVersion(NetAddress(port), | 376 status = WaitForDevToolsAndCheckVersion(NetAddress(port), |
| 377 context_getter, | 377 context_getter, |
| 378 socket_factory, | 378 socket_factory, |
| 379 &devtools_client); | 379 &devtools_client); |
| 380 if (status.IsError()) | 380 if (status.IsError()) { |
| 381 device->TearDown(); | |
| 381 return status; | 382 return status; |
| 383 } | |
| 382 | 384 |
| 383 chrome->reset(new ChromeAndroidImpl(devtools_client.Pass(), | 385 chrome->reset(new ChromeAndroidImpl(devtools_client.Pass(), |
| 384 devtools_event_listeners, | 386 devtools_event_listeners, |
| 385 port_reservation.Pass(), | 387 port_reservation.Pass(), |
| 386 device.Pass())); | 388 device.Pass())); |
| 387 return Status(kOk); | 389 return Status(kOk); |
| 388 } | 390 } |
| 389 | 391 |
| 390 } // namespace | 392 } // namespace |
| 391 | 393 |
| 392 Status LaunchChrome( | 394 Status LaunchChrome( |
| 393 URLRequestContextGetter* context_getter, | 395 URLRequestContextGetter* context_getter, |
| 394 const SyncWebSocketFactory& socket_factory, | 396 const SyncWebSocketFactory& socket_factory, |
| 395 DeviceManager* device_manager, | 397 DeviceManager* device_manager, |
| 396 PortServer* port_server, | 398 PortServer* port_server, |
| 397 PortManager* port_manager, | 399 PortManager* port_manager, |
| 400 PortManager* port_manager_android, | |
| 398 const Capabilities& capabilities, | 401 const Capabilities& capabilities, |
| 399 ScopedVector<DevToolsEventListener>& devtools_event_listeners, | 402 ScopedVector<DevToolsEventListener>& devtools_event_listeners, |
| 400 scoped_ptr<Chrome>* chrome) { | 403 scoped_ptr<Chrome>* chrome) { |
| 401 if (capabilities.IsExistingBrowser()) { | 404 if (capabilities.IsExistingBrowser()) { |
| 402 return LaunchExistingChromeSession( | 405 return LaunchExistingChromeSession( |
| 403 context_getter, socket_factory, | 406 context_getter, socket_factory, |
| 404 capabilities, devtools_event_listeners, chrome); | 407 capabilities, devtools_event_listeners, chrome); |
| 405 } | 408 } |
| 406 | 409 |
| 407 int port = 0; | 410 int port = 0; |
| 408 scoped_ptr<PortReservation> port_reservation; | 411 scoped_ptr<PortReservation> port_reservation; |
| 409 Status port_status(kOk); | 412 Status port_status(kOk); |
| 410 if (port_server) | |
| 411 port_status = port_server->ReservePort(&port, &port_reservation); | |
| 412 else | |
| 413 port_status = port_manager->ReservePort(&port, &port_reservation); | |
| 414 if (port_status.IsError()) | |
| 415 return Status(kUnknownError, "cannot reserve port for Chrome", port_status); | |
| 416 | 413 |
| 417 if (capabilities.IsAndroid()) { | 414 if (capabilities.IsAndroid()) { |
| 415 port_status = port_manager_android->ReservePort(&port, &port_reservation); | |
|
craigdh
2014/01/08 20:56:33
then just call the port_manager->ReservePortFromPo
frankf
2014/01/08 21:57:25
Done.
| |
| 416 if (port_status.IsError()) | |
| 417 return Status(kUnknownError, "cannot reserve port for Chrome", | |
| 418 port_status); | |
| 418 return LaunchAndroidChrome(context_getter, | 419 return LaunchAndroidChrome(context_getter, |
| 419 port, | 420 port, |
| 420 port_reservation.Pass(), | 421 port_reservation.Pass(), |
| 421 socket_factory, | 422 socket_factory, |
| 422 capabilities, | 423 capabilities, |
| 423 devtools_event_listeners, | 424 devtools_event_listeners, |
| 424 device_manager, | 425 device_manager, |
| 425 chrome); | 426 chrome); |
| 426 } else { | 427 } else { |
| 428 if (port_server) | |
| 429 port_status = port_server->ReservePort(&port, &port_reservation); | |
| 430 else | |
| 431 port_status = port_manager->ReservePort(&port, &port_reservation); | |
| 432 if (port_status.IsError()) | |
| 433 return Status(kUnknownError, "cannot reserve port for Chrome", | |
| 434 port_status); | |
| 427 return LaunchDesktopChrome(context_getter, | 435 return LaunchDesktopChrome(context_getter, |
| 428 port, | 436 port, |
| 429 port_reservation.Pass(), | 437 port_reservation.Pass(), |
| 430 socket_factory, | 438 socket_factory, |
| 431 capabilities, | 439 capabilities, |
| 432 devtools_event_listeners, | 440 devtools_event_listeners, |
| 433 chrome); | 441 chrome); |
| 434 } | 442 } |
| 435 } | 443 } |
| 436 | 444 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 // Write empty "First Run" file, otherwise Chrome will wipe the default | 685 // Write empty "First Run" file, otherwise Chrome will wipe the default |
| 678 // profile that was written. | 686 // profile that was written. |
| 679 if (file_util::WriteFile( | 687 if (file_util::WriteFile( |
| 680 user_data_dir.AppendASCII("First Run"), "", 0) != 0) { | 688 user_data_dir.AppendASCII("First Run"), "", 0) != 0) { |
| 681 return Status(kUnknownError, "failed to write first run file"); | 689 return Status(kUnknownError, "failed to write first run file"); |
| 682 } | 690 } |
| 683 return Status(kOk); | 691 return Status(kOk); |
| 684 } | 692 } |
| 685 | 693 |
| 686 } // namespace internal | 694 } // namespace internal |
| OLD | NEW |