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

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

Issue 12764021: [chromedriver] Support clicking an element in sub frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error. Created 7 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
« no previous file with comments | « chrome/test/chromedriver/commands_unittest.cc ('k') | chrome/test/chromedriver/element_util.h » ('j') | 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/element_commands.h" 5 #include "chrome/test/chromedriver/element_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/third_party/icu/icu_utf.h" 10 #include "base/third_party/icu/icu_utf.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return Status(kElementNotVisible); 67 return Status(kElementNotVisible);
68 bool is_enabled = false; 68 bool is_enabled = false;
69 status = IsElementEnabled(session, web_view, element_id, &is_enabled); 69 status = IsElementEnabled(session, web_view, element_id, &is_enabled);
70 if (status.IsError()) 70 if (status.IsError())
71 return status; 71 return status;
72 if (!is_enabled) 72 if (!is_enabled)
73 return Status(kInvalidElementState); 73 return Status(kInvalidElementState);
74 base::ListValue args; 74 base::ListValue args;
75 args.Append(CreateElement(element_id)); 75 args.Append(CreateElement(element_id));
76 scoped_ptr<base::Value> result; 76 scoped_ptr<base::Value> result;
77 status = web_view->CallFunction(session->frame, kFocusScript, args, &result); 77 status = web_view->CallFunction(
78 session->GetCurrentFrameId(), kFocusScript, args, &result);
78 if (status.IsError()) 79 if (status.IsError())
79 return status; 80 return status;
80 return SendKeysOnWindow(web_view, keys, true); 81 return SendKeysOnWindow(web_view, keys, true);
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 Status ExecuteElementCommand( 86 Status ExecuteElementCommand(
86 ElementCommand command, 87 ElementCommand command,
87 Session* session, 88 Session* session,
(...skipping 29 matching lines...) Expand all
117 } 118 }
118 119
119 Status ExecuteHoverOverElement( 120 Status ExecuteHoverOverElement(
120 Session* session, 121 Session* session,
121 WebView* web_view, 122 WebView* web_view,
122 const std::string& element_id, 123 const std::string& element_id,
123 const base::DictionaryValue& params, 124 const base::DictionaryValue& params,
124 scoped_ptr<base::Value>* value) { 125 scoped_ptr<base::Value>* value) {
125 WebPoint location; 126 WebPoint location;
126 Status status = GetElementClickableLocation( 127 Status status = GetElementClickableLocation(
127 session, web_view, element_id, &location, NULL); 128 session, web_view, element_id, &location);
128 if (status.IsError()) 129 if (status.IsError())
129 return status; 130 return status;
130 131
131 MouseEvent move_event( 132 MouseEvent move_event(
132 kMovedMouseEventType, kNoneMouseButton, location.x, location.y, 0); 133 kMovedMouseEventType, kNoneMouseButton, location.x, location.y, 0);
133 std::list<MouseEvent> events; 134 std::list<MouseEvent> events;
134 events.push_back(move_event); 135 events.push_back(move_event);
135 status = web_view->DispatchMouseEvents(events); 136 status = web_view->DispatchMouseEvents(events);
136 if (status.IsOk()) 137 if (status.IsOk())
137 session->mouse_position = location; 138 session->mouse_position = location;
(...skipping 15 matching lines...) Expand all
153 status = IsOptionElementTogglable( 154 status = IsOptionElementTogglable(
154 session, web_view, element_id, &is_toggleable); 155 session, web_view, element_id, &is_toggleable);
155 if (status.IsError()) 156 if (status.IsError())
156 return status; 157 return status;
157 if (is_toggleable) 158 if (is_toggleable)
158 return ToggleOptionElement(session, web_view, element_id); 159 return ToggleOptionElement(session, web_view, element_id);
159 else 160 else
160 return SetOptionElementSelected(session, web_view, element_id, true); 161 return SetOptionElementSelected(session, web_view, element_id, true);
161 } else { 162 } else {
162 WebPoint location; 163 WebPoint location;
163 bool is_clickable;
164 status = GetElementClickableLocation( 164 status = GetElementClickableLocation(
165 session, web_view, element_id, &location, &is_clickable); 165 session, web_view, element_id, &location);
166 if (status.IsError()) 166 if (status.IsError())
167 return status; 167 return status;
168 if (!is_clickable)
169 return Status(kUnknownError, status.message());
170 168
171 std::list<MouseEvent> events; 169 std::list<MouseEvent> events;
172 events.push_back( 170 events.push_back(
173 MouseEvent(kMovedMouseEventType, kNoneMouseButton, 171 MouseEvent(kMovedMouseEventType, kNoneMouseButton,
174 location.x, location.y, 0)); 172 location.x, location.y, 0));
175 events.push_back( 173 events.push_back(
176 MouseEvent(kPressedMouseEventType, kLeftMouseButton, 174 MouseEvent(kPressedMouseEventType, kLeftMouseButton,
177 location.x, location.y, 1)); 175 location.x, location.y, 1));
178 events.push_back( 176 events.push_back(
179 MouseEvent(kReleasedMouseEventType, kLeftMouseButton, 177 MouseEvent(kReleasedMouseEventType, kLeftMouseButton,
180 location.x, location.y, 1)); 178 location.x, location.y, 1));
181 status = web_view->DispatchMouseEvents(events); 179 status = web_view->DispatchMouseEvents(events);
182 if (status.IsOk()) 180 if (status.IsOk())
183 session->mouse_position = location; 181 session->mouse_position = location;
184 return status; 182 return status;
185 } 183 }
186 } 184 }
187 185
188 Status ExecuteClearElement( 186 Status ExecuteClearElement(
189 Session* session, 187 Session* session,
190 WebView* web_view, 188 WebView* web_view,
191 const std::string& element_id, 189 const std::string& element_id,
192 const base::DictionaryValue& params, 190 const base::DictionaryValue& params,
193 scoped_ptr<base::Value>* value) { 191 scoped_ptr<base::Value>* value) {
194 base::ListValue args; 192 base::ListValue args;
195 args.Append(CreateElement(element_id)); 193 args.Append(CreateElement(element_id));
196 scoped_ptr<base::Value> result; 194 scoped_ptr<base::Value> result;
197 return web_view->CallFunction( 195 return web_view->CallFunction(
198 session->frame, 196 session->GetCurrentFrameId(),
199 webdriver::atoms::asString(webdriver::atoms::CLEAR), 197 webdriver::atoms::asString(webdriver::atoms::CLEAR),
200 args, &result); 198 args, &result);
201 } 199 }
202 200
203 Status ExecuteSendKeysToElement( 201 Status ExecuteSendKeysToElement(
204 Session* session, 202 Session* session,
205 WebView* web_view, 203 WebView* web_view,
206 const std::string& element_id, 204 const std::string& element_id,
207 const base::DictionaryValue& params, 205 const base::DictionaryValue& params,
208 scoped_ptr<base::Value>* value) { 206 scoped_ptr<base::Value>* value) {
(...skipping 25 matching lines...) Expand all
234 232
235 Status ExecuteSubmitElement( 233 Status ExecuteSubmitElement(
236 Session* session, 234 Session* session,
237 WebView* web_view, 235 WebView* web_view,
238 const std::string& element_id, 236 const std::string& element_id,
239 const base::DictionaryValue& params, 237 const base::DictionaryValue& params,
240 scoped_ptr<base::Value>* value) { 238 scoped_ptr<base::Value>* value) {
241 base::ListValue args; 239 base::ListValue args;
242 args.Append(CreateElement(element_id)); 240 args.Append(CreateElement(element_id));
243 return web_view->CallFunction( 241 return web_view->CallFunction(
244 session->frame, 242 session->GetCurrentFrameId(),
245 webdriver::atoms::asString(webdriver::atoms::SUBMIT), 243 webdriver::atoms::asString(webdriver::atoms::SUBMIT),
246 args, 244 args,
247 value); 245 value);
248 } 246 }
249 247
250 Status ExecuteGetElementText( 248 Status ExecuteGetElementText(
251 Session* session, 249 Session* session,
252 WebView* web_view, 250 WebView* web_view,
253 const std::string& element_id, 251 const std::string& element_id,
254 const base::DictionaryValue& params, 252 const base::DictionaryValue& params,
255 scoped_ptr<base::Value>* value) { 253 scoped_ptr<base::Value>* value) {
256 base::ListValue args; 254 base::ListValue args;
257 args.Append(CreateElement(element_id)); 255 args.Append(CreateElement(element_id));
258 return web_view->CallFunction( 256 return web_view->CallFunction(
259 session->frame, 257 session->GetCurrentFrameId(),
260 webdriver::atoms::asString(webdriver::atoms::GET_TEXT), 258 webdriver::atoms::asString(webdriver::atoms::GET_TEXT),
261 args, 259 args,
262 value); 260 value);
263 } 261 }
264 262
265 Status ExecuteGetElementValue( 263 Status ExecuteGetElementValue(
266 Session* session, 264 Session* session,
267 WebView* web_view, 265 WebView* web_view,
268 const std::string& element_id, 266 const std::string& element_id,
269 const base::DictionaryValue& params, 267 const base::DictionaryValue& params,
270 scoped_ptr<base::Value>* value) { 268 scoped_ptr<base::Value>* value) {
271 base::ListValue args; 269 base::ListValue args;
272 args.Append(CreateElement(element_id)); 270 args.Append(CreateElement(element_id));
273 return web_view->CallFunction( 271 return web_view->CallFunction(
274 session->frame, 272 session->GetCurrentFrameId(),
275 "function(elem) { return elem['value'] }", 273 "function(elem) { return elem['value'] }",
276 args, 274 args,
277 value); 275 value);
278 } 276 }
279 277
280 Status ExecuteGetElementTagName( 278 Status ExecuteGetElementTagName(
281 Session* session, 279 Session* session,
282 WebView* web_view, 280 WebView* web_view,
283 const std::string& element_id, 281 const std::string& element_id,
284 const base::DictionaryValue& params, 282 const base::DictionaryValue& params,
285 scoped_ptr<base::Value>* value) { 283 scoped_ptr<base::Value>* value) {
286 base::ListValue args; 284 base::ListValue args;
287 args.Append(CreateElement(element_id)); 285 args.Append(CreateElement(element_id));
288 return web_view->CallFunction( 286 return web_view->CallFunction(
289 session->frame, 287 session->GetCurrentFrameId(),
290 "function(elem) { return elem.tagName.toLowerCase() }", 288 "function(elem) { return elem.tagName.toLowerCase() }",
291 args, 289 args,
292 value); 290 value);
293 } 291 }
294 292
295 Status ExecuteIsElementSelected( 293 Status ExecuteIsElementSelected(
296 Session* session, 294 Session* session,
297 WebView* web_view, 295 WebView* web_view,
298 const std::string& element_id, 296 const std::string& element_id,
299 const base::DictionaryValue& params, 297 const base::DictionaryValue& params,
300 scoped_ptr<base::Value>* value) { 298 scoped_ptr<base::Value>* value) {
301 base::ListValue args; 299 base::ListValue args;
302 args.Append(CreateElement(element_id)); 300 args.Append(CreateElement(element_id));
303 return web_view->CallFunction( 301 return web_view->CallFunction(
304 session->frame, 302 session->GetCurrentFrameId(),
305 webdriver::atoms::asString(webdriver::atoms::IS_SELECTED), 303 webdriver::atoms::asString(webdriver::atoms::IS_SELECTED),
306 args, 304 args,
307 value); 305 value);
308 } 306 }
309 307
310 Status ExecuteIsElementEnabled( 308 Status ExecuteIsElementEnabled(
311 Session* session, 309 Session* session,
312 WebView* web_view, 310 WebView* web_view,
313 const std::string& element_id, 311 const std::string& element_id,
314 const base::DictionaryValue& params, 312 const base::DictionaryValue& params,
315 scoped_ptr<base::Value>* value) { 313 scoped_ptr<base::Value>* value) {
316 base::ListValue args; 314 base::ListValue args;
317 args.Append(CreateElement(element_id)); 315 args.Append(CreateElement(element_id));
318 return web_view->CallFunction( 316 return web_view->CallFunction(
319 session->frame, 317 session->GetCurrentFrameId(),
320 webdriver::atoms::asString(webdriver::atoms::IS_ENABLED), 318 webdriver::atoms::asString(webdriver::atoms::IS_ENABLED),
321 args, 319 args,
322 value); 320 value);
323 } 321 }
324 322
325 Status ExecuteIsElementDisplayed( 323 Status ExecuteIsElementDisplayed(
326 Session* session, 324 Session* session,
327 WebView* web_view, 325 WebView* web_view,
328 const std::string& element_id, 326 const std::string& element_id,
329 const base::DictionaryValue& params, 327 const base::DictionaryValue& params,
330 scoped_ptr<base::Value>* value) { 328 scoped_ptr<base::Value>* value) {
331 base::ListValue args; 329 base::ListValue args;
332 args.Append(CreateElement(element_id)); 330 args.Append(CreateElement(element_id));
333 return web_view->CallFunction( 331 return web_view->CallFunction(
334 session->frame, 332 session->GetCurrentFrameId(),
335 webdriver::atoms::asString(webdriver::atoms::IS_DISPLAYED), 333 webdriver::atoms::asString(webdriver::atoms::IS_DISPLAYED),
336 args, 334 args,
337 value); 335 value);
338 } 336 }
339 337
340 Status ExecuteGetElementLocation( 338 Status ExecuteGetElementLocation(
341 Session* session, 339 Session* session,
342 WebView* web_view, 340 WebView* web_view,
343 const std::string& element_id, 341 const std::string& element_id,
344 const base::DictionaryValue& params, 342 const base::DictionaryValue& params,
345 scoped_ptr<base::Value>* value) { 343 scoped_ptr<base::Value>* value) {
346 base::ListValue args; 344 base::ListValue args;
347 args.Append(CreateElement(element_id)); 345 args.Append(CreateElement(element_id));
348 return web_view->CallFunction( 346 return web_view->CallFunction(
349 session->frame, 347 session->GetCurrentFrameId(),
350 webdriver::atoms::asString(webdriver::atoms::GET_LOCATION), 348 webdriver::atoms::asString(webdriver::atoms::GET_LOCATION),
351 args, 349 args,
352 value); 350 value);
353 } 351 }
354 352
355 Status ExecuteGetElementLocationOnceScrolledIntoView( 353 Status ExecuteGetElementLocationOnceScrolledIntoView(
356 Session* session, 354 Session* session,
357 WebView* web_view, 355 WebView* web_view,
358 const std::string& element_id, 356 const std::string& element_id,
359 const base::DictionaryValue& params, 357 const base::DictionaryValue& params,
360 scoped_ptr<base::Value>* value) { 358 scoped_ptr<base::Value>* value) {
361 base::ListValue args; 359 base::ListValue args;
362 args.Append(CreateElement(element_id)); 360 args.Append(CreateElement(element_id));
363 return web_view->CallFunction( 361 return web_view->CallFunction(
364 session->frame, 362 session->GetCurrentFrameId(),
365 webdriver::atoms::asString(webdriver::atoms::GET_LOCATION_IN_VIEW), 363 webdriver::atoms::asString(webdriver::atoms::GET_LOCATION_IN_VIEW),
366 args, 364 args,
367 value); 365 value);
368 } 366 }
369 367
370 Status ExecuteGetElementSize( 368 Status ExecuteGetElementSize(
371 Session* session, 369 Session* session,
372 WebView* web_view, 370 WebView* web_view,
373 const std::string& element_id, 371 const std::string& element_id,
374 const base::DictionaryValue& params, 372 const base::DictionaryValue& params,
375 scoped_ptr<base::Value>* value) { 373 scoped_ptr<base::Value>* value) {
376 base::ListValue args; 374 base::ListValue args;
377 args.Append(CreateElement(element_id)); 375 args.Append(CreateElement(element_id));
378 return web_view->CallFunction( 376 return web_view->CallFunction(
379 session->frame, 377 session->GetCurrentFrameId(),
380 webdriver::atoms::asString(webdriver::atoms::GET_SIZE), 378 webdriver::atoms::asString(webdriver::atoms::GET_SIZE),
381 args, 379 args,
382 value); 380 value);
383 } 381 }
384 382
385 Status ExecuteGetElementAttribute( 383 Status ExecuteGetElementAttribute(
386 Session* session, 384 Session* session,
387 WebView* web_view, 385 WebView* web_view,
388 const std::string& element_id, 386 const std::string& element_id,
389 const base::DictionaryValue& params, 387 const base::DictionaryValue& params,
390 scoped_ptr<base::Value>* value) { 388 scoped_ptr<base::Value>* value) {
391 std::string name; 389 std::string name;
392 if (!params.GetString("name", &name)) 390 if (!params.GetString("name", &name))
393 return Status(kUnknownError, "missing 'name'"); 391 return Status(kUnknownError, "missing 'name'");
394 return GetElementAttribute(session, web_view, element_id, name, value); 392 return GetElementAttribute(session, web_view, element_id, name, value);
395 } 393 }
396 394
397 Status ExecuteGetElementValueOfCSSProperty( 395 Status ExecuteGetElementValueOfCSSProperty(
398 Session* session, 396 Session* session,
399 WebView* web_view, 397 WebView* web_view,
400 const std::string& element_id, 398 const std::string& element_id,
401 const base::DictionaryValue& params, 399 const base::DictionaryValue& params,
402 scoped_ptr<base::Value>* value) { 400 scoped_ptr<base::Value>* value) {
403 base::ListValue args; 401 base::ListValue args;
404 args.Append(CreateElement(element_id)); 402 args.Append(CreateElement(element_id));
405 return web_view->CallFunction( 403 return web_view->CallFunction(
406 session->frame, 404 session->GetCurrentFrameId(),
407 webdriver::atoms::asString(webdriver::atoms::GET_EFFECTIVE_STYLE), 405 webdriver::atoms::asString(webdriver::atoms::GET_EFFECTIVE_STYLE),
408 args, 406 args,
409 value); 407 value);
410 } 408 }
411 409
412 Status ExecuteElementEquals( 410 Status ExecuteElementEquals(
413 Session* session, 411 Session* session,
414 WebView* web_view, 412 WebView* web_view,
415 const std::string& element_id, 413 const std::string& element_id,
416 const base::DictionaryValue& params, 414 const base::DictionaryValue& params,
417 scoped_ptr<base::Value>* value) { 415 scoped_ptr<base::Value>* value) {
418 std::string other_element_id; 416 std::string other_element_id;
419 if (!params.GetString("other", &other_element_id)) 417 if (!params.GetString("other", &other_element_id))
420 return Status(kUnknownError, "'other' must be a string"); 418 return Status(kUnknownError, "'other' must be a string");
421 value->reset(new base::FundamentalValue(element_id == other_element_id)); 419 value->reset(new base::FundamentalValue(element_id == other_element_id));
422 return Status(kOk); 420 return Status(kOk);
423 } 421 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/commands_unittest.cc ('k') | chrome/test/chromedriver/element_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698