Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/test/webdriver/session.cc

Issue 6723004: ChromeDriver should be able to focus on a frame using its frame element, (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
OLDNEW
« chrome/test/webdriver/chromedriver_tests.py ('K') | « chrome/test/webdriver/session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698