| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return status; | 149 return status; |
| 150 switches.AppendToCommandLine(&command); | 150 switches.AppendToCommandLine(&command); |
| 151 *prepared_command = command; | 151 *prepared_command = command; |
| 152 return Status(kOk); | 152 return Status(kOk); |
| 153 } | 153 } |
| 154 | 154 |
| 155 Status WaitForDevToolsAndCheckVersion( | 155 Status WaitForDevToolsAndCheckVersion( |
| 156 const NetAddress& address, | 156 const NetAddress& address, |
| 157 URLRequestContextGetter* context_getter, | 157 URLRequestContextGetter* context_getter, |
| 158 const SyncWebSocketFactory& socket_factory, | 158 const SyncWebSocketFactory& socket_factory, |
| 159 const Capabilities* capabilities, |
| 159 scoped_ptr<DevToolsHttpClient>* user_client) { | 160 scoped_ptr<DevToolsHttpClient>* user_client) { |
| 161 scoped_ptr<DeviceMetrics> device_metrics; |
| 162 if (capabilities && capabilities->device_metrics) |
| 163 device_metrics.reset(new DeviceMetrics(*capabilities->device_metrics)); |
| 164 |
| 160 scoped_ptr<DevToolsHttpClient> client(new DevToolsHttpClient( | 165 scoped_ptr<DevToolsHttpClient> client(new DevToolsHttpClient( |
| 161 address, context_getter, socket_factory)); | 166 address, context_getter, socket_factory, device_metrics.Pass())); |
| 162 base::TimeTicks deadline = | 167 base::TimeTicks deadline = |
| 163 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(60); | 168 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(60); |
| 164 Status status = client->Init(deadline - base::TimeTicks::Now()); | 169 Status status = client->Init(deadline - base::TimeTicks::Now()); |
| 165 if (status.IsError()) | 170 if (status.IsError()) |
| 166 return status; | 171 return status; |
| 167 if (client->browser_info()->build_no < kMinimumSupportedChromeBuildNo) { | 172 if (client->browser_info()->build_no < kMinimumSupportedChromeBuildNo) { |
| 168 return Status(kUnknownError, "Chrome version must be >= " + | 173 return Status(kUnknownError, "Chrome version must be >= " + |
| 169 GetMinimumSupportedChromeVersion()); | 174 GetMinimumSupportedChromeVersion()); |
| 170 } | 175 } |
| 171 | 176 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 186 Status LaunchExistingChromeSession( | 191 Status LaunchExistingChromeSession( |
| 187 URLRequestContextGetter* context_getter, | 192 URLRequestContextGetter* context_getter, |
| 188 const SyncWebSocketFactory& socket_factory, | 193 const SyncWebSocketFactory& socket_factory, |
| 189 const Capabilities& capabilities, | 194 const Capabilities& capabilities, |
| 190 ScopedVector<DevToolsEventListener>& devtools_event_listeners, | 195 ScopedVector<DevToolsEventListener>& devtools_event_listeners, |
| 191 scoped_ptr<Chrome>* chrome) { | 196 scoped_ptr<Chrome>* chrome) { |
| 192 Status status(kOk); | 197 Status status(kOk); |
| 193 scoped_ptr<DevToolsHttpClient> devtools_client; | 198 scoped_ptr<DevToolsHttpClient> devtools_client; |
| 194 status = WaitForDevToolsAndCheckVersion( | 199 status = WaitForDevToolsAndCheckVersion( |
| 195 capabilities.debugger_address, context_getter, socket_factory, | 200 capabilities.debugger_address, context_getter, socket_factory, |
| 196 &devtools_client); | 201 NULL, &devtools_client); |
| 197 if (status.IsError()) { | 202 if (status.IsError()) { |
| 198 return Status(kUnknownError, "cannot connect to chrome at " + | 203 return Status(kUnknownError, "cannot connect to chrome at " + |
| 199 capabilities.debugger_address.ToString(), | 204 capabilities.debugger_address.ToString(), |
| 200 status); | 205 status); |
| 201 } | 206 } |
| 202 chrome->reset(new ChromeExistingImpl(devtools_client.Pass(), | 207 chrome->reset(new ChromeExistingImpl(devtools_client.Pass(), |
| 203 devtools_event_listeners)); | 208 devtools_event_listeners)); |
| 204 return Status(kOk); | 209 return Status(kOk); |
| 205 } | 210 } |
| 206 | 211 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 #else | 275 #else |
| 271 std::string command_string = command.GetCommandLineString(); | 276 std::string command_string = command.GetCommandLineString(); |
| 272 #endif | 277 #endif |
| 273 VLOG(0) << "Launching chrome: " << command_string; | 278 VLOG(0) << "Launching chrome: " << command_string; |
| 274 base::ProcessHandle process; | 279 base::ProcessHandle process; |
| 275 if (!base::LaunchProcess(command, options, &process)) | 280 if (!base::LaunchProcess(command, options, &process)) |
| 276 return Status(kUnknownError, "chrome failed to start"); | 281 return Status(kUnknownError, "chrome failed to start"); |
| 277 | 282 |
| 278 scoped_ptr<DevToolsHttpClient> devtools_client; | 283 scoped_ptr<DevToolsHttpClient> devtools_client; |
| 279 status = WaitForDevToolsAndCheckVersion( | 284 status = WaitForDevToolsAndCheckVersion( |
| 280 NetAddress(port), context_getter, socket_factory, &devtools_client); | 285 NetAddress(port), context_getter, socket_factory, &capabilities, |
| 286 &devtools_client); |
| 281 | 287 |
| 282 if (status.IsError()) { | 288 if (status.IsError()) { |
| 283 int exit_code; | 289 int exit_code; |
| 284 base::TerminationStatus chrome_status = | 290 base::TerminationStatus chrome_status = |
| 285 base::GetTerminationStatus(process, &exit_code); | 291 base::GetTerminationStatus(process, &exit_code); |
| 286 if (chrome_status != base::TERMINATION_STATUS_STILL_RUNNING) { | 292 if (chrome_status != base::TERMINATION_STATUS_STILL_RUNNING) { |
| 287 std::string termination_reason; | 293 std::string termination_reason; |
| 288 switch (chrome_status) { | 294 switch (chrome_status) { |
| 289 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 295 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 290 termination_reason = "exited normally"; | 296 termination_reason = "exited normally"; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 port); | 376 port); |
| 371 if (status.IsError()) { | 377 if (status.IsError()) { |
| 372 device->TearDown(); | 378 device->TearDown(); |
| 373 return status; | 379 return status; |
| 374 } | 380 } |
| 375 | 381 |
| 376 scoped_ptr<DevToolsHttpClient> devtools_client; | 382 scoped_ptr<DevToolsHttpClient> devtools_client; |
| 377 status = WaitForDevToolsAndCheckVersion(NetAddress(port), | 383 status = WaitForDevToolsAndCheckVersion(NetAddress(port), |
| 378 context_getter, | 384 context_getter, |
| 379 socket_factory, | 385 socket_factory, |
| 386 &capabilities, |
| 380 &devtools_client); | 387 &devtools_client); |
| 381 if (status.IsError()) { | 388 if (status.IsError()) { |
| 382 device->TearDown(); | 389 device->TearDown(); |
| 383 return status; | 390 return status; |
| 384 } | 391 } |
| 385 | 392 |
| 386 chrome->reset(new ChromeAndroidImpl(devtools_client.Pass(), | 393 chrome->reset(new ChromeAndroidImpl(devtools_client.Pass(), |
| 387 devtools_event_listeners, | 394 devtools_event_listeners, |
| 388 port_reservation.Pass(), | 395 port_reservation.Pass(), |
| 389 device.Pass())); | 396 device.Pass())); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // Write empty "First Run" file, otherwise Chrome will wipe the default | 692 // Write empty "First Run" file, otherwise Chrome will wipe the default |
| 686 // profile that was written. | 693 // profile that was written. |
| 687 if (base::WriteFile( | 694 if (base::WriteFile( |
| 688 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { | 695 user_data_dir.Append(chrome::kFirstRunSentinel), "", 0) != 0) { |
| 689 return Status(kUnknownError, "failed to write first run file"); | 696 return Status(kUnknownError, "failed to write first run file"); |
| 690 } | 697 } |
| 691 return Status(kOk); | 698 return Status(kOk); |
| 692 } | 699 } |
| 693 | 700 |
| 694 } // namespace internal | 701 } // namespace internal |
| OLD | NEW |