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/window_commands.h" | 5 #include "chrome/test/chromedriver/window_commands.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 return web_view->DispatchTouchEvents(events); | 196 return web_view->DispatchTouchEvents(events); |
197 } | 197 } |
198 | 198 |
199 } // namespace | 199 } // namespace |
200 | 200 |
201 Status ExecuteWindowCommand( | 201 Status ExecuteWindowCommand( |
202 const WindowCommand& command, | 202 const WindowCommand& command, |
203 Session* session, | 203 Session* session, |
204 const base::DictionaryValue& params, | 204 const base::DictionaryValue& params, |
205 scoped_ptr<base::Value>* value) { | 205 scoped_ptr<base::Value>* value) { |
206 Timeout timeout; | |
samuong
2016/02/20 00:11:44
I might have misread how this works, but does time
| |
206 WebView* web_view = NULL; | 207 WebView* web_view = NULL; |
207 Status status = session->GetTargetWindow(&web_view); | 208 Status status = session->GetTargetWindow(&web_view); |
208 if (status.IsError()) | 209 if (status.IsError()) |
209 return status; | 210 return status; |
210 | 211 |
211 status = web_view->ConnectIfNecessary(); | 212 status = web_view->ConnectIfNecessary(); |
212 if (status.IsError()) | 213 if (status.IsError()) |
213 return status; | 214 return status; |
214 | 215 |
215 status = web_view->HandleReceivedEvents(); | 216 status = web_view->HandleReceivedEvents(); |
(...skipping 10 matching lines...) Expand all Loading... | |
226 } | 227 } |
227 | 228 |
228 Status nav_status(kOk); | 229 Status nav_status(kOk); |
229 for (int attempt = 0; attempt < 3; attempt++) { | 230 for (int attempt = 0; attempt < 3; attempt++) { |
230 if (attempt == 2) { | 231 if (attempt == 2) { |
231 // Switch to main frame and retry command if subframe no longer exists. | 232 // Switch to main frame and retry command if subframe no longer exists. |
232 session->SwitchToTopFrame(); | 233 session->SwitchToTopFrame(); |
233 } | 234 } |
234 | 235 |
235 nav_status = web_view->WaitForPendingNavigations( | 236 nav_status = web_view->WaitForPendingNavigations( |
236 session->GetCurrentFrameId(), session->page_load_timeout, true); | 237 session->GetCurrentFrameId(), |
238 Timeout(session->page_load_timeout, &timeout), | |
samuong
2016/02/20 00:11:44
...and if so, does that mean that the timeout dura
Alexander Semashko
2016/02/20 00:38:40
No, the outer timout's duration has effect only if
samuong
2016/02/22 23:55:35
Ah right, I misread the way TimeTicks::is_null() w
| |
239 true); | |
237 if (nav_status.IsError()) | 240 if (nav_status.IsError()) |
238 return nav_status; | 241 return nav_status; |
239 | 242 |
240 status = command.Run(session, web_view, params, value); | 243 status = command.Run(session, web_view, params, value, &timeout); |
samuong
2016/02/22 23:55:35
...however the call to command.Run here may or may
Alexander Semashko
2016/02/24 12:51:20
Good catch! I've changed the code so that it's ok
| |
241 if (status.code() == kNoSuchExecutionContext) { | 244 if (status.code() == kNoSuchExecutionContext || |
245 status.code() == kTimeout) { | |
246 // If the command timed out, let WaitForPendingNavigations cancel | |
247 // the navigation if there is one. | |
242 continue; | 248 continue; |
243 } else if (status.IsError()) { | 249 } else if (status.IsError()) { |
244 // If the command failed while a new page or frame started loading, retry | 250 // If the command failed while a new page or frame started loading, retry |
245 // the command after the pending navigation has completed. | 251 // the command after the pending navigation has completed. |
246 bool is_pending = false; | 252 bool is_pending = false; |
247 nav_status = web_view->IsPendingNavigation(session->GetCurrentFrameId(), | 253 nav_status = web_view->IsPendingNavigation(session->GetCurrentFrameId(), |
248 &is_pending); | 254 &timeout, &is_pending); |
249 if (nav_status.IsError()) | 255 if (nav_status.IsError()) |
250 return nav_status; | 256 return nav_status; |
251 else if (is_pending) | 257 else if (is_pending) |
252 continue; | 258 continue; |
253 } | 259 } |
254 break; | 260 break; |
255 } | 261 } |
256 | 262 |
257 nav_status = web_view->WaitForPendingNavigations( | 263 nav_status = web_view->WaitForPendingNavigations( |
258 session->GetCurrentFrameId(), session->page_load_timeout, true); | 264 session->GetCurrentFrameId(), |
265 Timeout(session->page_load_timeout, &timeout), | |
266 true); | |
259 | 267 |
260 if (status.IsOk() && nav_status.IsError() && | 268 if (status.IsOk() && nav_status.IsError() && |
261 nav_status.code() != kUnexpectedAlertOpen) | 269 nav_status.code() != kUnexpectedAlertOpen) |
262 return nav_status; | 270 return nav_status; |
263 if (status.code() == kUnexpectedAlertOpen) | 271 if (status.code() == kUnexpectedAlertOpen) |
264 return Status(kOk); | 272 return Status(kOk); |
265 return status; | 273 return status; |
266 } | 274 } |
267 | 275 |
268 Status ExecuteGet( | 276 Status ExecuteGet( |
269 Session* session, | 277 Session* session, |
270 WebView* web_view, | 278 WebView* web_view, |
271 const base::DictionaryValue& params, | 279 const base::DictionaryValue& params, |
272 scoped_ptr<base::Value>* value) { | 280 scoped_ptr<base::Value>* value, |
281 Timeout* timeout) { | |
282 timeout->SetDuration(session->page_load_timeout); | |
samuong
2016/02/19 20:18:58
Is there a need to have a series of subtask timeou
Alexander Semashko
2016/02/19 23:38:59
Why not? Anyway, I could'n conceive a better (yet
samuong
2016/02/20 00:11:44
If the outer and inner timeouts have the same dura
Alexander Semashko
2016/02/20 00:38:40
Yeah, it is, only if they have the same duration.
samuong
2016/02/22 23:55:35
OK, it's fine if this is the same for now but you
| |
273 std::string url; | 283 std::string url; |
274 if (!params.GetString("url", &url)) | 284 if (!params.GetString("url", &url)) |
275 return Status(kUnknownError, "'url' must be a string"); | 285 return Status(kUnknownError, "'url' must be a string"); |
276 Status status = web_view->Load(url); | 286 Status status = web_view->Load(url, timeout); |
277 if (status.IsError()) | 287 if (status.IsError()) |
278 return status; | 288 return status; |
279 session->SwitchToTopFrame(); | 289 session->SwitchToTopFrame(); |
280 return Status(kOk); | 290 return Status(kOk); |
281 } | 291 } |
282 | 292 |
283 Status ExecuteExecuteScript( | 293 Status ExecuteExecuteScript( |
284 Session* session, | 294 Session* session, |
285 WebView* web_view, | 295 WebView* web_view, |
286 const base::DictionaryValue& params, | 296 const base::DictionaryValue& params, |
287 scoped_ptr<base::Value>* value) { | 297 scoped_ptr<base::Value>* value, |
298 Timeout* timeout) { | |
288 std::string script; | 299 std::string script; |
289 if (!params.GetString("script", &script)) | 300 if (!params.GetString("script", &script)) |
290 return Status(kUnknownError, "'script' must be a string"); | 301 return Status(kUnknownError, "'script' must be a string"); |
291 if (script == ":takeHeapSnapshot") { | 302 if (script == ":takeHeapSnapshot") { |
292 return web_view->TakeHeapSnapshot(value); | 303 return web_view->TakeHeapSnapshot(value); |
293 } else if (script == ":startProfile") { | 304 } else if (script == ":startProfile") { |
294 return web_view->StartProfile(); | 305 return web_view->StartProfile(); |
295 } else if (script == ":endProfile") { | 306 } else if (script == ":endProfile") { |
296 return web_view->EndProfile(value); | 307 return web_view->EndProfile(value); |
297 } else { | 308 } else { |
298 const base::ListValue* args; | 309 const base::ListValue* args; |
299 if (!params.GetList("args", &args)) | 310 if (!params.GetList("args", &args)) |
300 return Status(kUnknownError, "'args' must be a list"); | 311 return Status(kUnknownError, "'args' must be a list"); |
301 | 312 |
302 return web_view->CallFunction(session->GetCurrentFrameId(), | 313 return web_view->CallFunction(session->GetCurrentFrameId(), |
303 "function(){" + script + "}", *args, value); | 314 "function(){" + script + "}", *args, value); |
304 } | 315 } |
305 } | 316 } |
306 | 317 |
307 Status ExecuteExecuteAsyncScript( | 318 Status ExecuteExecuteAsyncScript( |
308 Session* session, | 319 Session* session, |
309 WebView* web_view, | 320 WebView* web_view, |
310 const base::DictionaryValue& params, | 321 const base::DictionaryValue& params, |
311 scoped_ptr<base::Value>* value) { | 322 scoped_ptr<base::Value>* value, |
323 Timeout* timeout) { | |
312 std::string script; | 324 std::string script; |
313 if (!params.GetString("script", &script)) | 325 if (!params.GetString("script", &script)) |
314 return Status(kUnknownError, "'script' must be a string"); | 326 return Status(kUnknownError, "'script' must be a string"); |
315 const base::ListValue* args; | 327 const base::ListValue* args; |
316 if (!params.GetList("args", &args)) | 328 if (!params.GetList("args", &args)) |
317 return Status(kUnknownError, "'args' must be a list"); | 329 return Status(kUnknownError, "'args' must be a list"); |
318 | 330 |
319 return web_view->CallUserAsyncFunction( | 331 return web_view->CallUserAsyncFunction( |
320 session->GetCurrentFrameId(), "function(){" + script + "}", *args, | 332 session->GetCurrentFrameId(), "function(){" + script + "}", *args, |
321 session->script_timeout, value); | 333 session->script_timeout, value); |
322 } | 334 } |
323 | 335 |
324 Status ExecuteSwitchToFrame( | 336 Status ExecuteSwitchToFrame( |
325 Session* session, | 337 Session* session, |
326 WebView* web_view, | 338 WebView* web_view, |
327 const base::DictionaryValue& params, | 339 const base::DictionaryValue& params, |
328 scoped_ptr<base::Value>* value) { | 340 scoped_ptr<base::Value>* value, |
341 Timeout* timeout) { | |
329 const base::Value* id; | 342 const base::Value* id; |
330 if (!params.Get("id", &id)) | 343 if (!params.Get("id", &id)) |
331 return Status(kUnknownError, "missing 'id'"); | 344 return Status(kUnknownError, "missing 'id'"); |
332 | 345 |
333 if (id->IsType(base::Value::TYPE_NULL)) { | 346 if (id->IsType(base::Value::TYPE_NULL)) { |
334 session->SwitchToTopFrame(); | 347 session->SwitchToTopFrame(); |
335 return Status(kOk); | 348 return Status(kOk); |
336 } | 349 } |
337 | 350 |
338 std::string script; | 351 std::string script; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 if (status.IsError()) | 402 if (status.IsError()) |
390 return status; | 403 return status; |
391 session->SwitchToSubFrame(frame, chrome_driver_id); | 404 session->SwitchToSubFrame(frame, chrome_driver_id); |
392 return Status(kOk); | 405 return Status(kOk); |
393 } | 406 } |
394 | 407 |
395 Status ExecuteSwitchToParentFrame( | 408 Status ExecuteSwitchToParentFrame( |
396 Session* session, | 409 Session* session, |
397 WebView* web_view, | 410 WebView* web_view, |
398 const base::DictionaryValue& params, | 411 const base::DictionaryValue& params, |
399 scoped_ptr<base::Value>* value) { | 412 scoped_ptr<base::Value>* value, |
413 Timeout* timeout) { | |
400 session->SwitchToParentFrame(); | 414 session->SwitchToParentFrame(); |
401 return Status(kOk); | 415 return Status(kOk); |
402 } | 416 } |
403 | 417 |
404 Status ExecuteGetTitle( | 418 Status ExecuteGetTitle( |
405 Session* session, | 419 Session* session, |
406 WebView* web_view, | 420 WebView* web_view, |
407 const base::DictionaryValue& params, | 421 const base::DictionaryValue& params, |
408 scoped_ptr<base::Value>* value) { | 422 scoped_ptr<base::Value>* value, |
423 Timeout* timeout) { | |
409 const char kGetTitleScript[] = "function() { return document.title;}"; | 424 const char kGetTitleScript[] = "function() { return document.title;}"; |
410 base::ListValue args; | 425 base::ListValue args; |
411 return web_view->CallFunction(std::string(), kGetTitleScript, args, value); | 426 return web_view->CallFunction(std::string(), kGetTitleScript, args, value); |
412 } | 427 } |
413 | 428 |
414 Status ExecuteGetPageSource( | 429 Status ExecuteGetPageSource( |
415 Session* session, | 430 Session* session, |
416 WebView* web_view, | 431 WebView* web_view, |
417 const base::DictionaryValue& params, | 432 const base::DictionaryValue& params, |
418 scoped_ptr<base::Value>* value) { | 433 scoped_ptr<base::Value>* value, |
434 Timeout* timeout) { | |
419 const char kGetPageSource[] = | 435 const char kGetPageSource[] = |
420 "function() {" | 436 "function() {" |
421 " return new XMLSerializer().serializeToString(document);" | 437 " return new XMLSerializer().serializeToString(document);" |
422 "}"; | 438 "}"; |
423 base::ListValue args; | 439 base::ListValue args; |
424 return web_view->CallFunction( | 440 return web_view->CallFunction( |
425 session->GetCurrentFrameId(), kGetPageSource, args, value); | 441 session->GetCurrentFrameId(), kGetPageSource, args, value); |
426 } | 442 } |
427 | 443 |
428 Status ExecuteFindElement( | 444 Status ExecuteFindElement( |
429 int interval_ms, | 445 int interval_ms, |
430 Session* session, | 446 Session* session, |
431 WebView* web_view, | 447 WebView* web_view, |
432 const base::DictionaryValue& params, | 448 const base::DictionaryValue& params, |
433 scoped_ptr<base::Value>* value) { | 449 scoped_ptr<base::Value>* value, |
450 Timeout* timeout) { | |
434 return FindElement(interval_ms, true, NULL, session, web_view, params, value); | 451 return FindElement(interval_ms, true, NULL, session, web_view, params, value); |
435 } | 452 } |
436 | 453 |
437 Status ExecuteFindElements( | 454 Status ExecuteFindElements( |
438 int interval_ms, | 455 int interval_ms, |
439 Session* session, | 456 Session* session, |
440 WebView* web_view, | 457 WebView* web_view, |
441 const base::DictionaryValue& params, | 458 const base::DictionaryValue& params, |
442 scoped_ptr<base::Value>* value) { | 459 scoped_ptr<base::Value>* value, |
460 Timeout* timeout) { | |
443 return FindElement( | 461 return FindElement( |
444 interval_ms, false, NULL, session, web_view, params, value); | 462 interval_ms, false, NULL, session, web_view, params, value); |
445 } | 463 } |
446 | 464 |
447 Status ExecuteGetCurrentUrl( | 465 Status ExecuteGetCurrentUrl( |
448 Session* session, | 466 Session* session, |
449 WebView* web_view, | 467 WebView* web_view, |
450 const base::DictionaryValue& params, | 468 const base::DictionaryValue& params, |
451 scoped_ptr<base::Value>* value) { | 469 scoped_ptr<base::Value>* value, |
470 Timeout* timeout) { | |
452 std::string url; | 471 std::string url; |
453 Status status = GetUrl(web_view, std::string(), &url); | 472 Status status = GetUrl(web_view, std::string(), &url); |
454 if (status.IsError()) | 473 if (status.IsError()) |
455 return status; | 474 return status; |
456 if (url == kUnreachableWebDataURL) { | 475 if (url == kUnreachableWebDataURL) { |
457 // https://bugs.chromium.org/p/chromedriver/issues/detail?id=1272 | 476 // https://bugs.chromium.org/p/chromedriver/issues/detail?id=1272 |
458 const BrowserInfo* browser_info = session->chrome->GetBrowserInfo(); | 477 const BrowserInfo* browser_info = session->chrome->GetBrowserInfo(); |
459 bool is_kitkat_webview = browser_info->browser_name == "webview" && | 478 bool is_kitkat_webview = browser_info->browser_name == "webview" && |
460 browser_info->major_version <= 30 && | 479 browser_info->major_version <= 30 && |
461 browser_info->is_android; | 480 browser_info->is_android; |
(...skipping 14 matching lines...) Expand all Loading... | |
476 "for details and workarounds."; | 495 "for details and workarounds."; |
477 } | 496 } |
478 value->reset(new base::StringValue(url)); | 497 value->reset(new base::StringValue(url)); |
479 return Status(kOk); | 498 return Status(kOk); |
480 } | 499 } |
481 | 500 |
482 Status ExecuteGoBack( | 501 Status ExecuteGoBack( |
483 Session* session, | 502 Session* session, |
484 WebView* web_view, | 503 WebView* web_view, |
485 const base::DictionaryValue& params, | 504 const base::DictionaryValue& params, |
486 scoped_ptr<base::Value>* value) { | 505 scoped_ptr<base::Value>* value, |
506 Timeout* timeout) { | |
487 Status status = web_view->TraverseHistory(-1); | 507 Status status = web_view->TraverseHistory(-1); |
488 if (status.IsError()) | 508 if (status.IsError()) |
489 return status; | 509 return status; |
490 session->SwitchToTopFrame(); | 510 session->SwitchToTopFrame(); |
491 return Status(kOk); | 511 return Status(kOk); |
492 } | 512 } |
493 | 513 |
494 Status ExecuteGoForward( | 514 Status ExecuteGoForward( |
495 Session* session, | 515 Session* session, |
496 WebView* web_view, | 516 WebView* web_view, |
497 const base::DictionaryValue& params, | 517 const base::DictionaryValue& params, |
498 scoped_ptr<base::Value>* value) { | 518 scoped_ptr<base::Value>* value, |
519 Timeout* timeout) { | |
499 Status status = web_view->TraverseHistory(1); | 520 Status status = web_view->TraverseHistory(1); |
500 if (status.IsError()) | 521 if (status.IsError()) |
501 return status; | 522 return status; |
502 session->SwitchToTopFrame(); | 523 session->SwitchToTopFrame(); |
503 return Status(kOk); | 524 return Status(kOk); |
504 } | 525 } |
505 | 526 |
506 Status ExecuteRefresh( | 527 Status ExecuteRefresh( |
507 Session* session, | 528 Session* session, |
508 WebView* web_view, | 529 WebView* web_view, |
509 const base::DictionaryValue& params, | 530 const base::DictionaryValue& params, |
510 scoped_ptr<base::Value>* value) { | 531 scoped_ptr<base::Value>* value, |
532 Timeout* timeout) { | |
511 Status status = web_view->Reload(); | 533 Status status = web_view->Reload(); |
512 if (status.IsError()) | 534 if (status.IsError()) |
513 return status; | 535 return status; |
514 session->SwitchToTopFrame(); | 536 session->SwitchToTopFrame(); |
515 return Status(kOk); | 537 return Status(kOk); |
516 } | 538 } |
517 | 539 |
518 Status ExecuteMouseMoveTo( | 540 Status ExecuteMouseMoveTo( |
519 Session* session, | 541 Session* session, |
520 WebView* web_view, | 542 WebView* web_view, |
521 const base::DictionaryValue& params, | 543 const base::DictionaryValue& params, |
522 scoped_ptr<base::Value>* value) { | 544 scoped_ptr<base::Value>* value, |
545 Timeout* timeout) { | |
523 std::string element_id; | 546 std::string element_id; |
524 bool has_element = params.GetString("element", &element_id); | 547 bool has_element = params.GetString("element", &element_id); |
525 int x_offset = 0; | 548 int x_offset = 0; |
526 int y_offset = 0; | 549 int y_offset = 0; |
527 bool has_offset = params.GetInteger("xoffset", &x_offset) && | 550 bool has_offset = params.GetInteger("xoffset", &x_offset) && |
528 params.GetInteger("yoffset", &y_offset); | 551 params.GetInteger("yoffset", &y_offset); |
529 if (!has_element && !has_offset) | 552 if (!has_element && !has_offset) |
530 return Status(kUnknownError, "at least an element or offset should be set"); | 553 return Status(kUnknownError, "at least an element or offset should be set"); |
531 | 554 |
532 WebPoint location; | 555 WebPoint location; |
(...skipping 17 matching lines...) Expand all Loading... | |
550 web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 573 web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
551 if (status.IsOk()) | 574 if (status.IsOk()) |
552 session->mouse_position = location; | 575 session->mouse_position = location; |
553 return status; | 576 return status; |
554 } | 577 } |
555 | 578 |
556 Status ExecuteMouseClick( | 579 Status ExecuteMouseClick( |
557 Session* session, | 580 Session* session, |
558 WebView* web_view, | 581 WebView* web_view, |
559 const base::DictionaryValue& params, | 582 const base::DictionaryValue& params, |
560 scoped_ptr<base::Value>* value) { | 583 scoped_ptr<base::Value>* value, |
584 Timeout* timeout) { | |
561 MouseButton button; | 585 MouseButton button; |
562 Status status = GetMouseButton(params, &button); | 586 Status status = GetMouseButton(params, &button); |
563 if (status.IsError()) | 587 if (status.IsError()) |
564 return status; | 588 return status; |
565 std::list<MouseEvent> events; | 589 std::list<MouseEvent> events; |
566 events.push_back( | 590 events.push_back( |
567 MouseEvent(kPressedMouseEventType, button, | 591 MouseEvent(kPressedMouseEventType, button, |
568 session->mouse_position.x, session->mouse_position.y, | 592 session->mouse_position.x, session->mouse_position.y, |
569 session->sticky_modifiers, 1)); | 593 session->sticky_modifiers, 1)); |
570 events.push_back( | 594 events.push_back( |
571 MouseEvent(kReleasedMouseEventType, button, | 595 MouseEvent(kReleasedMouseEventType, button, |
572 session->mouse_position.x, session->mouse_position.y, | 596 session->mouse_position.x, session->mouse_position.y, |
573 session->sticky_modifiers, 1)); | 597 session->sticky_modifiers, 1)); |
574 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 598 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
575 } | 599 } |
576 | 600 |
577 Status ExecuteMouseButtonDown( | 601 Status ExecuteMouseButtonDown( |
578 Session* session, | 602 Session* session, |
579 WebView* web_view, | 603 WebView* web_view, |
580 const base::DictionaryValue& params, | 604 const base::DictionaryValue& params, |
581 scoped_ptr<base::Value>* value) { | 605 scoped_ptr<base::Value>* value, |
606 Timeout* timeout) { | |
582 MouseButton button; | 607 MouseButton button; |
583 Status status = GetMouseButton(params, &button); | 608 Status status = GetMouseButton(params, &button); |
584 if (status.IsError()) | 609 if (status.IsError()) |
585 return status; | 610 return status; |
586 std::list<MouseEvent> events; | 611 std::list<MouseEvent> events; |
587 events.push_back( | 612 events.push_back( |
588 MouseEvent(kPressedMouseEventType, button, | 613 MouseEvent(kPressedMouseEventType, button, |
589 session->mouse_position.x, session->mouse_position.y, | 614 session->mouse_position.x, session->mouse_position.y, |
590 session->sticky_modifiers, 1)); | 615 session->sticky_modifiers, 1)); |
591 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 616 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
592 } | 617 } |
593 | 618 |
594 Status ExecuteMouseButtonUp( | 619 Status ExecuteMouseButtonUp( |
595 Session* session, | 620 Session* session, |
596 WebView* web_view, | 621 WebView* web_view, |
597 const base::DictionaryValue& params, | 622 const base::DictionaryValue& params, |
598 scoped_ptr<base::Value>* value) { | 623 scoped_ptr<base::Value>* value, |
624 Timeout* timeout) { | |
599 MouseButton button; | 625 MouseButton button; |
600 Status status = GetMouseButton(params, &button); | 626 Status status = GetMouseButton(params, &button); |
601 if (status.IsError()) | 627 if (status.IsError()) |
602 return status; | 628 return status; |
603 std::list<MouseEvent> events; | 629 std::list<MouseEvent> events; |
604 events.push_back( | 630 events.push_back( |
605 MouseEvent(kReleasedMouseEventType, button, | 631 MouseEvent(kReleasedMouseEventType, button, |
606 session->mouse_position.x, session->mouse_position.y, | 632 session->mouse_position.x, session->mouse_position.y, |
607 session->sticky_modifiers, 1)); | 633 session->sticky_modifiers, 1)); |
608 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 634 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
609 } | 635 } |
610 | 636 |
611 Status ExecuteMouseDoubleClick( | 637 Status ExecuteMouseDoubleClick( |
612 Session* session, | 638 Session* session, |
613 WebView* web_view, | 639 WebView* web_view, |
614 const base::DictionaryValue& params, | 640 const base::DictionaryValue& params, |
615 scoped_ptr<base::Value>* value) { | 641 scoped_ptr<base::Value>* value, |
642 Timeout* timeout) { | |
616 MouseButton button; | 643 MouseButton button; |
617 Status status = GetMouseButton(params, &button); | 644 Status status = GetMouseButton(params, &button); |
618 if (status.IsError()) | 645 if (status.IsError()) |
619 return status; | 646 return status; |
620 std::list<MouseEvent> events; | 647 std::list<MouseEvent> events; |
621 events.push_back( | 648 events.push_back( |
622 MouseEvent(kPressedMouseEventType, button, | 649 MouseEvent(kPressedMouseEventType, button, |
623 session->mouse_position.x, session->mouse_position.y, | 650 session->mouse_position.x, session->mouse_position.y, |
624 session->sticky_modifiers, 2)); | 651 session->sticky_modifiers, 2)); |
625 events.push_back( | 652 events.push_back( |
626 MouseEvent(kReleasedMouseEventType, button, | 653 MouseEvent(kReleasedMouseEventType, button, |
627 session->mouse_position.x, session->mouse_position.y, | 654 session->mouse_position.x, session->mouse_position.y, |
628 session->sticky_modifiers, 2)); | 655 session->sticky_modifiers, 2)); |
629 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 656 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
630 } | 657 } |
631 | 658 |
632 Status ExecuteTouchDown( | 659 Status ExecuteTouchDown( |
633 Session* session, | 660 Session* session, |
634 WebView* web_view, | 661 WebView* web_view, |
635 const base::DictionaryValue& params, | 662 const base::DictionaryValue& params, |
636 scoped_ptr<base::Value>* value) { | 663 scoped_ptr<base::Value>* value, |
664 Timeout* timeout) { | |
637 return ExecuteTouchEvent(session, web_view, kTouchStart, params); | 665 return ExecuteTouchEvent(session, web_view, kTouchStart, params); |
638 } | 666 } |
639 | 667 |
640 Status ExecuteTouchUp( | 668 Status ExecuteTouchUp( |
641 Session* session, | 669 Session* session, |
642 WebView* web_view, | 670 WebView* web_view, |
643 const base::DictionaryValue& params, | 671 const base::DictionaryValue& params, |
644 scoped_ptr<base::Value>* value) { | 672 scoped_ptr<base::Value>* value, |
673 Timeout* timeout) { | |
645 return ExecuteTouchEvent(session, web_view, kTouchEnd, params); | 674 return ExecuteTouchEvent(session, web_view, kTouchEnd, params); |
646 } | 675 } |
647 | 676 |
648 Status ExecuteTouchMove( | 677 Status ExecuteTouchMove( |
649 Session* session, | 678 Session* session, |
650 WebView* web_view, | 679 WebView* web_view, |
651 const base::DictionaryValue& params, | 680 const base::DictionaryValue& params, |
652 scoped_ptr<base::Value>* value) { | 681 scoped_ptr<base::Value>* value, |
682 Timeout* timeout) { | |
653 return ExecuteTouchEvent(session, web_view, kTouchMove, params); | 683 return ExecuteTouchEvent(session, web_view, kTouchMove, params); |
654 } | 684 } |
655 | 685 |
656 Status ExecuteTouchScroll( | 686 Status ExecuteTouchScroll( |
657 Session *session, | 687 Session *session, |
658 WebView* web_view, | 688 WebView* web_view, |
659 const base::DictionaryValue& params, | 689 const base::DictionaryValue& params, |
660 scoped_ptr<base::Value>* value) { | 690 scoped_ptr<base::Value>* value, |
691 Timeout* timeout) { | |
661 if (session->chrome->GetBrowserInfo()->build_no < 2286) { | 692 if (session->chrome->GetBrowserInfo()->build_no < 2286) { |
662 // TODO(samuong): remove this once we stop supporting M41. | 693 // TODO(samuong): remove this once we stop supporting M41. |
663 return Status(kUnknownCommand, "Touch scroll action requires Chrome 42+"); | 694 return Status(kUnknownCommand, "Touch scroll action requires Chrome 42+"); |
664 } | 695 } |
665 WebPoint location = session->mouse_position; | 696 WebPoint location = session->mouse_position; |
666 std::string element; | 697 std::string element; |
667 if (params.GetString("element", &element)) { | 698 if (params.GetString("element", &element)) { |
668 Status status = GetElementClickableLocation( | 699 Status status = GetElementClickableLocation( |
669 session, web_view, element, &location); | 700 session, web_view, element, &location); |
670 if (status.IsError()) | 701 if (status.IsError()) |
671 return status; | 702 return status; |
672 } | 703 } |
673 int xoffset; | 704 int xoffset; |
674 if (!params.GetInteger("xoffset", &xoffset)) | 705 if (!params.GetInteger("xoffset", &xoffset)) |
675 return Status(kUnknownError, "'xoffset' must be an integer"); | 706 return Status(kUnknownError, "'xoffset' must be an integer"); |
676 int yoffset; | 707 int yoffset; |
677 if (!params.GetInteger("yoffset", &yoffset)) | 708 if (!params.GetInteger("yoffset", &yoffset)) |
678 return Status(kUnknownError, "'yoffset' must be an integer"); | 709 return Status(kUnknownError, "'yoffset' must be an integer"); |
679 return web_view->SynthesizeScrollGesture( | 710 return web_view->SynthesizeScrollGesture( |
680 location.x, location.y, xoffset, yoffset); | 711 location.x, location.y, xoffset, yoffset); |
681 } | 712 } |
682 | 713 |
683 Status ExecuteTouchPinch( | 714 Status ExecuteTouchPinch( |
684 Session* session, | 715 Session* session, |
685 WebView* web_view, | 716 WebView* web_view, |
686 const base::DictionaryValue& params, | 717 const base::DictionaryValue& params, |
687 scoped_ptr<base::Value>* value) { | 718 scoped_ptr<base::Value>* value, |
719 Timeout* timeout) { | |
688 if (session->chrome->GetBrowserInfo()->build_no < 2286) { | 720 if (session->chrome->GetBrowserInfo()->build_no < 2286) { |
689 // TODO(samuong): remove this once we stop supporting M41. | 721 // TODO(samuong): remove this once we stop supporting M41. |
690 return Status(kUnknownCommand, "Pinch action requires Chrome 42+"); | 722 return Status(kUnknownCommand, "Pinch action requires Chrome 42+"); |
691 } | 723 } |
692 WebPoint location; | 724 WebPoint location; |
693 if (!params.GetInteger("x", &location.x)) | 725 if (!params.GetInteger("x", &location.x)) |
694 return Status(kUnknownError, "'x' must be an integer"); | 726 return Status(kUnknownError, "'x' must be an integer"); |
695 if (!params.GetInteger("y", &location.y)) | 727 if (!params.GetInteger("y", &location.y)) |
696 return Status(kUnknownError, "'y' must be an integer"); | 728 return Status(kUnknownError, "'y' must be an integer"); |
697 double scale_factor; | 729 double scale_factor; |
698 if (!params.GetDouble("scale", &scale_factor)) | 730 if (!params.GetDouble("scale", &scale_factor)) |
699 return Status(kUnknownError, "'scale' must be an integer"); | 731 return Status(kUnknownError, "'scale' must be an integer"); |
700 return web_view->SynthesizePinchGesture(location.x, location.y, scale_factor); | 732 return web_view->SynthesizePinchGesture(location.x, location.y, scale_factor); |
701 } | 733 } |
702 | 734 |
703 Status ExecuteGetActiveElement( | 735 Status ExecuteGetActiveElement( |
704 Session* session, | 736 Session* session, |
705 WebView* web_view, | 737 WebView* web_view, |
706 const base::DictionaryValue& params, | 738 const base::DictionaryValue& params, |
707 scoped_ptr<base::Value>* value) { | 739 scoped_ptr<base::Value>* value, |
740 Timeout* timeout) { | |
708 return GetActiveElement(session, web_view, value); | 741 return GetActiveElement(session, web_view, value); |
709 } | 742 } |
710 | 743 |
711 Status ExecuteSendKeysToActiveElement( | 744 Status ExecuteSendKeysToActiveElement( |
712 Session* session, | 745 Session* session, |
713 WebView* web_view, | 746 WebView* web_view, |
714 const base::DictionaryValue& params, | 747 const base::DictionaryValue& params, |
715 scoped_ptr<base::Value>* value) { | 748 scoped_ptr<base::Value>* value, |
749 Timeout* timeout) { | |
716 const base::ListValue* key_list; | 750 const base::ListValue* key_list; |
717 if (!params.GetList("value", &key_list)) | 751 if (!params.GetList("value", &key_list)) |
718 return Status(kUnknownError, "'value' must be a list"); | 752 return Status(kUnknownError, "'value' must be a list"); |
719 return SendKeysOnWindow( | 753 return SendKeysOnWindow( |
720 web_view, key_list, false, &session->sticky_modifiers); | 754 web_view, key_list, false, &session->sticky_modifiers); |
721 } | 755 } |
722 | 756 |
723 Status ExecuteGetAppCacheStatus( | 757 Status ExecuteGetAppCacheStatus( |
724 Session* session, | 758 Session* session, |
725 WebView* web_view, | 759 WebView* web_view, |
726 const base::DictionaryValue& params, | 760 const base::DictionaryValue& params, |
727 scoped_ptr<base::Value>* value) { | 761 scoped_ptr<base::Value>* value, |
762 Timeout* timeout) { | |
728 return web_view->EvaluateScript( | 763 return web_view->EvaluateScript( |
729 session->GetCurrentFrameId(), | 764 session->GetCurrentFrameId(), |
730 "applicationCache.status", | 765 "applicationCache.status", |
731 value); | 766 value); |
732 } | 767 } |
733 | 768 |
734 Status ExecuteIsBrowserOnline( | 769 Status ExecuteIsBrowserOnline( |
735 Session* session, | 770 Session* session, |
736 WebView* web_view, | 771 WebView* web_view, |
737 const base::DictionaryValue& params, | 772 const base::DictionaryValue& params, |
738 scoped_ptr<base::Value>* value) { | 773 scoped_ptr<base::Value>* value, |
774 Timeout* timeout) { | |
739 return web_view->EvaluateScript( | 775 return web_view->EvaluateScript( |
740 session->GetCurrentFrameId(), | 776 session->GetCurrentFrameId(), |
741 "navigator.onLine", | 777 "navigator.onLine", |
742 value); | 778 value); |
743 } | 779 } |
744 | 780 |
745 Status ExecuteGetStorageItem( | 781 Status ExecuteGetStorageItem( |
746 const char* storage, | 782 const char* storage, |
747 Session* session, | 783 Session* session, |
748 WebView* web_view, | 784 WebView* web_view, |
749 const base::DictionaryValue& params, | 785 const base::DictionaryValue& params, |
750 scoped_ptr<base::Value>* value) { | 786 scoped_ptr<base::Value>* value, |
787 Timeout* timeout) { | |
751 std::string key; | 788 std::string key; |
752 if (!params.GetString("key", &key)) | 789 if (!params.GetString("key", &key)) |
753 return Status(kUnknownError, "'key' must be a string"); | 790 return Status(kUnknownError, "'key' must be a string"); |
754 base::ListValue args; | 791 base::ListValue args; |
755 args.Append(new base::StringValue(key)); | 792 args.Append(new base::StringValue(key)); |
756 return web_view->CallFunction( | 793 return web_view->CallFunction( |
757 session->GetCurrentFrameId(), | 794 session->GetCurrentFrameId(), |
758 base::StringPrintf("function(key) { return %s[key]; }", storage), | 795 base::StringPrintf("function(key) { return %s[key]; }", storage), |
759 args, | 796 args, |
760 value); | 797 value); |
761 } | 798 } |
762 | 799 |
763 Status ExecuteGetStorageKeys( | 800 Status ExecuteGetStorageKeys( |
764 const char* storage, | 801 const char* storage, |
765 Session* session, | 802 Session* session, |
766 WebView* web_view, | 803 WebView* web_view, |
767 const base::DictionaryValue& params, | 804 const base::DictionaryValue& params, |
768 scoped_ptr<base::Value>* value) { | 805 scoped_ptr<base::Value>* value, |
806 Timeout* timeout) { | |
769 const char script[] = | 807 const char script[] = |
770 "var keys = [];" | 808 "var keys = [];" |
771 "for (var key in %s) {" | 809 "for (var key in %s) {" |
772 " keys.push(key);" | 810 " keys.push(key);" |
773 "}" | 811 "}" |
774 "keys"; | 812 "keys"; |
775 return web_view->EvaluateScript( | 813 return web_view->EvaluateScript( |
776 session->GetCurrentFrameId(), | 814 session->GetCurrentFrameId(), |
777 base::StringPrintf(script, storage), | 815 base::StringPrintf(script, storage), |
778 value); | 816 value); |
779 } | 817 } |
780 | 818 |
781 Status ExecuteSetStorageItem( | 819 Status ExecuteSetStorageItem( |
782 const char* storage, | 820 const char* storage, |
783 Session* session, | 821 Session* session, |
784 WebView* web_view, | 822 WebView* web_view, |
785 const base::DictionaryValue& params, | 823 const base::DictionaryValue& params, |
786 scoped_ptr<base::Value>* value) { | 824 scoped_ptr<base::Value>* value, |
825 Timeout* timeout) { | |
787 std::string key; | 826 std::string key; |
788 if (!params.GetString("key", &key)) | 827 if (!params.GetString("key", &key)) |
789 return Status(kUnknownError, "'key' must be a string"); | 828 return Status(kUnknownError, "'key' must be a string"); |
790 std::string storage_value; | 829 std::string storage_value; |
791 if (!params.GetString("value", &storage_value)) | 830 if (!params.GetString("value", &storage_value)) |
792 return Status(kUnknownError, "'value' must be a string"); | 831 return Status(kUnknownError, "'value' must be a string"); |
793 base::ListValue args; | 832 base::ListValue args; |
794 args.Append(new base::StringValue(key)); | 833 args.Append(new base::StringValue(key)); |
795 args.Append(new base::StringValue(storage_value)); | 834 args.Append(new base::StringValue(storage_value)); |
796 return web_view->CallFunction( | 835 return web_view->CallFunction( |
797 session->GetCurrentFrameId(), | 836 session->GetCurrentFrameId(), |
798 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), | 837 base::StringPrintf("function(key, value) { %s[key] = value; }", storage), |
799 args, | 838 args, |
800 value); | 839 value); |
801 } | 840 } |
802 | 841 |
803 Status ExecuteRemoveStorageItem( | 842 Status ExecuteRemoveStorageItem( |
804 const char* storage, | 843 const char* storage, |
805 Session* session, | 844 Session* session, |
806 WebView* web_view, | 845 WebView* web_view, |
807 const base::DictionaryValue& params, | 846 const base::DictionaryValue& params, |
808 scoped_ptr<base::Value>* value) { | 847 scoped_ptr<base::Value>* value, |
848 Timeout* timeout) { | |
809 std::string key; | 849 std::string key; |
810 if (!params.GetString("key", &key)) | 850 if (!params.GetString("key", &key)) |
811 return Status(kUnknownError, "'key' must be a string"); | 851 return Status(kUnknownError, "'key' must be a string"); |
812 base::ListValue args; | 852 base::ListValue args; |
813 args.Append(new base::StringValue(key)); | 853 args.Append(new base::StringValue(key)); |
814 return web_view->CallFunction( | 854 return web_view->CallFunction( |
815 session->GetCurrentFrameId(), | 855 session->GetCurrentFrameId(), |
816 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), | 856 base::StringPrintf("function(key) { %s.removeItem(key) }", storage), |
817 args, | 857 args, |
818 value); | 858 value); |
819 } | 859 } |
820 | 860 |
821 Status ExecuteClearStorage( | 861 Status ExecuteClearStorage( |
822 const char* storage, | 862 const char* storage, |
823 Session* session, | 863 Session* session, |
824 WebView* web_view, | 864 WebView* web_view, |
825 const base::DictionaryValue& params, | 865 const base::DictionaryValue& params, |
826 scoped_ptr<base::Value>* value) { | 866 scoped_ptr<base::Value>* value, |
867 Timeout* timeout) { | |
827 return web_view->EvaluateScript( | 868 return web_view->EvaluateScript( |
828 session->GetCurrentFrameId(), | 869 session->GetCurrentFrameId(), |
829 base::StringPrintf("%s.clear()", storage), | 870 base::StringPrintf("%s.clear()", storage), |
830 value); | 871 value); |
831 } | 872 } |
832 | 873 |
833 Status ExecuteGetStorageSize( | 874 Status ExecuteGetStorageSize( |
834 const char* storage, | 875 const char* storage, |
835 Session* session, | 876 Session* session, |
836 WebView* web_view, | 877 WebView* web_view, |
837 const base::DictionaryValue& params, | 878 const base::DictionaryValue& params, |
838 scoped_ptr<base::Value>* value) { | 879 scoped_ptr<base::Value>* value, |
880 Timeout* timeout) { | |
839 return web_view->EvaluateScript( | 881 return web_view->EvaluateScript( |
840 session->GetCurrentFrameId(), | 882 session->GetCurrentFrameId(), |
841 base::StringPrintf("%s.length", storage), | 883 base::StringPrintf("%s.length", storage), |
842 value); | 884 value); |
843 } | 885 } |
844 | 886 |
845 Status ExecuteScreenshot( | 887 Status ExecuteScreenshot( |
846 Session* session, | 888 Session* session, |
847 WebView* web_view, | 889 WebView* web_view, |
848 const base::DictionaryValue& params, | 890 const base::DictionaryValue& params, |
849 scoped_ptr<base::Value>* value) { | 891 scoped_ptr<base::Value>* value, |
892 Timeout* timeout) { | |
850 Status status = session->chrome->ActivateWebView(web_view->GetId()); | 893 Status status = session->chrome->ActivateWebView(web_view->GetId()); |
851 if (status.IsError()) | 894 if (status.IsError()) |
852 return status; | 895 return status; |
853 | 896 |
854 std::string screenshot; | 897 std::string screenshot; |
855 ChromeDesktopImpl* desktop = NULL; | 898 ChromeDesktopImpl* desktop = NULL; |
856 status = session->chrome->GetAsDesktop(&desktop); | 899 status = session->chrome->GetAsDesktop(&desktop); |
857 if (status.IsOk() && !session->force_devtools_screenshot) { | 900 if (status.IsOk() && !session->force_devtools_screenshot) { |
858 AutomationExtension* extension = NULL; | 901 AutomationExtension* extension = NULL; |
859 status = desktop->GetAutomationExtension(&extension); | 902 status = desktop->GetAutomationExtension(&extension); |
(...skipping 11 matching lines...) Expand all Loading... | |
871 return status; | 914 return status; |
872 | 915 |
873 value->reset(new base::StringValue(screenshot)); | 916 value->reset(new base::StringValue(screenshot)); |
874 return Status(kOk); | 917 return Status(kOk); |
875 } | 918 } |
876 | 919 |
877 Status ExecuteGetCookies( | 920 Status ExecuteGetCookies( |
878 Session* session, | 921 Session* session, |
879 WebView* web_view, | 922 WebView* web_view, |
880 const base::DictionaryValue& params, | 923 const base::DictionaryValue& params, |
881 scoped_ptr<base::Value>* value) { | 924 scoped_ptr<base::Value>* value, |
925 Timeout* timeout) { | |
882 std::list<Cookie> cookies; | 926 std::list<Cookie> cookies; |
883 Status status = GetVisibleCookies(web_view, &cookies); | 927 Status status = GetVisibleCookies(web_view, &cookies); |
884 if (status.IsError()) | 928 if (status.IsError()) |
885 return status; | 929 return status; |
886 scoped_ptr<base::ListValue> cookie_list(new base::ListValue()); | 930 scoped_ptr<base::ListValue> cookie_list(new base::ListValue()); |
887 for (std::list<Cookie>::const_iterator it = cookies.begin(); | 931 for (std::list<Cookie>::const_iterator it = cookies.begin(); |
888 it != cookies.end(); ++it) { | 932 it != cookies.end(); ++it) { |
889 cookie_list->Append(CreateDictionaryFrom(*it)); | 933 cookie_list->Append(CreateDictionaryFrom(*it)); |
890 } | 934 } |
891 value->reset(cookie_list.release()); | 935 value->reset(cookie_list.release()); |
892 return Status(kOk); | 936 return Status(kOk); |
893 } | 937 } |
894 | 938 |
895 Status ExecuteAddCookie( | 939 Status ExecuteAddCookie( |
896 Session* session, | 940 Session* session, |
897 WebView* web_view, | 941 WebView* web_view, |
898 const base::DictionaryValue& params, | 942 const base::DictionaryValue& params, |
899 scoped_ptr<base::Value>* value) { | 943 scoped_ptr<base::Value>* value, |
944 Timeout* timeout) { | |
900 const base::DictionaryValue* cookie; | 945 const base::DictionaryValue* cookie; |
901 if (!params.GetDictionary("cookie", &cookie)) | 946 if (!params.GetDictionary("cookie", &cookie)) |
902 return Status(kUnknownError, "missing 'cookie'"); | 947 return Status(kUnknownError, "missing 'cookie'"); |
903 base::ListValue args; | 948 base::ListValue args; |
904 args.Append(cookie->DeepCopy()); | 949 args.Append(cookie->DeepCopy()); |
905 scoped_ptr<base::Value> result; | 950 scoped_ptr<base::Value> result; |
906 return web_view->CallFunction( | 951 return web_view->CallFunction( |
907 session->GetCurrentFrameId(), kAddCookieScript, args, &result); | 952 session->GetCurrentFrameId(), kAddCookieScript, args, &result); |
908 } | 953 } |
909 | 954 |
910 Status ExecuteDeleteCookie( | 955 Status ExecuteDeleteCookie( |
911 Session* session, | 956 Session* session, |
912 WebView* web_view, | 957 WebView* web_view, |
913 const base::DictionaryValue& params, | 958 const base::DictionaryValue& params, |
914 scoped_ptr<base::Value>* value) { | 959 scoped_ptr<base::Value>* value, |
960 Timeout* timeout) { | |
915 std::string name; | 961 std::string name; |
916 if (!params.GetString("name", &name)) | 962 if (!params.GetString("name", &name)) |
917 return Status(kUnknownError, "missing 'name'"); | 963 return Status(kUnknownError, "missing 'name'"); |
918 base::DictionaryValue params_url; | 964 base::DictionaryValue params_url; |
919 scoped_ptr<base::Value> value_url; | 965 scoped_ptr<base::Value> value_url; |
920 std::string url; | 966 std::string url; |
921 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); | 967 Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
922 if (status.IsError()) | 968 if (status.IsError()) |
923 return status; | 969 return status; |
924 return web_view->DeleteCookie(name, url); | 970 return web_view->DeleteCookie(name, url); |
925 } | 971 } |
926 | 972 |
927 Status ExecuteDeleteAllCookies( | 973 Status ExecuteDeleteAllCookies( |
928 Session* session, | 974 Session* session, |
929 WebView* web_view, | 975 WebView* web_view, |
930 const base::DictionaryValue& params, | 976 const base::DictionaryValue& params, |
931 scoped_ptr<base::Value>* value) { | 977 scoped_ptr<base::Value>* value, |
978 Timeout* timeout) { | |
932 std::list<Cookie> cookies; | 979 std::list<Cookie> cookies; |
933 Status status = GetVisibleCookies(web_view, &cookies); | 980 Status status = GetVisibleCookies(web_view, &cookies); |
934 if (status.IsError()) | 981 if (status.IsError()) |
935 return status; | 982 return status; |
936 | 983 |
937 if (!cookies.empty()) { | 984 if (!cookies.empty()) { |
938 base::DictionaryValue params_url; | 985 base::DictionaryValue params_url; |
939 scoped_ptr<base::Value> value_url; | 986 scoped_ptr<base::Value> value_url; |
940 std::string url; | 987 std::string url; |
941 status = GetUrl(web_view, session->GetCurrentFrameId(), &url); | 988 status = GetUrl(web_view, session->GetCurrentFrameId(), &url); |
942 if (status.IsError()) | 989 if (status.IsError()) |
943 return status; | 990 return status; |
944 for (std::list<Cookie>::const_iterator it = cookies.begin(); | 991 for (std::list<Cookie>::const_iterator it = cookies.begin(); |
945 it != cookies.end(); ++it) { | 992 it != cookies.end(); ++it) { |
946 status = web_view->DeleteCookie(it->name, url); | 993 status = web_view->DeleteCookie(it->name, url); |
947 if (status.IsError()) | 994 if (status.IsError()) |
948 return status; | 995 return status; |
949 } | 996 } |
950 } | 997 } |
951 | 998 |
952 return Status(kOk); | 999 return Status(kOk); |
953 } | 1000 } |
954 | 1001 |
955 Status ExecuteSetLocation( | 1002 Status ExecuteSetLocation( |
956 Session* session, | 1003 Session* session, |
957 WebView* web_view, | 1004 WebView* web_view, |
958 const base::DictionaryValue& params, | 1005 const base::DictionaryValue& params, |
959 scoped_ptr<base::Value>* value) { | 1006 scoped_ptr<base::Value>* value, |
1007 Timeout* timeout) { | |
960 const base::DictionaryValue* location = NULL; | 1008 const base::DictionaryValue* location = NULL; |
961 Geoposition geoposition; | 1009 Geoposition geoposition; |
962 if (!params.GetDictionary("location", &location) || | 1010 if (!params.GetDictionary("location", &location) || |
963 !location->GetDouble("latitude", &geoposition.latitude) || | 1011 !location->GetDouble("latitude", &geoposition.latitude) || |
964 !location->GetDouble("longitude", &geoposition.longitude)) | 1012 !location->GetDouble("longitude", &geoposition.longitude)) |
965 return Status(kUnknownError, "missing or invalid 'location'"); | 1013 return Status(kUnknownError, "missing or invalid 'location'"); |
966 if (location->HasKey("accuracy") && | 1014 if (location->HasKey("accuracy") && |
967 !location->GetDouble("accuracy", &geoposition.accuracy)) { | 1015 !location->GetDouble("accuracy", &geoposition.accuracy)) { |
968 return Status(kUnknownError, "invalid 'accuracy'"); | 1016 return Status(kUnknownError, "invalid 'accuracy'"); |
969 } else { | 1017 } else { |
970 // |accuracy| is not part of the WebDriver spec yet, so if it is not given | 1018 // |accuracy| is not part of the WebDriver spec yet, so if it is not given |
971 // default to 100 meters accuracy. | 1019 // default to 100 meters accuracy. |
972 geoposition.accuracy = 100; | 1020 geoposition.accuracy = 100; |
973 } | 1021 } |
974 | 1022 |
975 Status status = web_view->OverrideGeolocation(geoposition); | 1023 Status status = web_view->OverrideGeolocation(geoposition); |
976 if (status.IsOk()) | 1024 if (status.IsOk()) |
977 session->overridden_geoposition.reset(new Geoposition(geoposition)); | 1025 session->overridden_geoposition.reset(new Geoposition(geoposition)); |
978 return status; | 1026 return status; |
979 } | 1027 } |
980 | 1028 |
981 Status ExecuteSetNetworkConditions( | 1029 Status ExecuteSetNetworkConditions( |
982 Session* session, | 1030 Session* session, |
983 WebView* web_view, | 1031 WebView* web_view, |
984 const base::DictionaryValue& params, | 1032 const base::DictionaryValue& params, |
985 scoped_ptr<base::Value>* value) { | 1033 scoped_ptr<base::Value>* value, |
1034 Timeout* timeout) { | |
986 std::string network_name; | 1035 std::string network_name; |
987 const base::DictionaryValue* conditions = NULL; | 1036 const base::DictionaryValue* conditions = NULL; |
988 scoped_ptr<NetworkConditions> network_conditions(new NetworkConditions()); | 1037 scoped_ptr<NetworkConditions> network_conditions(new NetworkConditions()); |
989 if (params.GetString("network_name", &network_name)) { | 1038 if (params.GetString("network_name", &network_name)) { |
990 // Get conditions from preset list. | 1039 // Get conditions from preset list. |
991 Status status = FindPresetNetwork(network_name, network_conditions.get()); | 1040 Status status = FindPresetNetwork(network_name, network_conditions.get()); |
992 if (status.IsError()) | 1041 if (status.IsError()) |
993 return status; | 1042 return status; |
994 } else if (params.GetDictionary("network_conditions", &conditions)) { | 1043 } else if (params.GetDictionary("network_conditions", &conditions)) { |
995 // |latency| is required. | 1044 // |latency| is required. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 session->overridden_network_conditions.reset( | 1084 session->overridden_network_conditions.reset( |
1036 network_conditions.release()); | 1085 network_conditions.release()); |
1037 return web_view->OverrideNetworkConditions( | 1086 return web_view->OverrideNetworkConditions( |
1038 *session->overridden_network_conditions); | 1087 *session->overridden_network_conditions); |
1039 } | 1088 } |
1040 | 1089 |
1041 Status ExecuteDeleteNetworkConditions( | 1090 Status ExecuteDeleteNetworkConditions( |
1042 Session* session, | 1091 Session* session, |
1043 WebView* web_view, | 1092 WebView* web_view, |
1044 const base::DictionaryValue& params, | 1093 const base::DictionaryValue& params, |
1045 scoped_ptr<base::Value>* value) { | 1094 scoped_ptr<base::Value>* value, |
1095 Timeout* timeout) { | |
1046 // Chrome does not have any command to stop overriding network conditions, so | 1096 // Chrome does not have any command to stop overriding network conditions, so |
1047 // we just override the network conditions with the "No throttling" preset. | 1097 // we just override the network conditions with the "No throttling" preset. |
1048 NetworkConditions network_conditions; | 1098 NetworkConditions network_conditions; |
1049 // Get conditions from preset list. | 1099 // Get conditions from preset list. |
1050 Status status = FindPresetNetwork("No throttling", &network_conditions); | 1100 Status status = FindPresetNetwork("No throttling", &network_conditions); |
1051 if (status.IsError()) | 1101 if (status.IsError()) |
1052 return status; | 1102 return status; |
1053 | 1103 |
1054 status = web_view->OverrideNetworkConditions(network_conditions); | 1104 status = web_view->OverrideNetworkConditions(network_conditions); |
1055 if (status.IsError()) | 1105 if (status.IsError()) |
1056 return status; | 1106 return status; |
1057 | 1107 |
1058 // After we've successfully overridden the network conditions with | 1108 // After we've successfully overridden the network conditions with |
1059 // "No throttling", we can delete them from |session|. | 1109 // "No throttling", we can delete them from |session|. |
1060 session->overridden_network_conditions.reset(); | 1110 session->overridden_network_conditions.reset(); |
1061 return status; | 1111 return status; |
1062 } | 1112 } |
1063 | 1113 |
1064 Status ExecuteTakeHeapSnapshot( | 1114 Status ExecuteTakeHeapSnapshot( |
1065 Session* session, | 1115 Session* session, |
1066 WebView* web_view, | 1116 WebView* web_view, |
1067 const base::DictionaryValue& params, | 1117 const base::DictionaryValue& params, |
1068 scoped_ptr<base::Value>* value) { | 1118 scoped_ptr<base::Value>* value, |
1119 Timeout* timeout) { | |
1069 return web_view->TakeHeapSnapshot(value); | 1120 return web_view->TakeHeapSnapshot(value); |
1070 } | 1121 } |
OLD | NEW |