Chromium Code Reviews| Index: chrome/test/chromedriver/window_commands.cc |
| diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc |
| index cec74796246a2c03e592455ad658d9a733dc3cf9..225a43e94579fa21e3a8a6662ce6b26a68895524 100644 |
| --- a/chrome/test/chromedriver/window_commands.cc |
| +++ b/chrome/test/chromedriver/window_commands.cc |
| @@ -121,6 +121,67 @@ Status GetVisibleCookies(WebView* web_view, |
| return Status(kOk); |
| } |
| +Status ScrollCoordinateInToView( |
| + Session* session, WebView* web_view, int x, int y, int* xoffset, |
| + int* yoffset) { |
| + scoped_ptr<base::Value> value, ignored; |
| + base::ListValue args; |
| + args.AppendInteger(x); |
| + args.AppendInteger(y); |
| + Status status = web_view->CallFunction( |
| + 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.
|
| + "function(x, y) {" |
| + " if (x < window.pageXOffset ||" |
| + " 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
|
| + " y < window.pageYOffset ||" |
| + " y >= window.pageYOffset + window.innerHeight) {" |
| + " window.scrollTo(x - window.innerWidth/2, y - window.innerHeight/2);" |
| + " }" |
| + " return {" |
| + " x: Math.floor(window.pageXOffset)," |
| + " y: Math.floor(window.pageYOffset)," |
| + " width: Math.floor(window.innerWidth)," |
| + " height: Math.floor(window.innerHeight)};" |
| + "}", |
| + args, |
| + &value); |
| + if (!status.IsOk()) |
| + return status; |
| + base::DictionaryValue* window_attrib; |
| + value->GetAsDictionary(&window_attrib); |
| + int window_x, window_y, window_width, window_height; |
| + 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.
|
| + window_attrib->GetInteger("y", &window_y); |
| + window_attrib->GetInteger("width", &window_width); |
| + window_attrib->GetInteger("height", &window_height); |
| + *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.
|
| + *yoffset = y - window_y; |
| + if (*xoffset < 0 || *xoffset >= window_width || *yoffset < 0 || |
| + *yoffset >= window_height) |
| + return Status(kUnknownError, "Failed to scroll coordinate into view"); |
| + return Status(kOk); |
| +} |
| + |
| +Status ExecuteTouchEvent( |
| + Session* session, WebView* web_view, TouchEventType type, |
| + const base::DictionaryValue& params) { |
| + int x, y; |
| + if (!params.GetInteger("x", &x)) |
| + return Status(kUnknownError, "'x' must be an integer"); |
| + if (!params.GetInteger("y", &y)) |
| + return Status(kUnknownError, "'y' must be an integer"); |
| + int relative_x = x; |
| + int relative_y = y; |
| + Status status = ScrollCoordinateInToView( |
| + session, web_view, x, y, &relative_x, &relative_y); |
| + if (!status.IsOk()) |
| + return status; |
| + std::list<TouchEvent> events; |
| + events.push_back( |
| + TouchEvent(type, relative_x, relative_y)); |
| + return web_view->DispatchTouchEvents(events); |
| +} |
| + |
| } // namespace |
| Status ExecuteWindowCommand( |
| @@ -499,6 +560,30 @@ Status ExecuteMouseDoubleClick( |
| return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); |
| } |
| +Status ExecuteTouchDown( |
| + Session* session, |
| + WebView* web_view, |
| + const base::DictionaryValue& params, |
| + scoped_ptr<base::Value>* value) { |
| + return ExecuteTouchEvent(session, web_view, kTouchStart, params); |
| +} |
| + |
| +Status ExecuteTouchUp( |
| + Session* session, |
| + WebView* web_view, |
| + const base::DictionaryValue& params, |
| + scoped_ptr<base::Value>* value) { |
| + return ExecuteTouchEvent(session, web_view, kTouchEnd, params); |
| +} |
| + |
| +Status ExecuteTouchMove( |
| + Session* session, |
| + WebView* web_view, |
| + const base::DictionaryValue& params, |
| + scoped_ptr<base::Value>* value) { |
| + return ExecuteTouchEvent(session, web_view, kTouchMove, params); |
| +} |
| + |
| Status ExecuteGetActiveElement( |
| Session* session, |
| WebView* web_view, |