OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webdriver/webdriver_session.h" | 5 #include "chrome/test/webdriver/webdriver_session.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/test/automation/automation_json_requests.h" | 36 #include "chrome/test/automation/automation_json_requests.h" |
37 #include "chrome/test/automation/value_conversion_util.h" | 37 #include "chrome/test/automation/value_conversion_util.h" |
38 #include "chrome/test/webdriver/webdriver_error.h" | 38 #include "chrome/test/webdriver/webdriver_error.h" |
39 #include "chrome/test/webdriver/webdriver_key_converter.h" | 39 #include "chrome/test/webdriver/webdriver_key_converter.h" |
40 #include "chrome/test/webdriver/webdriver_session_manager.h" | 40 #include "chrome/test/webdriver/webdriver_session_manager.h" |
41 #include "chrome/test/webdriver/webdriver_util.h" | 41 #include "chrome/test/webdriver/webdriver_util.h" |
42 #include "third_party/webdriver/atoms.h" | 42 #include "third_party/webdriver/atoms.h" |
43 | 43 |
44 namespace webdriver { | 44 namespace webdriver { |
45 | 45 |
46 FrameId::FrameId(int window_id, const FramePath& frame_path) | 46 FrameId::FrameId() {} |
47 : window_id(window_id), | 47 |
| 48 FrameId::FrameId(const WebViewId& view_id, const FramePath& frame_path) |
| 49 : view_id(view_id), |
48 frame_path(frame_path) { | 50 frame_path(frame_path) { |
49 } | 51 } |
50 | 52 |
| 53 /* |
51 FrameId& FrameId::operator=(const FrameId& other) { | 54 FrameId& FrameId::operator=(const FrameId& other) { |
52 window_id = other.window_id; | 55 view_id = other.view_id; |
53 frame_path = other.frame_path; | 56 frame_path = other.frame_path; |
54 return *this; | 57 return *this; |
55 } | 58 } |
| 59 */ |
56 | 60 |
57 Session::Options::Options() | 61 Session::Options::Options() |
58 : use_native_events(false), | 62 : use_native_events(false), |
59 load_async(false) { | 63 load_async(false) { |
60 } | 64 } |
61 | 65 |
62 Session::Options::~Options() { | 66 Session::Options::~Options() { |
63 } | 67 } |
64 | 68 |
65 Session::Session(const Options& options) | 69 Session::Session(const Options& options) |
66 : id_(GenerateRandomID()), | 70 : id_(GenerateRandomID()), |
67 current_target_(FrameId(0, FramePath())), | 71 current_target_(FrameId(WebViewId(), FramePath())), |
68 thread_(id_.c_str()), | 72 thread_(id_.c_str()), |
69 async_script_timeout_(0), | 73 async_script_timeout_(0), |
70 implicit_wait_(0), | 74 implicit_wait_(0), |
71 has_alert_prompt_text_(false), | 75 has_alert_prompt_text_(false), |
72 options_(options) { | 76 options_(options) { |
73 SessionManager::GetInstance()->Add(this); | 77 SessionManager::GetInstance()->Add(this); |
74 } | 78 } |
75 | 79 |
76 Session::~Session() { | 80 Session::~Session() { |
77 SessionManager::GetInstance()->Remove(id_); | 81 SessionManager::GetInstance()->Remove(id_); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return error; | 274 return error; |
271 } | 275 } |
272 | 276 |
273 Error* Session::DragAndDropFilePaths( | 277 Error* Session::DragAndDropFilePaths( |
274 const Point& location, | 278 const Point& location, |
275 const std::vector<FilePath::StringType>& paths) { | 279 const std::vector<FilePath::StringType>& paths) { |
276 Error* error = NULL; | 280 Error* error = NULL; |
277 RunSessionTask(NewRunnableMethod( | 281 RunSessionTask(NewRunnableMethod( |
278 automation_.get(), | 282 automation_.get(), |
279 &Automation::DragAndDropFilePaths, | 283 &Automation::DragAndDropFilePaths, |
280 current_target_.window_id, | 284 current_target_.view_id.id.tab_id, // FIXME |
281 location, | 285 location, |
282 paths, | 286 paths, |
283 &error)); | 287 &error)); |
284 return error; | 288 return error; |
285 } | 289 } |
286 | 290 |
287 Error* Session::NavigateToURL(const std::string& url) { | 291 Error* Session::NavigateToURL(const std::string& url) { |
288 Error* error = NULL; | 292 Error* error = NULL; |
289 if (options_.load_async) { | 293 if (options_.load_async) { |
290 RunSessionTask(NewRunnableMethod( | 294 RunSessionTask(NewRunnableMethod( |
291 automation_.get(), | 295 automation_.get(), |
292 &Automation::NavigateToURLAsync, | 296 &Automation::NavigateToURLAsync, |
293 current_target_.window_id, | 297 current_target_.view_id.id.tab_id, // FIXME |
294 url, | 298 url, |
295 &error)); | 299 &error)); |
296 } else { | 300 } else { |
297 RunSessionTask(NewRunnableMethod( | 301 RunSessionTask(NewRunnableMethod( |
298 automation_.get(), | 302 automation_.get(), |
299 &Automation::NavigateToURL, | 303 &Automation::NavigateToURL, |
300 current_target_.window_id, | 304 current_target_.view_id.id.tab_id, // FIXME |
301 url, | 305 url, |
302 &error)); | 306 &error)); |
303 } | 307 } |
304 return error; | 308 return error; |
305 } | 309 } |
306 | 310 |
307 Error* Session::GoForward() { | 311 Error* Session::GoForward() { |
308 Error* error = NULL; | 312 Error* error = NULL; |
309 RunSessionTask(NewRunnableMethod( | 313 RunSessionTask(NewRunnableMethod( |
310 automation_.get(), | 314 automation_.get(), |
311 &Automation::GoForward, | 315 &Automation::GoForward, |
312 current_target_.window_id, | 316 current_target_.view_id.id.tab_id, // FIXME |
313 &error)); | 317 &error)); |
314 return error; | 318 return error; |
315 } | 319 } |
316 | 320 |
317 Error* Session::GoBack() { | 321 Error* Session::GoBack() { |
318 Error* error = NULL; | 322 Error* error = NULL; |
319 RunSessionTask(NewRunnableMethod( | 323 RunSessionTask(NewRunnableMethod( |
320 automation_.get(), | 324 automation_.get(), |
321 &Automation::GoBack, | 325 &Automation::GoBack, |
322 current_target_.window_id, | 326 current_target_.view_id.id.tab_id, // FIXME |
323 &error)); | 327 &error)); |
324 return error; | 328 return error; |
325 } | 329 } |
326 | 330 |
327 Error* Session::Reload() { | 331 Error* Session::Reload() { |
328 Error* error = NULL; | 332 Error* error = NULL; |
329 RunSessionTask(NewRunnableMethod( | 333 RunSessionTask(NewRunnableMethod( |
330 automation_.get(), | 334 automation_.get(), |
331 &Automation::Reload, | 335 &Automation::Reload, |
332 current_target_.window_id, | 336 current_target_.view_id.id.tab_id, // FIXME |
333 &error)); | 337 &error)); |
334 return error; | 338 return error; |
335 } | 339 } |
336 | 340 |
337 Error* Session::GetURL(std::string* url) { | 341 Error* Session::GetURL(std::string* url) { |
338 return ExecuteScriptAndParse(current_target_, | 342 return ExecuteScriptAndParse(current_target_, |
339 "function() { return document.URL }", | 343 "function() { return document.URL }", |
340 "getUrl", | 344 "getUrl", |
341 new ListValue(), | 345 new ListValue(), |
342 CreateDirectValueParser(url)); | 346 CreateDirectValueParser(url)); |
343 } | 347 } |
344 | 348 |
345 Error* Session::GetTitle(std::string* tab_title) { | 349 Error* Session::GetTitle(std::string* tab_title) { |
346 const char* kGetTitleScript = | 350 const char* kGetTitleScript = |
347 "function() {" | 351 "function() {" |
348 " if (document.title)" | 352 " if (document.title)" |
349 " return document.title;" | 353 " return document.title;" |
350 " else" | 354 " else" |
351 " return document.URL;" | 355 " return document.URL;" |
352 "}"; | 356 "}"; |
353 return ExecuteScriptAndParse(FrameId(current_target_.window_id, FramePath()), | 357 return ExecuteScriptAndParse(FrameId(current_target_.view_id, FramePath()), |
354 kGetTitleScript, | 358 kGetTitleScript, |
355 "getTitle", | 359 "getTitle", |
356 new ListValue(), | 360 new ListValue(), |
357 CreateDirectValueParser(tab_title)); | 361 CreateDirectValueParser(tab_title)); |
358 } | 362 } |
359 | 363 |
360 Error* Session::MouseMoveAndClick(const Point& location, | 364 Error* Session::MouseMoveAndClick(const Point& location, |
361 automation::MouseButton button) { | 365 automation::MouseButton button) { |
362 Error* error = NULL; | 366 Error* error = NULL; |
363 RunSessionTask(NewRunnableMethod( | 367 RunSessionTask(NewRunnableMethod( |
364 automation_.get(), | 368 automation_.get(), |
365 &Automation::MouseClick, | 369 &Automation::MouseClick, |
366 current_target_.window_id, | 370 current_target_.view_id.id.tab_id, // FIXME |
367 location, | 371 location, |
368 button, | 372 button, |
369 &error)); | 373 &error)); |
370 if (!error) | 374 if (!error) |
371 mouse_position_ = location; | 375 mouse_position_ = location; |
372 return error; | 376 return error; |
373 } | 377 } |
374 | 378 |
375 Error* Session::MouseMove(const Point& location) { | 379 Error* Session::MouseMove(const Point& location) { |
376 Error* error = NULL; | 380 Error* error = NULL; |
377 RunSessionTask(NewRunnableMethod( | 381 RunSessionTask(NewRunnableMethod( |
378 automation_.get(), | 382 automation_.get(), |
379 &Automation::MouseMove, | 383 &Automation::MouseMove, |
380 current_target_.window_id, | 384 current_target_.view_id.id.tab_id, // FIXME |
381 location, | 385 location, |
382 &error)); | 386 &error)); |
383 if (!error) | 387 if (!error) |
384 mouse_position_ = location; | 388 mouse_position_ = location; |
385 return error; | 389 return error; |
386 } | 390 } |
387 | 391 |
388 Error* Session::MouseDrag(const Point& start, | 392 Error* Session::MouseDrag(const Point& start, |
389 const Point& end) { | 393 const Point& end) { |
390 Error* error = NULL; | 394 Error* error = NULL; |
391 RunSessionTask(NewRunnableMethod( | 395 RunSessionTask(NewRunnableMethod( |
392 automation_.get(), | 396 automation_.get(), |
393 &Automation::MouseDrag, | 397 &Automation::MouseDrag, |
394 current_target_.window_id, | 398 current_target_.view_id.id.tab_id, // FIXME |
395 start, | 399 start, |
396 end, | 400 end, |
397 &error)); | 401 &error)); |
398 if (!error) | 402 if (!error) |
399 mouse_position_ = end; | 403 mouse_position_ = end; |
400 return error; | 404 return error; |
401 } | 405 } |
402 | 406 |
403 Error* Session::MouseClick(automation::MouseButton button) { | 407 Error* Session::MouseClick(automation::MouseButton button) { |
404 return MouseMoveAndClick(mouse_position_, button); | 408 return MouseMoveAndClick(mouse_position_, button); |
405 } | 409 } |
406 | 410 |
407 Error* Session::MouseButtonDown() { | 411 Error* Session::MouseButtonDown() { |
408 Error* error = NULL; | 412 Error* error = NULL; |
409 RunSessionTask(NewRunnableMethod( | 413 RunSessionTask(NewRunnableMethod( |
410 automation_.get(), | 414 automation_.get(), |
411 &Automation::MouseButtonDown, | 415 &Automation::MouseButtonDown, |
412 current_target_.window_id, | 416 current_target_.view_id.id.tab_id, // FIXME |
413 mouse_position_, | 417 mouse_position_, |
414 &error)); | 418 &error)); |
415 return error; | 419 return error; |
416 } | 420 } |
417 | 421 |
418 Error* Session::MouseButtonUp() { | 422 Error* Session::MouseButtonUp() { |
419 Error* error = NULL; | 423 Error* error = NULL; |
420 RunSessionTask(NewRunnableMethod( | 424 RunSessionTask(NewRunnableMethod( |
421 automation_.get(), | 425 automation_.get(), |
422 &Automation::MouseButtonUp, | 426 &Automation::MouseButtonUp, |
423 current_target_.window_id, | 427 current_target_.view_id.id.tab_id, // FIXME |
424 mouse_position_, | 428 mouse_position_, |
425 &error)); | 429 &error)); |
426 return error; | 430 return error; |
427 } | 431 } |
428 | 432 |
429 Error* Session::MouseDoubleClick() { | 433 Error* Session::MouseDoubleClick() { |
430 Error* error = NULL; | 434 Error* error = NULL; |
431 RunSessionTask(NewRunnableMethod( | 435 RunSessionTask(NewRunnableMethod( |
432 automation_.get(), | 436 automation_.get(), |
433 &Automation::MouseDoubleClick, | 437 &Automation::MouseDoubleClick, |
434 current_target_.window_id, | 438 current_target_.view_id.id.tab_id, // FIXME |
435 mouse_position_, | 439 mouse_position_, |
436 &error)); | 440 &error)); |
437 return error; | 441 return error; |
438 } | 442 } |
439 | 443 |
440 Error* Session::GetCookies(const std::string& url, ListValue** cookies) { | 444 Error* Session::GetCookies(const std::string& url, ListValue** cookies) { |
441 Error* error = NULL; | 445 Error* error = NULL; |
442 RunSessionTask(NewRunnableMethod( | 446 RunSessionTask(NewRunnableMethod( |
443 automation_.get(), | 447 automation_.get(), |
444 &Automation::GetCookies, | 448 &Automation::GetCookies, |
(...skipping 20 matching lines...) Expand all Loading... |
465 Error* error = NULL; | 469 Error* error = NULL; |
466 RunSessionTask(NewRunnableMethod( | 470 RunSessionTask(NewRunnableMethod( |
467 automation_.get(), | 471 automation_.get(), |
468 &Automation::SetCookie, | 472 &Automation::SetCookie, |
469 url, | 473 url, |
470 cookie_dict, | 474 cookie_dict, |
471 &error)); | 475 &error)); |
472 return error; | 476 return error; |
473 } | 477 } |
474 | 478 |
475 Error* Session::GetWindowIds(std::vector<int>* window_ids) { | 479 Error* Session::GetViews(std::vector<WebViewInfo>* views) { |
476 Error* error = NULL; | 480 Error* error = NULL; |
477 RunSessionTask(NewRunnableMethod( | 481 RunSessionTask(NewRunnableMethod( |
478 automation_.get(), | 482 automation_.get(), |
479 &Automation::GetTabIds, | 483 &Automation::GetViews, |
480 window_ids, | 484 views, |
481 &error)); | 485 &error)); |
482 return error; | 486 return error; |
483 } | 487 } |
484 | 488 |
485 Error* Session::SwitchToWindow(const std::string& name) { | 489 Error* Session::SwitchToView(const std::string& id_or_name) { |
486 int switch_to_id = 0; | 490 Error* error = NULL; |
487 int name_no = 0; | 491 bool does_exist = false; |
488 if (base::StringToInt(name, &name_no)) { | 492 |
489 Error* error = NULL; | 493 bool new_version = false; |
490 bool does_exist = false; | 494 error = CompareBrowserVersion(500, 0, &new_version); |
| 495 if (error) |
| 496 return error; |
| 497 int id_no; |
| 498 WebViewId new_view; |
| 499 if (new_version) { |
| 500 std::vector<std::string> parts; |
| 501 // Check if valid type. |
| 502 base::SplitString(id_or_name, '|', &parts); |
| 503 int type; |
| 504 if (parts.size() == 2 && base::StringToInt(parts[0], &type)) { |
| 505 new_view = WebViewId::ForView( |
| 506 AutomationId(static_cast<AutomationId::Type>(type), |
| 507 parts[1])); |
| 508 } |
| 509 } else if (base::StringToInt(id_or_name, &id_no)) { |
| 510 new_view = WebViewId::ForTab(id_no); |
| 511 } |
| 512 if (new_view.IsValid()) { |
491 RunSessionTask(NewRunnableMethod( | 513 RunSessionTask(NewRunnableMethod( |
492 automation_.get(), | 514 automation_.get(), |
493 &Automation::DoesTabExist, | 515 &Automation::DoesViewExist, |
494 name_no, | 516 new_view, |
495 &does_exist, | 517 &does_exist, |
496 &error)); | 518 &error)); |
497 if (error) | 519 if (error) |
498 return error; | 520 return error; |
499 if (does_exist) | |
500 switch_to_id = name_no; | |
501 } | 521 } |
502 | 522 |
503 if (!switch_to_id) { | 523 if (!does_exist) { |
504 std::vector<int> window_ids; | 524 // See if any of the tab window names match |name|. |
505 Error* error = GetWindowIds(&window_ids); | 525 std::vector<WebViewInfo> views; |
| 526 Error* error = GetViews(&views); |
506 if (error) | 527 if (error) |
507 return error; | 528 return error; |
508 // See if any of the window names match |name|. | 529 for (size_t i = 0; i < views.size(); ++i) { |
509 for (size_t i = 0; i < window_ids.size(); ++i) { | 530 if (views[i].view_id.type != WebViewId::kTypeTabId) |
| 531 continue; |
510 std::string window_name; | 532 std::string window_name; |
511 Error* error = ExecuteScriptAndParse( | 533 Error* error = ExecuteScriptAndParse( |
512 FrameId(window_ids[i], FramePath()), | 534 FrameId(views[i].view_id, FramePath()), |
513 "function() { return window.name; }", | 535 "function() { return window.name; }", |
514 "getWindowName", | 536 "getWindowName", |
515 new ListValue(), | 537 new ListValue(), |
516 CreateDirectValueParser(&window_name)); | 538 CreateDirectValueParser(&window_name)); |
517 if (error) | 539 if (error) |
518 return error; | 540 return error; |
519 if (name == window_name) { | 541 if (id_or_name == window_name) { |
520 switch_to_id = window_ids[i]; | 542 new_view = views[i].view_id; |
| 543 does_exist = true; |
521 break; | 544 break; |
522 } | 545 } |
523 } | 546 } |
524 } | 547 } |
525 | 548 |
526 if (!switch_to_id) | 549 if (!does_exist) |
527 return new Error(kNoSuchWindow); | 550 return new Error(kNoSuchWindow); |
528 frame_elements_.clear(); | 551 frame_elements_.clear(); |
529 current_target_ = FrameId(switch_to_id, FramePath()); | 552 current_target_ = FrameId(new_view, FramePath()); |
530 return NULL; | 553 return NULL; |
531 } | 554 } |
532 | 555 |
533 Error* Session::SwitchToFrameWithNameOrId(const std::string& name_or_id) { | 556 Error* Session::SwitchToFrameWithNameOrId(const std::string& name_or_id) { |
534 std::string script = | 557 std::string script = |
535 "function(arg) {" | 558 "function(arg) {" |
536 " var xpath = '(/html/body//iframe|/html/frameset/frame)';" | 559 " var xpath = '(/html/body//iframe|/html/frameset/frame)';" |
537 " var sub = function(s) { return s.replace(/\\$/g, arg); };" | 560 " var sub = function(s) { return s.replace(/\\$/g, arg); };" |
538 " xpath += sub('[@name=\"$\" or @id=\"$\"]');" | 561 " xpath += sub('[@name=\"$\" or @id=\"$\"]');" |
539 " var frame = document.evaluate(xpath, document, null, " | 562 " var frame = document.evaluate(xpath, document, null, " |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 if (frame_elements_.size() != components.size()) { | 627 if (frame_elements_.size() != components.size()) { |
605 return new Error(kUnknownError, | 628 return new Error(kUnknownError, |
606 "Frame element vector out of sync with frame path"); | 629 "Frame element vector out of sync with frame path"); |
607 } | 630 } |
608 FramePath frame_path; | 631 FramePath frame_path; |
609 // Start from the root path and check that each frame element that makes | 632 // Start from the root path and check that each frame element that makes |
610 // up the current frame target is valid by executing an empty script. | 633 // up the current frame target is valid by executing an empty script. |
611 // This code should not execute script in any frame before making sure the | 634 // This code should not execute script in any frame before making sure the |
612 // frame element is valid, otherwise the automation hangs until a timeout. | 635 // frame element is valid, otherwise the automation hangs until a timeout. |
613 for (size_t i = 0; i < frame_elements_.size(); ++i) { | 636 for (size_t i = 0; i < frame_elements_.size(); ++i) { |
614 FrameId frame_id(current_target_.window_id, frame_path); | 637 FrameId frame_id(current_target_.view_id, frame_path); |
615 scoped_ptr<Error> error(ExecuteScriptAndParse( | 638 scoped_ptr<Error> error(ExecuteScriptAndParse( |
616 frame_id, | 639 frame_id, |
617 "function(){ }", | 640 "function(){ }", |
618 "emptyScript", | 641 "emptyScript", |
619 CreateListValueFrom(frame_elements_[i]), | 642 CreateListValueFrom(frame_elements_[i]), |
620 CreateDirectValueParser(kSkipParsing))); | 643 CreateDirectValueParser(kSkipParsing))); |
621 if (error.get() && error->code() == kStaleElementReference) { | 644 if (error.get() && error->code() == kStaleElementReference) { |
622 SwitchToTopFrame(); | 645 SwitchToTopFrame(); |
623 } else if (error.get()) { | 646 } else if (error.get()) { |
624 return error.release(); | 647 return error.release(); |
625 } | 648 } |
626 frame_path = frame_path.Append(components[i]); | 649 frame_path = frame_path.Append(components[i]); |
627 } | 650 } |
628 return NULL; | 651 return NULL; |
629 } | 652 } |
630 | 653 |
631 Error* Session::CloseWindow() { | 654 Error* Session::CloseWindow() { |
632 Error* error = NULL; | 655 Error* error = NULL; |
633 RunSessionTask(NewRunnableMethod( | 656 RunSessionTask(NewRunnableMethod( |
634 automation_.get(), | 657 automation_.get(), |
635 &Automation::CloseTab, | 658 &Automation::CloseTab, |
636 current_target_.window_id, | 659 current_target_.view_id.id.tab_id, // FIXME |
637 &error)); | 660 &error)); |
638 | 661 |
639 if (!error) { | 662 if (!error) { |
640 std::vector<int> window_ids; | 663 std::vector<WebViewInfo> views; |
641 scoped_ptr<Error> error(GetWindowIds(&window_ids)); | 664 scoped_ptr<Error> error(GetViews(&views)); |
642 if (error.get() || window_ids.empty()) { | 665 if (error.get() || views.empty()) { |
643 // The automation connection will soon be closed, if not already, | 666 // The automation connection will soon be closed, if not already, |
644 // because we supposedly just closed the last window. Terminate the | 667 // because we supposedly just closed the last window. Terminate the |
645 // session. | 668 // session. |
646 // TODO(kkania): This will cause us problems if GetWindowIds fails for a | 669 // TODO(kkania): This will cause us problems if GetWindowIds fails for a |
647 // reason other than the channel is disconnected. Look into having | 670 // reason other than the channel is disconnected. Look into having |
648 // |GetWindowIds| tell us if it just closed the last window. | 671 // |GetWindowIds| tell us if it just closed the last window. |
649 Terminate(); | 672 Terminate(); |
650 } | 673 } |
651 } | 674 } |
652 return error; | 675 return error; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 Error* error = GetElementRegionInViewHelper( | 796 Error* error = GetElementRegionInViewHelper( |
774 current_target_, element, region, center, verify_clickable_at_middle, | 797 current_target_, element, region, center, verify_clickable_at_middle, |
775 ®ion_offset); | 798 ®ion_offset); |
776 if (error) | 799 if (error) |
777 return error; | 800 return error; |
778 | 801 |
779 for (FramePath frame_path = current_target_.frame_path; | 802 for (FramePath frame_path = current_target_.frame_path; |
780 frame_path.IsSubframe(); | 803 frame_path.IsSubframe(); |
781 frame_path = frame_path.Parent()) { | 804 frame_path = frame_path.Parent()) { |
782 // Find the frame element for the current frame path. | 805 // Find the frame element for the current frame path. |
783 FrameId frame_id(current_target_.window_id, frame_path.Parent()); | 806 FrameId frame_id(current_target_.view_id, frame_path.Parent()); |
784 ElementId frame_element; | 807 ElementId frame_element; |
785 error = FindElement( | 808 error = FindElement( |
786 frame_id, ElementId(""), | 809 frame_id, ElementId(""), |
787 LocatorType::kXpath, frame_path.BaseName().value(), &frame_element); | 810 LocatorType::kXpath, frame_path.BaseName().value(), &frame_element); |
788 if (error) { | 811 if (error) { |
789 std::string context = base::StringPrintf( | 812 std::string context = base::StringPrintf( |
790 "Could not find frame element (%s) in frame (%s)", | 813 "Could not find frame element (%s) in frame (%s)", |
791 frame_path.BaseName().value().c_str(), | 814 frame_path.BaseName().value().c_str(), |
792 frame_path.Parent().value().c_str()); | 815 frame_path.Parent().value().c_str()); |
793 error->AddDetails(context); | 816 error->AddDetails(context); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 done_event->Signal(); | 1120 done_event->Signal(); |
1098 } | 1121 } |
1099 | 1122 |
1100 void Session::InitOnSessionThread(const Automation::BrowserOptions& options, | 1123 void Session::InitOnSessionThread(const Automation::BrowserOptions& options, |
1101 Error** error) { | 1124 Error** error) { |
1102 automation_.reset(new Automation()); | 1125 automation_.reset(new Automation()); |
1103 automation_->Init(options, error); | 1126 automation_->Init(options, error); |
1104 if (*error) | 1127 if (*error) |
1105 return; | 1128 return; |
1106 | 1129 |
1107 std::vector<int> tab_ids; | 1130 std::vector<WebViewInfo> views; |
1108 automation_->GetTabIds(&tab_ids, error); | 1131 automation_->GetViews(&views, error); |
1109 if (*error) | 1132 if (*error) |
1110 return; | 1133 return; |
1111 if (tab_ids.empty()) { | 1134 if (views.empty()) { |
1112 *error = new Error(kUnknownError, "No tab ids after initialization"); | 1135 *error = new Error(kUnknownError, "No view ids after initialization"); |
1113 return; | 1136 return; |
1114 } | 1137 } |
1115 current_target_ = FrameId(tab_ids[0], FramePath()); | 1138 current_target_ = FrameId(views[0].view_id, FramePath()); |
1116 } | 1139 } |
1117 | 1140 |
1118 void Session::TerminateOnSessionThread() { | 1141 void Session::TerminateOnSessionThread() { |
1119 if (automation_.get()) | 1142 if (automation_.get()) |
1120 automation_->Terminate(); | 1143 automation_->Terminate(); |
1121 automation_.reset(); | 1144 automation_.reset(); |
1122 } | 1145 } |
1123 | 1146 |
1124 Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id, | 1147 Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id, |
1125 const std::string& script, | 1148 const std::string& script, |
1126 Value** script_result) { | 1149 Value** script_result) { |
1127 std::string response_json; | 1150 std::string response_json; |
1128 Error* error = NULL; | 1151 Error* error = NULL; |
1129 RunSessionTask(NewRunnableMethod( | 1152 RunSessionTask(NewRunnableMethod( |
1130 automation_.get(), | 1153 automation_.get(), |
1131 &Automation::ExecuteScript, | 1154 &Automation::ExecuteScript, |
1132 frame_id.window_id, | 1155 frame_id.view_id, |
1133 frame_id.frame_path, | 1156 frame_id.frame_path, |
1134 script, | 1157 script, |
1135 &response_json, | 1158 &response_json, |
1136 &error)); | 1159 &error)); |
1137 if (error) | 1160 if (error) |
1138 return error; | 1161 return error; |
1139 | 1162 |
1140 scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError( | 1163 scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError( |
1141 response_json, true, NULL, NULL)); | 1164 response_json, true, NULL, NULL)); |
1142 if (!value.get()) | 1165 if (!value.get()) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 return; | 1202 return; |
1180 } | 1203 } |
1181 for (size_t i = 0; i < key_events.size(); ++i) { | 1204 for (size_t i = 0; i < key_events.size(); ++i) { |
1182 if (options_.use_native_events) { | 1205 if (options_.use_native_events) { |
1183 // The automation provider will generate up/down events for us, we | 1206 // The automation provider will generate up/down events for us, we |
1184 // only need to call it once as compared to the WebKeyEvent method. | 1207 // only need to call it once as compared to the WebKeyEvent method. |
1185 // Hence we filter events by their types, keeping only rawkeydown. | 1208 // Hence we filter events by their types, keeping only rawkeydown. |
1186 if (key_events[i].type != automation::kRawKeyDownType) | 1209 if (key_events[i].type != automation::kRawKeyDownType) |
1187 continue; | 1210 continue; |
1188 automation_->SendNativeKeyEvent( | 1211 automation_->SendNativeKeyEvent( |
1189 current_target_.window_id, | 1212 current_target_.view_id.id.tab_id, // FIXME |
1190 key_events[i].key_code, | 1213 key_events[i].key_code, |
1191 key_events[i].modifiers, | 1214 key_events[i].modifiers, |
1192 error); | 1215 error); |
1193 } else { | 1216 } else { |
1194 automation_->SendWebKeyEvent( | 1217 automation_->SendWebKeyEvent( |
1195 current_target_.window_id, key_events[i], error); | 1218 current_target_.view_id.id.tab_id, // FIXME |
| 1219 key_events[i], error); |
1196 } | 1220 } |
1197 if (*error) { | 1221 if (*error) { |
1198 std::string details = base::StringPrintf( | 1222 std::string details = base::StringPrintf( |
1199 "Failed to send key event. Event details:\n" | 1223 "Failed to send key event. Event details:\n" |
1200 "Type: %d, KeyCode: %d, UnmodifiedText: %s, ModifiedText: %s, " | 1224 "Type: %d, KeyCode: %d, UnmodifiedText: %s, ModifiedText: %s, " |
1201 "Modifiers: %d", | 1225 "Modifiers: %d", |
1202 key_events[i].type, | 1226 key_events[i].type, |
1203 key_events[i].key_code, | 1227 key_events[i].key_code, |
1204 key_events[i].unmodified_text.c_str(), | 1228 key_events[i].unmodified_text.c_str(), |
1205 key_events[i].modified_text.c_str(), | 1229 key_events[i].modified_text.c_str(), |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 ScopedTempDir screenshots_dir; | 1465 ScopedTempDir screenshots_dir; |
1442 if (!screenshots_dir.CreateUniqueTempDir()) { | 1466 if (!screenshots_dir.CreateUniqueTempDir()) { |
1443 return new Error(kUnknownError, | 1467 return new Error(kUnknownError, |
1444 "Could not create temp directory for screenshot"); | 1468 "Could not create temp directory for screenshot"); |
1445 } | 1469 } |
1446 | 1470 |
1447 FilePath path = screenshots_dir.path().AppendASCII("screen"); | 1471 FilePath path = screenshots_dir.path().AppendASCII("screen"); |
1448 RunSessionTask(NewRunnableMethod( | 1472 RunSessionTask(NewRunnableMethod( |
1449 automation_.get(), | 1473 automation_.get(), |
1450 &Automation::CaptureEntirePageAsPNG, | 1474 &Automation::CaptureEntirePageAsPNG, |
1451 current_target_.window_id, | 1475 current_target_.view_id.id.tab_id, // FIXME |
1452 path, | 1476 path, |
1453 &error)); | 1477 &error)); |
1454 if (error) | 1478 if (error) |
1455 return error; | 1479 return error; |
1456 if (!file_util::ReadFileToString(path, png)) | 1480 if (!file_util::ReadFileToString(path, png)) |
1457 return new Error(kUnknownError, "Could not read screenshot file"); | 1481 return new Error(kUnknownError, "Could not read screenshot file"); |
1458 return NULL; | 1482 return NULL; |
1459 } | 1483 } |
1460 | 1484 |
1461 Error* Session::GetBrowserConnectionState(bool* online) { | 1485 Error* Session::GetBrowserConnectionState(bool* online) { |
1462 return ExecuteScriptAndParse( | 1486 return ExecuteScriptAndParse( |
1463 current_target_, | 1487 current_target_, |
1464 atoms::asString(atoms::IS_ONLINE), | 1488 atoms::asString(atoms::IS_ONLINE), |
1465 "isOnline", | 1489 "isOnline", |
1466 new ListValue(), | 1490 new ListValue(), |
1467 CreateDirectValueParser(online)); | 1491 CreateDirectValueParser(online)); |
1468 } | 1492 } |
1469 | 1493 |
1470 Error* Session::GetAppCacheStatus(int* status) { | 1494 Error* Session::GetAppCacheStatus(int* status) { |
1471 return ExecuteScriptAndParse( | 1495 return ExecuteScriptAndParse( |
1472 current_target_, | 1496 current_target_, |
1473 atoms::asString(atoms::GET_APPCACHE_STATUS), | 1497 atoms::asString(atoms::GET_APPCACHE_STATUS), |
1474 "getAppcacheStatus", | 1498 "getAppcacheStatus", |
1475 new ListValue(), | 1499 new ListValue(), |
1476 CreateDirectValueParser(status)); | 1500 CreateDirectValueParser(status)); |
1477 } | 1501 } |
1478 | 1502 |
1479 } // namespace webdriver | 1503 } // namespace webdriver |
OLD | NEW |