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

Side by Side Diff: chrome/test/chromedriver/window_commands.cc

Issue 12217149: [ChromeDriver] Implement SwitchToFrame by element command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « chrome/test/chromedriver/run_py_tests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <list> 7 #include <list>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 scoped_ptr<base::Value>* value) { 115 scoped_ptr<base::Value>* value) {
116 const base::Value* id; 116 const base::Value* id;
117 if (!params.Get("id", &id)) 117 if (!params.Get("id", &id))
118 return Status(kUnknownError, "missing 'id'"); 118 return Status(kUnknownError, "missing 'id'");
119 119
120 if (id->IsType(base::Value::TYPE_NULL)) { 120 if (id->IsType(base::Value::TYPE_NULL)) {
121 session->frame = ""; 121 session->frame = "";
122 return Status(kOk); 122 return Status(kOk);
123 } 123 }
124 124
125 std::string evaluate_xpath_script = 125 std::string script;
126 "function(xpath) {" 126 base::ListValue args;
127 " return document.evaluate(xpath, document, null, " 127 const base::DictionaryValue* id_dict;
128 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" 128 if (id->GetAsDictionary(&id_dict)) {
129 "}"; 129 script = "function(elem) { return elem; }";
130 std::string xpath = "(/html/body//iframe|/html/frameset/frame)"; 130 args.Append(id_dict->DeepCopy());
131 std::string id_string;
132 int id_int;
133 if (id->GetAsString(&id_string)) {
134 xpath += base::StringPrintf(
135 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str());
136 } else if (id->GetAsInteger(&id_int)) {
137 xpath += base::StringPrintf("[%d]", id_int + 1);
138 } else if (id->IsType(base::Value::TYPE_DICTIONARY)) {
139 // TODO(kkania): Implement.
140 return Status(kUnknownError, "frame switching by element not implemented");
141 } else { 131 } else {
142 return Status(kUnknownError, "invalid 'id'"); 132 script =
133 "function(xpath) {"
134 " return document.evaluate(xpath, document, null, "
135 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
136 "}";
137 std::string xpath = "(/html/body//iframe|/html/frameset/frame)";
138 std::string id_string;
139 int id_int;
140 if (id->GetAsString(&id_string)) {
141 xpath += base::StringPrintf(
142 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str());
143 } else if (id->GetAsInteger(&id_int)) {
144 xpath += base::StringPrintf("[%d]", id_int + 1);
145 } else {
146 return Status(kUnknownError, "invalid 'id'");
147 }
148 args.Append(new base::StringValue(xpath));
143 } 149 }
144 base::ListValue args;
145 args.Append(new base::StringValue(xpath));
146 std::string frame; 150 std::string frame;
147 Status status = web_view->GetFrameByFunction( 151 Status status = web_view->GetFrameByFunction(
148 session->frame, evaluate_xpath_script, args, &frame); 152 session->frame, script, args, &frame);
149 if (status.IsError()) 153 if (status.IsError())
150 return status; 154 return status;
151 session->frame = frame; 155 session->frame = frame;
152 return Status(kOk); 156 return Status(kOk);
153 } 157 }
154 158
155 Status ExecuteGetTitle( 159 Status ExecuteGetTitle(
156 Session* session, 160 Session* session,
157 WebView* web_view, 161 WebView* web_view,
158 const base::DictionaryValue& params, 162 const base::DictionaryValue& params,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return status; 331 return status;
328 std::list<MouseEvent> events; 332 std::list<MouseEvent> events;
329 events.push_back( 333 events.push_back(
330 MouseEvent(kPressedMouseEventType, button, 334 MouseEvent(kPressedMouseEventType, button,
331 session->mouse_position.x, session->mouse_position.y, 2)); 335 session->mouse_position.x, session->mouse_position.y, 2));
332 events.push_back( 336 events.push_back(
333 MouseEvent(kReleasedMouseEventType, button, 337 MouseEvent(kReleasedMouseEventType, button,
334 session->mouse_position.x, session->mouse_position.y, 2)); 338 session->mouse_position.x, session->mouse_position.y, 2));
335 return web_view->DispatchMouseEvents(events); 339 return web_view->DispatchMouseEvents(events);
336 } 340 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/run_py_tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698