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/session_manager.h" | 5 #include "chrome/test/webdriver/session.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 "var frame = document.evaluate(xpath, document, null, " | 461 "var frame = document.evaluate(xpath, document, null, " |
462 "XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" | 462 "XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" |
463 "console.info(frame == null ? 'found nothing' : frame);" | 463 "console.info(frame == null ? 'found nothing' : frame);" |
464 "return frame == null ? null : ((frame.tagName == 'IFRAME' ? " | 464 "return frame == null ? null : ((frame.tagName == 'IFRAME' ? " |
465 " '/html/body//iframe' : '/html/frameset/frame') + index);"; | 465 " '/html/body//iframe' : '/html/frameset/frame') + index);"; |
466 ListValue args; | 466 ListValue args; |
467 args.Append(Value::CreateIntegerValue(index)); | 467 args.Append(Value::CreateIntegerValue(index)); |
468 return SwitchToFrameWithJavaScriptLocatedFrame(script, &args); | 468 return SwitchToFrameWithJavaScriptLocatedFrame(script, &args); |
469 } | 469 } |
470 | 470 |
| 471 ErrorCode Session::SwitchToFrameWithElement(const WebElementId& element) { |
| 472 // TODO(jleyba): Extract this, and the other frame switch methods to an atom. |
| 473 std::string script = |
| 474 "var element = arguments[0];" |
| 475 "console.info('Attempting to switch to ' + element);" |
| 476 "if (element.nodeType != 1 || !/^i?frame$/i.test(element.tagName)) {" |
| 477 " console.info('Element is not a frame: ' + element + " |
| 478 "' {nodeType:' + element.nodeType + ',tagName:' + element.tagName + '}');" |
| 479 " return null;" |
| 480 "}" |
| 481 "for (var i = 0; i < window.frames.length; i++) {" |
| 482 " if (element.contentWindow == window.frames[i]) {" |
| 483 " return '(//iframe|//frame)[' + (i + 1) + ']';" |
| 484 " }" |
| 485 "}" |
| 486 "console.info('Frame is not connected to this DOM tree');" |
| 487 "return null;"; |
| 488 |
| 489 ListValue args; |
| 490 args.Append(element.ToValue()); |
| 491 return SwitchToFrameWithJavaScriptLocatedFrame(script, &args); |
| 492 } |
| 493 |
471 void Session::SwitchToTopFrame() { | 494 void Session::SwitchToTopFrame() { |
472 current_target_.frame_path = FramePath(); | 495 current_target_.frame_path = FramePath(); |
473 } | 496 } |
474 | 497 |
475 bool Session::CloseWindow() { | 498 bool Session::CloseWindow() { |
476 bool success = false; | 499 bool success = false; |
477 RunSessionTask(NewRunnableMethod( | 500 RunSessionTask(NewRunnableMethod( |
478 automation_.get(), | 501 automation_.get(), |
479 &Automation::CloseTab, | 502 &Automation::CloseTab, |
480 current_target_.window_id, | 503 current_target_.window_id, |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 if (!loc_dict->GetInteger("x", &x) || | 885 if (!loc_dict->GetInteger("x", &x) || |
863 !loc_dict->GetInteger("y", &y)) { | 886 !loc_dict->GetInteger("y", &y)) { |
864 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; | 887 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; |
865 code = kUnknownError; | 888 code = kUnknownError; |
866 } | 889 } |
867 *location = gfx::Point(x, y); | 890 *location = gfx::Point(x, y); |
868 return kSuccess; | 891 return kSuccess; |
869 } | 892 } |
870 | 893 |
871 } // namespace webdriver | 894 } // namespace webdriver |
OLD | NEW |