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

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: Rebased code with w3c flag change. 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
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();
samuong 2016/08/11 18:13:20 put a CHECK(session) here, just in case
roisinmcl 2016/08/13 01:47:26 Done.
30 if (session->w3c_compliant)
31 return kElementKeyW3C;
32 else
33 return kElementKey;
34 }
26 35
27 bool ParseFromValue(base::Value* value, WebPoint* point) { 36 bool ParseFromValue(base::Value* value, WebPoint* point) {
28 base::DictionaryValue* dict_value; 37 base::DictionaryValue* dict_value;
29 if (!value->GetAsDictionary(&dict_value)) 38 if (!value->GetAsDictionary(&dict_value))
30 return false; 39 return false;
31 double x = 0; 40 double x = 0;
32 double y = 0; 41 double y = 0;
33 if (!dict_value->GetDouble("x", &x) || 42 if (!dict_value->GetDouble("x", &x) ||
34 !dict_value->GetDouble("y", &y)) 43 !dict_value->GetDouble("y", &y))
35 return false; 44 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"); 211 return Status(kUnknownError, "failed to get border width of element");
203 *border_left = border_left_tmp; 212 *border_left = border_left_tmp;
204 *border_top = border_top_tmp; 213 *border_top = border_top_tmp;
205 return Status(kOk); 214 return Status(kOk);
206 } 215 }
207 216
208 } // namespace 217 } // namespace
209 218
210 base::DictionaryValue* CreateElement(const std::string& element_id) { 219 base::DictionaryValue* CreateElement(const std::string& element_id) {
211 base::DictionaryValue* element = new base::DictionaryValue(); 220 base::DictionaryValue* element = new base::DictionaryValue();
212 element->SetString(kElementKey, element_id); 221 element->SetString(GetElementKey(), element_id);
213 return element; 222 return element;
214 } 223 }
215 224
216 base::Value* CreateValueFrom(const WebPoint& point) { 225 base::Value* CreateValueFrom(const WebPoint& point) {
217 base::DictionaryValue* dict = new base::DictionaryValue(); 226 base::DictionaryValue* dict = new base::DictionaryValue();
218 dict->SetInteger("x", point.x); 227 dict->SetInteger("x", point.x);
219 dict->SetInteger("y", point.y); 228 dict->SetInteger("y", point.y);
220 return dict; 229 return dict;
221 } 230 }
222 231
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return status; 264 return status;
256 265
257 if (!temp->IsType(base::Value::TYPE_NULL)) { 266 if (!temp->IsType(base::Value::TYPE_NULL)) {
258 if (only_one) { 267 if (only_one) {
259 value->reset(temp.release()); 268 value->reset(temp.release());
260 return Status(kOk); 269 return Status(kOk);
261 } else { 270 } else {
262 base::ListValue* result; 271 base::ListValue* result;
263 if (!temp->GetAsList(&result)) 272 if (!temp->GetAsList(&result))
264 return Status(kUnknownError, "script returns unexpected result"); 273 return Status(kUnknownError, "script returns unexpected result");
265
266 if (result->GetSize() > 0U) { 274 if (result->GetSize() > 0U) {
267 value->reset(temp.release()); 275 value->reset(temp.release());
268 return Status(kOk); 276 return Status(kOk);
269 } 277 }
270 } 278 }
271 } 279 }
272 280
273 if (base::TimeTicks::Now() - start_time >= session->implicit_wait) { 281 if (base::TimeTicks::Now() - start_time >= session->implicit_wait) {
274 if (only_one) { 282 if (only_one) {
275 return Status(kNoSuchElement, "Unable to locate element: {\"method\":\"" 283 return Status(kNoSuchElement, "Unable to locate element: {\"method\":\""
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 "}"; 383 "}";
376 base::ListValue args; 384 base::ListValue args;
377 args.Append(CreateElement(element_id)); 385 args.Append(CreateElement(element_id));
378 std::unique_ptr<base::Value> result; 386 std::unique_ptr<base::Value> result;
379 status = web_view->CallFunction( 387 status = web_view->CallFunction(
380 session->GetCurrentFrameId(), kGetImageElementForArea, args, &result); 388 session->GetCurrentFrameId(), kGetImageElementForArea, args, &result);
381 if (status.IsError()) 389 if (status.IsError())
382 return status; 390 return status;
383 const base::DictionaryValue* element_dict; 391 const base::DictionaryValue* element_dict;
384 if (!result->GetAsDictionary(&element_dict) || 392 if (!result->GetAsDictionary(&element_dict) ||
385 !element_dict->GetString(kElementKey, &target_element_id)) 393 !element_dict->GetString(GetElementKey(), &target_element_id))
386 return Status(kUnknownError, "no element reference returned by script"); 394 return Status(kUnknownError, "no element reference returned by script");
387 } 395 }
388 bool is_displayed = false; 396 bool is_displayed = false;
389 status = IsElementDisplayed( 397 status = IsElementDisplayed(
390 session, web_view, target_element_id, true, &is_displayed); 398 session, web_view, target_element_id, true, &is_displayed);
391 if (status.IsError()) 399 if (status.IsError())
392 return status; 400 return status;
393 if (!is_displayed) 401 if (!is_displayed)
394 return Status(kElementNotVisible); 402 return Status(kElementNotVisible);
395 403
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 rit->chromedriver_frame_id.c_str())); 631 rit->chromedriver_frame_id.c_str()));
624 std::unique_ptr<base::Value> result; 632 std::unique_ptr<base::Value> result;
625 status = web_view->CallFunction( 633 status = web_view->CallFunction(
626 rit->parent_frame_id, kFindSubFrameScript, args, &result); 634 rit->parent_frame_id, kFindSubFrameScript, args, &result);
627 if (status.IsError()) 635 if (status.IsError())
628 return status; 636 return status;
629 const base::DictionaryValue* element_dict; 637 const base::DictionaryValue* element_dict;
630 if (!result->GetAsDictionary(&element_dict)) 638 if (!result->GetAsDictionary(&element_dict))
631 return Status(kUnknownError, "no element reference returned by script"); 639 return Status(kUnknownError, "no element reference returned by script");
632 std::string frame_element_id; 640 std::string frame_element_id;
633 if (!element_dict->GetString(kElementKey, &frame_element_id)) 641 if (!element_dict->GetString(GetElementKey(), &frame_element_id))
634 return Status(kUnknownError, "failed to locate a sub frame"); 642 return Status(kUnknownError, "failed to locate a sub frame");
635 643
636 // Modify |region_offset| by the frame's border. 644 // Modify |region_offset| by the frame's border.
637 int border_left = -1; 645 int border_left = -1;
638 int border_top = -1; 646 int border_top = -1;
639 status = GetElementBorder( 647 status = GetElementBorder(
640 rit->parent_frame_id, web_view, frame_element_id, 648 rit->parent_frame_id, web_view, frame_element_id,
641 &border_left, &border_top); 649 &border_left, &border_top);
642 if (status.IsError()) 650 if (status.IsError())
643 return status; 651 return status;
644 region_offset.Offset(border_left, border_top); 652 region_offset.Offset(border_left, border_top);
645 653
646 status = ScrollElementRegionIntoViewHelper( 654 status = ScrollElementRegionIntoViewHelper(
647 rit->parent_frame_id, web_view, frame_element_id, 655 rit->parent_frame_id, web_view, frame_element_id,
648 WebRect(region_offset, region_size), 656 WebRect(region_offset, region_size),
649 center, frame_element_id, &region_offset); 657 center, frame_element_id, &region_offset);
650 if (status.IsError()) 658 if (status.IsError())
651 return status; 659 return status;
652 } 660 }
653 *location = region_offset; 661 *location = region_offset;
654 return Status(kOk); 662 return Status(kOk);
655 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698