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

Unified Diff: chrome/test/chromedriver/window_commands.cc

Issue 22263003: [chromedriver] Implement touch down, up, and move commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/window_commands.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..88d8b1cb43c700073b08eef2fe55e5321f24ae4c 100644
--- a/chrome/test/chromedriver/window_commands.cc
+++ b/chrome/test/chromedriver/window_commands.cc
@@ -5,6 +5,7 @@
#include "chrome/test/chromedriver/window_commands.h"
#include <list>
+#include <string>
#include "base/callback.h"
#include "base/strings/string_number_conversions.h"
@@ -121,6 +122,67 @@ Status GetVisibleCookies(WebView* web_view,
return Status(kOk);
}
+Status ScrollCoordinateInToView(
+ Session* session, WebView* web_view, int x, int y, int* offset_x,
+ int* offset_y) {
+ scoped_ptr<base::Value> value;
+ base::ListValue args;
+ args.AppendInteger(x);
+ args.AppendInteger(y);
+ Status status = web_view->CallFunction(
+ std::string(),
+ "function(x, y) {"
+ " if (x < window.pageXOffset ||"
+ " x >= window.pageXOffset + window.innerWidth ||"
+ " y < window.pageYOffset ||"
+ " y >= window.pageYOffset + window.innerHeight) {"
+ " window.scrollTo(x - window.innerWidth/2, y - window.innerHeight/2);"
+ " }"
+ " return {"
+ " view_x: Math.floor(window.pageXOffset),"
+ " view_y: Math.floor(window.pageYOffset),"
+ " view_width: Math.floor(window.innerWidth),"
+ " view_height: Math.floor(window.innerHeight)};"
+ "}",
+ args,
+ &value);
+ if (!status.IsOk())
+ return status;
+ base::DictionaryValue* view_attrib;
+ value->GetAsDictionary(&view_attrib);
+ int view_x, view_y, view_width, view_height;
+ view_attrib->GetInteger("view_x", &view_x);
+ view_attrib->GetInteger("view_y", &view_y);
+ view_attrib->GetInteger("view_width", &view_width);
+ view_attrib->GetInteger("view_height", &view_height);
+ *offset_x = x - view_x;
+ *offset_y = y - view_y;
+ if (*offset_x < 0 || *offset_x >= view_width || *offset_y < 0 ||
+ *offset_y >= view_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 +561,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,
« no previous file with comments | « chrome/test/chromedriver/window_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698