OLD | NEW |
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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/test/chromedriver/basic_types.h" | 13 #include "chrome/test/chromedriver/basic_types.h" |
14 #include "chrome/test/chromedriver/chrome/chrome.h" | 14 #include "chrome/test/chromedriver/chrome/chrome.h" |
15 #include "chrome/test/chromedriver/chrome/js.h" | 15 #include "chrome/test/chromedriver/chrome/js.h" |
16 #include "chrome/test/chromedriver/chrome/status.h" | 16 #include "chrome/test/chromedriver/chrome/status.h" |
17 #include "chrome/test/chromedriver/chrome/version.h" | 17 #include "chrome/test/chromedriver/chrome/version.h" |
18 #include "chrome/test/chromedriver/chrome/web_view.h" | 18 #include "chrome/test/chromedriver/chrome/web_view.h" |
19 #include "chrome/test/chromedriver/session.h" | 19 #include "chrome/test/chromedriver/session.h" |
20 #include "third_party/webdriver/atoms.h" | 20 #include "third_party/webdriver/atoms.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kElementKey[] = "ELEMENT"; | 24 const char kElementKey[] = "ELEMENT"; |
25 | 25 |
26 bool ParseFromValue(base::Value* value, WebPoint* point) { | 26 bool ParseFromValue(base::Value* value, WebPoint* point) { |
27 base::DictionaryValue* dict_value; | 27 base::DictionaryValue* dict_value; |
28 if (!value->GetAsDictionary(&dict_value)) | 28 if (!value->GetAsDictionary(&dict_value)) |
29 return false; | 29 return false; |
30 double x, y; | 30 double x = 0; |
| 31 double y = 0; |
31 if (!dict_value->GetDouble("x", &x) || | 32 if (!dict_value->GetDouble("x", &x) || |
32 !dict_value->GetDouble("y", &y)) | 33 !dict_value->GetDouble("y", &y)) |
33 return false; | 34 return false; |
34 point->x = static_cast<int>(x); | 35 point->x = static_cast<int>(x); |
35 point->y = static_cast<int>(y); | 36 point->y = static_cast<int>(y); |
36 return true; | 37 return true; |
37 } | 38 } |
38 | 39 |
39 bool ParseFromValue(base::Value* value, WebSize* size) { | 40 bool ParseFromValue(base::Value* value, WebSize* size) { |
40 base::DictionaryValue* dict_value; | 41 base::DictionaryValue* dict_value; |
41 if (!value->GetAsDictionary(&dict_value)) | 42 if (!value->GetAsDictionary(&dict_value)) |
42 return false; | 43 return false; |
43 double width, height; | 44 double width = 0; |
| 45 double height = 0; |
44 if (!dict_value->GetDouble("width", &width) || | 46 if (!dict_value->GetDouble("width", &width) || |
45 !dict_value->GetDouble("height", &height)) | 47 !dict_value->GetDouble("height", &height)) |
46 return false; | 48 return false; |
47 size->width = static_cast<int>(width); | 49 size->width = static_cast<int>(width); |
48 size->height = static_cast<int>(height); | 50 size->height = static_cast<int>(height); |
49 return true; | 51 return true; |
50 } | 52 } |
51 | 53 |
52 bool ParseFromValue(base::Value* value, WebRect* rect) { | 54 bool ParseFromValue(base::Value* value, WebRect* rect) { |
53 base::DictionaryValue* dict_value; | 55 base::DictionaryValue* dict_value; |
54 if (!value->GetAsDictionary(&dict_value)) | 56 if (!value->GetAsDictionary(&dict_value)) |
55 return false; | 57 return false; |
56 double x, y, width, height; | 58 double x = 0; |
| 59 double y = 0; |
| 60 double width = 0; |
| 61 double height = 0; |
57 if (!dict_value->GetDouble("left", &x) || | 62 if (!dict_value->GetDouble("left", &x) || |
58 !dict_value->GetDouble("top", &y) || | 63 !dict_value->GetDouble("top", &y) || |
59 !dict_value->GetDouble("width", &width) || | 64 !dict_value->GetDouble("width", &width) || |
60 !dict_value->GetDouble("height", &height)) | 65 !dict_value->GetDouble("height", &height)) |
61 return false; | 66 return false; |
62 rect->origin.x = static_cast<int>(x); | 67 rect->origin.x = static_cast<int>(x); |
63 rect->origin.y = static_cast<int>(y); | 68 rect->origin.y = static_cast<int>(y); |
64 rect->size.width = static_cast<int>(width); | 69 rect->size.width = static_cast<int>(width); |
65 rect->size.height = static_cast<int>(height); | 70 rect->size.height = static_cast<int>(height); |
66 return true; | 71 return true; |
(...skipping 26 matching lines...) Expand all Loading... |
93 base::ListValue args; | 98 base::ListValue args; |
94 args.Append(CreateElement(element_id)); | 99 args.Append(CreateElement(element_id)); |
95 args.Append(CreateValueFrom(location)); | 100 args.Append(CreateValueFrom(location)); |
96 scoped_ptr<base::Value> result; | 101 scoped_ptr<base::Value> result; |
97 Status status = CallAtomsJs( | 102 Status status = CallAtomsJs( |
98 frame, web_view, webdriver::atoms::IS_ELEMENT_CLICKABLE, | 103 frame, web_view, webdriver::atoms::IS_ELEMENT_CLICKABLE, |
99 args, &result); | 104 args, &result); |
100 if (status.IsError()) | 105 if (status.IsError()) |
101 return status; | 106 return status; |
102 base::DictionaryValue* dict; | 107 base::DictionaryValue* dict; |
103 bool is_clickable; | 108 bool is_clickable = false; |
104 if (!result->GetAsDictionary(&dict) || | 109 if (!result->GetAsDictionary(&dict) || |
105 !dict->GetBoolean("clickable", &is_clickable)) { | 110 !dict->GetBoolean("clickable", &is_clickable)) { |
106 return Status(kUnknownError, | 111 return Status(kUnknownError, |
107 "failed to parse value of IS_ELEMENT_CLICKABLE"); | 112 "failed to parse value of IS_ELEMENT_CLICKABLE"); |
108 } | 113 } |
109 | 114 |
110 if (!is_clickable) { | 115 if (!is_clickable) { |
111 std::string message; | 116 std::string message; |
112 if (!dict->GetString("message", &message)) | 117 if (!dict->GetString("message", &message)) |
113 message = "element is not clickable"; | 118 message = "element is not clickable"; |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 status = ScrollElementRegionIntoViewHelper( | 650 status = ScrollElementRegionIntoViewHelper( |
646 rit->parent_frame_id, web_view, frame_element_id, | 651 rit->parent_frame_id, web_view, frame_element_id, |
647 WebRect(region_offset, region_size), | 652 WebRect(region_offset, region_size), |
648 center, frame_element_id, ®ion_offset); | 653 center, frame_element_id, ®ion_offset); |
649 if (status.IsError()) | 654 if (status.IsError()) |
650 return status; | 655 return status; |
651 } | 656 } |
652 *location = region_offset; | 657 *location = region_offset; |
653 return Status(kOk); | 658 return Status(kOk); |
654 } | 659 } |
OLD | NEW |