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/window_commands.h" | 5 #include "chrome/test/chromedriver/window_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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 bool secure = false; | 114 bool secure = false; |
| 115 cookie_dict->GetBoolean("secure", &secure); | 115 cookie_dict->GetBoolean("secure", &secure); |
| 116 | 116 |
| 117 cookies_tmp.push_back( | 117 cookies_tmp.push_back( |
| 118 Cookie(name, value, domain, path, expiry, secure, session)); | 118 Cookie(name, value, domain, path, expiry, secure, session)); |
| 119 } | 119 } |
| 120 cookies->swap(cookies_tmp); | 120 cookies->swap(cookies_tmp); |
| 121 return Status(kOk); | 121 return Status(kOk); |
| 122 } | 122 } |
| 123 | 123 |
| 124 Status ScrollCoordinateInToView( | |
| 125 Session* session, WebView* web_view, int x, int y, int* xoffset, | |
| 126 int* yoffset) { | |
| 127 scoped_ptr<base::Value> value, ignored; | |
| 128 base::ListValue args; | |
| 129 args.AppendInteger(x); | |
| 130 args.AppendInteger(y); | |
| 131 Status status = web_view->CallFunction( | |
| 132 session->GetCurrentFrameId(), | |
|
frankf
2013/08/14 01:09:10
This is always the top frame right?
craigdh
2013/08/14 22:01:57
I believe so.
| |
| 133 "function(x, y) {" | |
| 134 " if (x < window.pageXOffset ||" | |
| 135 " x >= window.pageXOffset + window.innerWidth ||" | |
|
frankf
2013/08/14 01:09:10
Is scrollbar considered here?
craigdh
2013/08/14 22:01:57
yes, window.innerWidth is the width NOT including
| |
| 136 " y < window.pageYOffset ||" | |
| 137 " y >= window.pageYOffset + window.innerHeight) {" | |
| 138 " window.scrollTo(x - window.innerWidth/2, y - window.innerHeight/2);" | |
| 139 " }" | |
| 140 " return {" | |
| 141 " x: Math.floor(window.pageXOffset)," | |
| 142 " y: Math.floor(window.pageYOffset)," | |
| 143 " width: Math.floor(window.innerWidth)," | |
| 144 " height: Math.floor(window.innerHeight)};" | |
| 145 "}", | |
| 146 args, | |
| 147 &value); | |
| 148 if (!status.IsOk()) | |
| 149 return status; | |
| 150 base::DictionaryValue* window_attrib; | |
| 151 value->GetAsDictionary(&window_attrib); | |
| 152 int window_x, window_y, window_width, window_height; | |
| 153 window_attrib->GetInteger("x", &window_x); | |
|
frankf
2013/08/14 01:09:10
just have the same name ("window_x", &window_x)
craigdh
2013/08/14 22:01:57
Done.
| |
| 154 window_attrib->GetInteger("y", &window_y); | |
| 155 window_attrib->GetInteger("width", &window_width); | |
| 156 window_attrib->GetInteger("height", &window_height); | |
| 157 *xoffset = x - window_x; | |
|
frankf
2013/08/14 01:09:10
be consistant with naming: offset_x, window_x
craigdh
2013/08/14 22:01:57
Done.
| |
| 158 *yoffset = y - window_y; | |
| 159 if (*xoffset < 0 || *xoffset >= window_width || *yoffset < 0 || | |
| 160 *yoffset >= window_height) | |
| 161 return Status(kUnknownError, "Failed to scroll coordinate into view"); | |
| 162 return Status(kOk); | |
| 163 } | |
| 164 | |
| 165 Status ExecuteTouchEvent( | |
| 166 Session* session, WebView* web_view, TouchEventType type, | |
| 167 const base::DictionaryValue& params) { | |
| 168 int x, y; | |
| 169 if (!params.GetInteger("x", &x)) | |
| 170 return Status(kUnknownError, "'x' must be an integer"); | |
| 171 if (!params.GetInteger("y", &y)) | |
| 172 return Status(kUnknownError, "'y' must be an integer"); | |
| 173 int relative_x = x; | |
| 174 int relative_y = y; | |
| 175 Status status = ScrollCoordinateInToView( | |
| 176 session, web_view, x, y, &relative_x, &relative_y); | |
| 177 if (!status.IsOk()) | |
| 178 return status; | |
| 179 std::list<TouchEvent> events; | |
| 180 events.push_back( | |
| 181 TouchEvent(type, relative_x, relative_y)); | |
| 182 return web_view->DispatchTouchEvents(events); | |
| 183 } | |
| 184 | |
| 124 } // namespace | 185 } // namespace |
| 125 | 186 |
| 126 Status ExecuteWindowCommand( | 187 Status ExecuteWindowCommand( |
| 127 const WindowCommand& command, | 188 const WindowCommand& command, |
| 128 Session* session, | 189 Session* session, |
| 129 const base::DictionaryValue& params, | 190 const base::DictionaryValue& params, |
| 130 scoped_ptr<base::Value>* value) { | 191 scoped_ptr<base::Value>* value) { |
| 131 WebView* web_view = NULL; | 192 WebView* web_view = NULL; |
| 132 Status status = session->GetTargetWindow(&web_view); | 193 Status status = session->GetTargetWindow(&web_view); |
| 133 if (status.IsError()) | 194 if (status.IsError()) |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 MouseEvent(kPressedMouseEventType, button, | 553 MouseEvent(kPressedMouseEventType, button, |
| 493 session->mouse_position.x, session->mouse_position.y, | 554 session->mouse_position.x, session->mouse_position.y, |
| 494 session->sticky_modifiers, 2)); | 555 session->sticky_modifiers, 2)); |
| 495 events.push_back( | 556 events.push_back( |
| 496 MouseEvent(kReleasedMouseEventType, button, | 557 MouseEvent(kReleasedMouseEventType, button, |
| 497 session->mouse_position.x, session->mouse_position.y, | 558 session->mouse_position.x, session->mouse_position.y, |
| 498 session->sticky_modifiers, 2)); | 559 session->sticky_modifiers, 2)); |
| 499 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); | 560 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
| 500 } | 561 } |
| 501 | 562 |
| 563 Status ExecuteTouchDown( | |
| 564 Session* session, | |
| 565 WebView* web_view, | |
| 566 const base::DictionaryValue& params, | |
| 567 scoped_ptr<base::Value>* value) { | |
| 568 return ExecuteTouchEvent(session, web_view, kTouchStart, params); | |
| 569 } | |
| 570 | |
| 571 Status ExecuteTouchUp( | |
| 572 Session* session, | |
| 573 WebView* web_view, | |
| 574 const base::DictionaryValue& params, | |
| 575 scoped_ptr<base::Value>* value) { | |
| 576 return ExecuteTouchEvent(session, web_view, kTouchEnd, params); | |
| 577 } | |
| 578 | |
| 579 Status ExecuteTouchMove( | |
| 580 Session* session, | |
| 581 WebView* web_view, | |
| 582 const base::DictionaryValue& params, | |
| 583 scoped_ptr<base::Value>* value) { | |
| 584 return ExecuteTouchEvent(session, web_view, kTouchMove, params); | |
| 585 } | |
| 586 | |
| 502 Status ExecuteGetActiveElement( | 587 Status ExecuteGetActiveElement( |
| 503 Session* session, | 588 Session* session, |
| 504 WebView* web_view, | 589 WebView* web_view, |
| 505 const base::DictionaryValue& params, | 590 const base::DictionaryValue& params, |
| 506 scoped_ptr<base::Value>* value) { | 591 scoped_ptr<base::Value>* value) { |
| 507 base::ListValue args; | 592 base::ListValue args; |
| 508 return web_view->CallFunction( | 593 return web_view->CallFunction( |
| 509 session->GetCurrentFrameId(), | 594 session->GetCurrentFrameId(), |
| 510 "function() { return document.activeElement || document.body }", | 595 "function() { return document.activeElement || document.body }", |
| 511 args, | 596 args, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 // |accuracy| is not part of the WebDriver spec yet, so if it is not given | 840 // |accuracy| is not part of the WebDriver spec yet, so if it is not given |
| 756 // default to 100 meters accuracy. | 841 // default to 100 meters accuracy. |
| 757 geoposition.accuracy = 100; | 842 geoposition.accuracy = 100; |
| 758 } | 843 } |
| 759 | 844 |
| 760 Status status = web_view->OverrideGeolocation(geoposition); | 845 Status status = web_view->OverrideGeolocation(geoposition); |
| 761 if (status.IsOk()) | 846 if (status.IsOk()) |
| 762 session->overridden_geoposition.reset(new Geoposition(geoposition)); | 847 session->overridden_geoposition.reset(new Geoposition(geoposition)); |
| 763 return status; | 848 return status; |
| 764 } | 849 } |
| OLD | NEW |