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/session_commands.h" | 5 #include "chrome/test/chromedriver/session_commands.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 | 189 |
190 session->window = web_view_ids.front(); | 190 session->window = web_view_ids.front(); |
191 session->detach = capabilities.detach; | 191 session->detach = capabilities.detach; |
192 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; | 192 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; |
193 session->capabilities = CreateCapabilities(session->chrome.get()); | 193 session->capabilities = CreateCapabilities(session->chrome.get()); |
194 value->reset(session->capabilities->DeepCopy()); | 194 value->reset(session->capabilities->DeepCopy()); |
195 return CheckSessionCreated(session); | 195 return CheckSessionCreated(session); |
196 } | 196 } |
197 | 197 |
| 198 Status SwitchToWebView(Session* session, const std::string& web_view_id) { |
| 199 if (session->overridden_geoposition) { |
| 200 WebView* web_view; |
| 201 Status status = session->chrome->GetWebViewById(web_view_id, &web_view); |
| 202 if (status.IsError()) |
| 203 return status; |
| 204 status = web_view->ConnectIfNecessary(); |
| 205 if (status.IsError()) |
| 206 return status; |
| 207 status = web_view->OverrideGeolocation(*session->overridden_geoposition); |
| 208 if (status.IsError()) |
| 209 return status; |
| 210 } |
| 211 |
| 212 if (session->overridden_network_conditions) { |
| 213 WebView* web_view; |
| 214 Status status = session->chrome->GetWebViewById(web_view_id, &web_view); |
| 215 if (status.IsError()) |
| 216 return status; |
| 217 status = web_view->ConnectIfNecessary(); |
| 218 if (status.IsError()) |
| 219 return status; |
| 220 status = web_view->OverrideNetworkConditions( |
| 221 *session->overridden_network_conditions); |
| 222 if (status.IsError()) |
| 223 return status; |
| 224 } |
| 225 |
| 226 session->window = web_view_id; |
| 227 session->SwitchToTopFrame(); |
| 228 session->mouse_position = WebPoint(0, 0); |
| 229 return Status(kOk); |
| 230 } |
| 231 |
198 } // namespace | 232 } // namespace |
199 | 233 |
200 Status ExecuteInitSession( | 234 Status ExecuteInitSession( |
201 const InitSessionParams& bound_params, | 235 const InitSessionParams& bound_params, |
202 Session* session, | 236 Session* session, |
203 const base::DictionaryValue& params, | 237 const base::DictionaryValue& params, |
204 scoped_ptr<base::Value>* value) { | 238 scoped_ptr<base::Value>* value) { |
205 Status status = InitSessionHelper(bound_params, session, params, value); | 239 Status status = InitSessionHelper(bound_params, session, params, value); |
206 if (status.IsError()) { | 240 if (status.IsError()) { |
207 session->quit = true; | 241 session->quit = true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 ChromeDesktopImpl* desktop = NULL; | 290 ChromeDesktopImpl* desktop = NULL; |
257 Status status = session->chrome->GetAsDesktop(&desktop); | 291 Status status = session->chrome->GetAsDesktop(&desktop); |
258 if (status.IsError()) | 292 if (status.IsError()) |
259 return status; | 293 return status; |
260 | 294 |
261 AutomationExtension* extension = NULL; | 295 AutomationExtension* extension = NULL; |
262 status = desktop->GetAutomationExtension(&extension); | 296 status = desktop->GetAutomationExtension(&extension); |
263 if (status.IsError()) | 297 if (status.IsError()) |
264 return status; | 298 return status; |
265 | 299 |
266 return extension->LaunchApp(id); | 300 status = extension->LaunchApp(id); |
| 301 if (status.IsError()) |
| 302 return status; |
| 303 |
| 304 std::string web_view_id; |
| 305 base::TimeDelta timeout = base::TimeDelta::FromSeconds(60); |
| 306 status = desktop->WaitForNewAppWindow(timeout, id, &web_view_id); |
| 307 if (status.IsError()) |
| 308 return status; |
| 309 |
| 310 return SwitchToWebView(session, web_view_id); |
267 } | 311 } |
268 | 312 |
269 Status ExecuteClose( | 313 Status ExecuteClose( |
270 Session* session, | 314 Session* session, |
271 const base::DictionaryValue& params, | 315 const base::DictionaryValue& params, |
272 scoped_ptr<base::Value>* value) { | 316 scoped_ptr<base::Value>* value) { |
273 std::list<std::string> web_view_ids; | 317 std::list<std::string> web_view_ids; |
274 Status status = session->chrome->GetWebViewIds(&web_view_ids); | 318 Status status = session->chrome->GetWebViewIds(&web_view_ids); |
275 if (status.IsError()) | 319 if (status.IsError()) |
276 return status; | 320 return status; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (window_name == name) { | 406 if (window_name == name) { |
363 web_view_id = *it; | 407 web_view_id = *it; |
364 found = true; | 408 found = true; |
365 break; | 409 break; |
366 } | 410 } |
367 } | 411 } |
368 } | 412 } |
369 | 413 |
370 if (!found) | 414 if (!found) |
371 return Status(kNoSuchWindow); | 415 return Status(kNoSuchWindow); |
372 | 416 return SwitchToWebView(session, web_view_id); |
373 if (session->overridden_geoposition) { | |
374 WebView* web_view; | |
375 status = session->chrome->GetWebViewById(web_view_id, &web_view); | |
376 if (status.IsError()) | |
377 return status; | |
378 status = web_view->ConnectIfNecessary(); | |
379 if (status.IsError()) | |
380 return status; | |
381 status = web_view->OverrideGeolocation(*session->overridden_geoposition); | |
382 if (status.IsError()) | |
383 return status; | |
384 } | |
385 | |
386 if (session->overridden_network_conditions) { | |
387 WebView* web_view; | |
388 status = session->chrome->GetWebViewById(web_view_id, &web_view); | |
389 if (status.IsError()) | |
390 return status; | |
391 status = web_view->ConnectIfNecessary(); | |
392 if (status.IsError()) | |
393 return status; | |
394 status = web_view->OverrideNetworkConditions( | |
395 *session->overridden_network_conditions); | |
396 if (status.IsError()) | |
397 return status; | |
398 } | |
399 | |
400 session->window = web_view_id; | |
401 session->SwitchToTopFrame(); | |
402 session->mouse_position = WebPoint(0, 0); | |
403 return Status(kOk); | |
404 } | 417 } |
405 | 418 |
406 Status ExecuteSetTimeout( | 419 Status ExecuteSetTimeout( |
407 Session* session, | 420 Session* session, |
408 const base::DictionaryValue& params, | 421 const base::DictionaryValue& params, |
409 scoped_ptr<base::Value>* value) { | 422 scoped_ptr<base::Value>* value) { |
410 double ms_double; | 423 double ms_double; |
411 if (!params.GetDouble("ms", &ms_double)) | 424 if (!params.GetDouble("ms", &ms_double)) |
412 return Status(kUnknownError, "'ms' must be a double"); | 425 return Status(kUnknownError, "'ms' must be a double"); |
413 std::string type; | 426 std::string type; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 Status ExecuteSetAutoReporting( | 725 Status ExecuteSetAutoReporting( |
713 Session* session, | 726 Session* session, |
714 const base::DictionaryValue& params, | 727 const base::DictionaryValue& params, |
715 scoped_ptr<base::Value>* value) { | 728 scoped_ptr<base::Value>* value) { |
716 bool enabled; | 729 bool enabled; |
717 if (!params.GetBoolean("enabled", &enabled)) | 730 if (!params.GetBoolean("enabled", &enabled)) |
718 return Status(kUnknownError, "missing parameter 'enabled'"); | 731 return Status(kUnknownError, "missing parameter 'enabled'"); |
719 session->auto_reporting_enabled = enabled; | 732 session->auto_reporting_enabled = enabled; |
720 return Status(kOk); | 733 return Status(kOk); |
721 } | 734 } |
OLD | NEW |