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