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

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

Issue 2230053002: [chromedriver] Added option to make element references W3C compliant. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed presubmit errors. Created 4 years, 4 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
« no previous file with comments | « chrome/test/chromedriver/commands.cc ('k') | chrome/test/chromedriver/js/call_function.js » ('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_util.h" 5 #include "chrome/test/chromedriver/element_util.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/test/chromedriver/basic_types.h" 15 #include "chrome/test/chromedriver/basic_types.h"
16 #include "chrome/test/chromedriver/chrome/chrome.h" 16 #include "chrome/test/chromedriver/chrome/chrome.h"
17 #include "chrome/test/chromedriver/chrome/js.h" 17 #include "chrome/test/chromedriver/chrome/js.h"
18 #include "chrome/test/chromedriver/chrome/status.h" 18 #include "chrome/test/chromedriver/chrome/status.h"
19 #include "chrome/test/chromedriver/chrome/web_view.h" 19 #include "chrome/test/chromedriver/chrome/web_view.h"
20 #include "chrome/test/chromedriver/session.h" 20 #include "chrome/test/chromedriver/session.h"
21 #include "third_party/webdriver/atoms.h" 21 #include "third_party/webdriver/atoms.h"
22 22
23 namespace { 23 namespace {
24 24
25 const char kElementKey[] = "ELEMENT"; 25 const char kElementKey[] = "ELEMENT";
26 const char kElementKeyW3C[] = "element-6066-11e4-a52e-4f735466cecf";
27
28 std::string GetElementKey() {
29 Session* session = GetThreadLocalSession();
30 CHECK(session);
31 if (session->w3c_compliant)
32 return kElementKeyW3C;
33 else
34 return kElementKey;
35 }
26 36
27 bool ParseFromValue(base::Value* value, WebPoint* point) { 37 bool ParseFromValue(base::Value* value, WebPoint* point) {
28 base::DictionaryValue* dict_value; 38 base::DictionaryValue* dict_value;
29 if (!value->GetAsDictionary(&dict_value)) 39 if (!value->GetAsDictionary(&dict_value))
30 return false; 40 return false;
31 double x = 0; 41 double x = 0;
32 double y = 0; 42 double y = 0;
33 if (!dict_value->GetDouble("x", &x) || 43 if (!dict_value->GetDouble("x", &x) ||
34 !dict_value->GetDouble("y", &y)) 44 !dict_value->GetDouble("y", &y))
35 return false; 45 return false;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return Status(kUnknownError, "failed to get border width of element"); 212 return Status(kUnknownError, "failed to get border width of element");
203 *border_left = border_left_tmp; 213 *border_left = border_left_tmp;
204 *border_top = border_top_tmp; 214 *border_top = border_top_tmp;
205 return Status(kOk); 215 return Status(kOk);
206 } 216 }
207 217
208 } // namespace 218 } // namespace
209 219
210 base::DictionaryValue* CreateElement(const std::string& element_id) { 220 base::DictionaryValue* CreateElement(const std::string& element_id) {
211 base::DictionaryValue* element = new base::DictionaryValue(); 221 base::DictionaryValue* element = new base::DictionaryValue();
212 element->SetString(kElementKey, element_id); 222 element->SetString(GetElementKey(), element_id);
213 return element; 223 return element;
214 } 224 }
215 225
216 base::Value* CreateValueFrom(const WebPoint& point) { 226 base::Value* CreateValueFrom(const WebPoint& point) {
217 base::DictionaryValue* dict = new base::DictionaryValue(); 227 base::DictionaryValue* dict = new base::DictionaryValue();
218 dict->SetInteger("x", point.x); 228 dict->SetInteger("x", point.x);
219 dict->SetInteger("y", point.y); 229 dict->SetInteger("y", point.y);
220 return dict; 230 return dict;
221 } 231 }
222 232
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return status; 265 return status;
256 266
257 if (!temp->IsType(base::Value::TYPE_NULL)) { 267 if (!temp->IsType(base::Value::TYPE_NULL)) {
258 if (only_one) { 268 if (only_one) {
259 value->reset(temp.release()); 269 value->reset(temp.release());
260 return Status(kOk); 270 return Status(kOk);
261 } else { 271 } else {
262 base::ListValue* result; 272 base::ListValue* result;
263 if (!temp->GetAsList(&result)) 273 if (!temp->GetAsList(&result))
264 return Status(kUnknownError, "script returns unexpected result"); 274 return Status(kUnknownError, "script returns unexpected result");
265
266 if (result->GetSize() > 0U) { 275 if (result->GetSize() > 0U) {
267 value->reset(temp.release()); 276 value->reset(temp.release());
268 return Status(kOk); 277 return Status(kOk);
269 } 278 }
270 } 279 }
271 } 280 }
272 281
273 if (base::TimeTicks::Now() - start_time >= session->implicit_wait) { 282 if (base::TimeTicks::Now() - start_time >= session->implicit_wait) {
274 if (only_one) { 283 if (only_one) {
275 return Status(kNoSuchElement, "Unable to locate element: {\"method\":\"" 284 return Status(kNoSuchElement, "Unable to locate element: {\"method\":\""
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 "}"; 384 "}";
376 base::ListValue args; 385 base::ListValue args;
377 args.Append(CreateElement(element_id)); 386 args.Append(CreateElement(element_id));
378 std::unique_ptr<base::Value> result; 387 std::unique_ptr<base::Value> result;
379 status = web_view->CallFunction( 388 status = web_view->CallFunction(
380 session->GetCurrentFrameId(), kGetImageElementForArea, args, &result); 389 session->GetCurrentFrameId(), kGetImageElementForArea, args, &result);
381 if (status.IsError()) 390 if (status.IsError())
382 return status; 391 return status;
383 const base::DictionaryValue* element_dict; 392 const base::DictionaryValue* element_dict;
384 if (!result->GetAsDictionary(&element_dict) || 393 if (!result->GetAsDictionary(&element_dict) ||
385 !element_dict->GetString(kElementKey, &target_element_id)) 394 !element_dict->GetString(GetElementKey(), &target_element_id))
386 return Status(kUnknownError, "no element reference returned by script"); 395 return Status(kUnknownError, "no element reference returned by script");
387 } 396 }
388 bool is_displayed = false; 397 bool is_displayed = false;
389 status = IsElementDisplayed( 398 status = IsElementDisplayed(
390 session, web_view, target_element_id, true, &is_displayed); 399 session, web_view, target_element_id, true, &is_displayed);
391 if (status.IsError()) 400 if (status.IsError())
392 return status; 401 return status;
393 if (!is_displayed) 402 if (!is_displayed)
394 return Status(kElementNotVisible); 403 return Status(kElementNotVisible);
395 404
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 rit->chromedriver_frame_id.c_str())); 632 rit->chromedriver_frame_id.c_str()));
624 std::unique_ptr<base::Value> result; 633 std::unique_ptr<base::Value> result;
625 status = web_view->CallFunction( 634 status = web_view->CallFunction(
626 rit->parent_frame_id, kFindSubFrameScript, args, &result); 635 rit->parent_frame_id, kFindSubFrameScript, args, &result);
627 if (status.IsError()) 636 if (status.IsError())
628 return status; 637 return status;
629 const base::DictionaryValue* element_dict; 638 const base::DictionaryValue* element_dict;
630 if (!result->GetAsDictionary(&element_dict)) 639 if (!result->GetAsDictionary(&element_dict))
631 return Status(kUnknownError, "no element reference returned by script"); 640 return Status(kUnknownError, "no element reference returned by script");
632 std::string frame_element_id; 641 std::string frame_element_id;
633 if (!element_dict->GetString(kElementKey, &frame_element_id)) 642 if (!element_dict->GetString(GetElementKey(), &frame_element_id))
634 return Status(kUnknownError, "failed to locate a sub frame"); 643 return Status(kUnknownError, "failed to locate a sub frame");
635 644
636 // Modify |region_offset| by the frame's border. 645 // Modify |region_offset| by the frame's border.
637 int border_left = -1; 646 int border_left = -1;
638 int border_top = -1; 647 int border_top = -1;
639 status = GetElementBorder( 648 status = GetElementBorder(
640 rit->parent_frame_id, web_view, frame_element_id, 649 rit->parent_frame_id, web_view, frame_element_id,
641 &border_left, &border_top); 650 &border_left, &border_top);
642 if (status.IsError()) 651 if (status.IsError())
643 return status; 652 return status;
644 region_offset.Offset(border_left, border_top); 653 region_offset.Offset(border_left, border_top);
645 654
646 status = ScrollElementRegionIntoViewHelper( 655 status = ScrollElementRegionIntoViewHelper(
647 rit->parent_frame_id, web_view, frame_element_id, 656 rit->parent_frame_id, web_view, frame_element_id,
648 WebRect(region_offset, region_size), 657 WebRect(region_offset, region_size),
649 center, frame_element_id, &region_offset); 658 center, frame_element_id, &region_offset);
650 if (status.IsError()) 659 if (status.IsError())
651 return status; 660 return status;
652 } 661 }
653 *location = region_offset; 662 *location = region_offset;
654 return Status(kOk); 663 return Status(kOk);
655 } 664 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/commands.cc ('k') | chrome/test/chromedriver/js/call_function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698