Chromium Code Reviews| 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/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 WebPoint middle = tmp_location; | 151 WebPoint middle = tmp_location; |
| 152 middle.Offset(region.Width() / 2, region.Height() / 2); | 152 middle.Offset(region.Width() / 2, region.Height() / 2); |
| 153 status = VerifyElementClickable(frame, web_view, element_id, middle); | 153 status = VerifyElementClickable(frame, web_view, element_id, middle); |
| 154 if (status.IsError()) | 154 if (status.IsError()) |
| 155 return status; | 155 return status; |
| 156 } | 156 } |
| 157 *location = tmp_location; | 157 *location = tmp_location; |
| 158 return Status(kOk); | 158 return Status(kOk); |
| 159 } | 159 } |
| 160 | 160 |
| 161 Status GetElementEffectiveStyle( | |
| 162 const std::string& frame, | |
| 163 WebView* web_view, | |
| 164 const std::string& element_id, | |
| 165 const std::string& property, | |
| 166 std::string* value) { | |
| 167 base::ListValue args; | |
| 168 args.Append(CreateElement(element_id)); | |
| 169 args.AppendString(property); | |
| 170 scoped_ptr<base::Value> result; | |
| 171 Status status = web_view->CallFunction( | |
| 172 frame, webdriver::atoms::asString(webdriver::atoms::GET_EFFECTIVE_STYLE), | |
| 173 args, &result); | |
| 174 if (status.IsError()) | |
| 175 return status; | |
| 176 if (!result->GetAsString(value)) | |
| 177 return Status(kUnknownError, "fail to parse value of GET_EFFECTIVE_STYLE"); | |
| 178 return Status(kOk); | |
| 179 } | |
| 180 | |
| 181 Status GetElementBorder( | 161 Status GetElementBorder( |
| 182 const std::string& frame, | 162 const std::string& frame, |
| 183 WebView* web_view, | 163 WebView* web_view, |
| 184 const std::string& element_id, | 164 const std::string& element_id, |
| 185 int* border_left, | 165 int* border_left, |
| 186 int* border_top) { | 166 int* border_top) { |
| 187 std::string border_left_str; | 167 std::string border_left_str; |
| 188 Status status = GetElementEffectiveStyle( | 168 Status status = GetElementEffectiveStyle( |
| 189 frame, web_view, element_id, "border-left-width", &border_left_str); | 169 frame, web_view, element_id, "border-left-width", &border_left_str); |
| 190 if (status.IsError()) | 170 if (status.IsError()) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 | 313 |
| 334 status = ScrollElementRegionIntoView( | 314 status = ScrollElementRegionIntoView( |
| 335 session, web_view, element_id, rect, | 315 session, web_view, element_id, rect, |
| 336 true /* center */, true /* verify_clickable */, location); | 316 true /* center */, true /* verify_clickable */, location); |
| 337 if (status.IsError()) | 317 if (status.IsError()) |
| 338 return status; | 318 return status; |
| 339 location->Offset(rect.Width() / 2, rect.Height() / 2); | 319 location->Offset(rect.Width() / 2, rect.Height() / 2); |
| 340 return Status(kOk); | 320 return Status(kOk); |
| 341 } | 321 } |
| 342 | 322 |
| 323 Status GetElementEffectiveStyle( | |
| 324 const std::string& frame, | |
|
kkania
2013/04/18 00:38:52
i think it would make sense for the webview to be
chrisgao (Use stgao instead)
2013/04/18 01:39:48
Fix in the established convention here.
| |
| 325 WebView* web_view, | |
| 326 const std::string& element_id, | |
| 327 const std::string& property, | |
| 328 std::string* value) { | |
| 329 base::ListValue args; | |
| 330 args.Append(CreateElement(element_id)); | |
| 331 args.AppendString(property); | |
| 332 scoped_ptr<base::Value> result; | |
| 333 Status status = web_view->CallFunction( | |
| 334 frame, webdriver::atoms::asString(webdriver::atoms::GET_EFFECTIVE_STYLE), | |
| 335 args, &result); | |
| 336 if (status.IsError()) | |
| 337 return status; | |
| 338 if (!result->GetAsString(value)) | |
| 339 return Status(kUnknownError, "fail to parse value of GET_EFFECTIVE_STYLE"); | |
|
kkania
2013/04/18 00:38:52
failed
chrisgao (Use stgao instead)
2013/04/18 01:39:48
Done.
| |
| 340 return Status(kOk); | |
| 341 } | |
| 342 | |
| 343 Status GetElementRegion( | 343 Status GetElementRegion( |
| 344 Session* session, | 344 Session* session, |
| 345 WebView* web_view, | 345 WebView* web_view, |
| 346 const std::string& element_id, | 346 const std::string& element_id, |
| 347 WebRect* rect) { | 347 WebRect* rect) { |
| 348 base::ListValue args; | 348 base::ListValue args; |
| 349 args.Append(CreateElement(element_id)); | 349 args.Append(CreateElement(element_id)); |
| 350 scoped_ptr<base::Value> result; | 350 scoped_ptr<base::Value> result; |
| 351 Status status = web_view->CallFunction( | 351 Status status = web_view->CallFunction( |
| 352 session->GetCurrentFrameId(), kGetElementRegionScript, args, &result); | 352 session->GetCurrentFrameId(), kGetElementRegionScript, args, &result); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 status = ScrollElementRegionIntoViewHelper( | 562 status = ScrollElementRegionIntoViewHelper( |
| 563 rit->parent_frame_id, web_view, frame_element_id, | 563 rit->parent_frame_id, web_view, frame_element_id, |
| 564 WebRect(region_offset, region_size), | 564 WebRect(region_offset, region_size), |
| 565 center, verify_clickable, ®ion_offset); | 565 center, verify_clickable, ®ion_offset); |
| 566 if (status.IsError()) | 566 if (status.IsError()) |
| 567 return status; | 567 return status; |
| 568 } | 568 } |
| 569 *location = region_offset; | 569 *location = region_offset; |
| 570 return Status(kOk); | 570 return Status(kOk); |
| 571 } | 571 } |
| OLD | NEW |