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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/chromedriver/window_commands.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <string>
8 9
9 #include "base/callback.h" 10 #include "base/callback.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/test/chromedriver/basic_types.h" 16 #include "chrome/test/chromedriver/basic_types.h"
16 #include "chrome/test/chromedriver/chrome/chrome.h" 17 #include "chrome/test/chromedriver/chrome/chrome.h"
17 #include "chrome/test/chromedriver/chrome/devtools_client.h" 18 #include "chrome/test/chromedriver/chrome/devtools_client.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 bool secure = false; 115 bool secure = false;
115 cookie_dict->GetBoolean("secure", &secure); 116 cookie_dict->GetBoolean("secure", &secure);
116 117
117 cookies_tmp.push_back( 118 cookies_tmp.push_back(
118 Cookie(name, value, domain, path, expiry, secure, session)); 119 Cookie(name, value, domain, path, expiry, secure, session));
119 } 120 }
120 cookies->swap(cookies_tmp); 121 cookies->swap(cookies_tmp);
121 return Status(kOk); 122 return Status(kOk);
122 } 123 }
123 124
125 Status ScrollCoordinateInToView(
126 Session* session, WebView* web_view, int x, int y, int* offset_x,
127 int* offset_y) {
128 scoped_ptr<base::Value> value;
129 base::ListValue args;
130 args.AppendInteger(x);
131 args.AppendInteger(y);
132 Status status = web_view->CallFunction(
133 std::string(),
134 "function(x, y) {"
135 " if (x < window.pageXOffset ||"
136 " x >= window.pageXOffset + window.innerWidth ||"
137 " y < window.pageYOffset ||"
138 " y >= window.pageYOffset + window.innerHeight) {"
139 " window.scrollTo(x - window.innerWidth/2, y - window.innerHeight/2);"
140 " }"
141 " return {"
142 " view_x: Math.floor(window.pageXOffset),"
143 " view_y: Math.floor(window.pageYOffset),"
144 " view_width: Math.floor(window.innerWidth),"
145 " view_height: Math.floor(window.innerHeight)};"
146 "}",
147 args,
148 &value);
149 if (!status.IsOk())
150 return status;
151 base::DictionaryValue* view_attrib;
152 value->GetAsDictionary(&view_attrib);
153 int view_x, view_y, view_width, view_height;
154 view_attrib->GetInteger("view_x", &view_x);
155 view_attrib->GetInteger("view_y", &view_y);
156 view_attrib->GetInteger("view_width", &view_width);
157 view_attrib->GetInteger("view_height", &view_height);
158 *offset_x = x - view_x;
159 *offset_y = y - view_y;
160 if (*offset_x < 0 || *offset_x >= view_width || *offset_y < 0 ||
161 *offset_y >= view_height)
162 return Status(kUnknownError, "Failed to scroll coordinate into view");
163 return Status(kOk);
164 }
165
166 Status ExecuteTouchEvent(
167 Session* session, WebView* web_view, TouchEventType type,
168 const base::DictionaryValue& params) {
169 int x, y;
170 if (!params.GetInteger("x", &x))
171 return Status(kUnknownError, "'x' must be an integer");
172 if (!params.GetInteger("y", &y))
173 return Status(kUnknownError, "'y' must be an integer");
174 int relative_x = x;
175 int relative_y = y;
176 Status status = ScrollCoordinateInToView(
177 session, web_view, x, y, &relative_x, &relative_y);
178 if (!status.IsOk())
179 return status;
180 std::list<TouchEvent> events;
181 events.push_back(
182 TouchEvent(type, relative_x, relative_y));
183 return web_view->DispatchTouchEvents(events);
184 }
185
124 } // namespace 186 } // namespace
125 187
126 Status ExecuteWindowCommand( 188 Status ExecuteWindowCommand(
127 const WindowCommand& command, 189 const WindowCommand& command,
128 Session* session, 190 Session* session,
129 const base::DictionaryValue& params, 191 const base::DictionaryValue& params,
130 scoped_ptr<base::Value>* value) { 192 scoped_ptr<base::Value>* value) {
131 WebView* web_view = NULL; 193 WebView* web_view = NULL;
132 Status status = session->GetTargetWindow(&web_view); 194 Status status = session->GetTargetWindow(&web_view);
133 if (status.IsError()) 195 if (status.IsError())
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 MouseEvent(kPressedMouseEventType, button, 554 MouseEvent(kPressedMouseEventType, button,
493 session->mouse_position.x, session->mouse_position.y, 555 session->mouse_position.x, session->mouse_position.y,
494 session->sticky_modifiers, 2)); 556 session->sticky_modifiers, 2));
495 events.push_back( 557 events.push_back(
496 MouseEvent(kReleasedMouseEventType, button, 558 MouseEvent(kReleasedMouseEventType, button,
497 session->mouse_position.x, session->mouse_position.y, 559 session->mouse_position.x, session->mouse_position.y,
498 session->sticky_modifiers, 2)); 560 session->sticky_modifiers, 2));
499 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId()); 561 return web_view->DispatchMouseEvents(events, session->GetCurrentFrameId());
500 } 562 }
501 563
564 Status ExecuteTouchDown(
565 Session* session,
566 WebView* web_view,
567 const base::DictionaryValue& params,
568 scoped_ptr<base::Value>* value) {
569 return ExecuteTouchEvent(session, web_view, kTouchStart, params);
570 }
571
572 Status ExecuteTouchUp(
573 Session* session,
574 WebView* web_view,
575 const base::DictionaryValue& params,
576 scoped_ptr<base::Value>* value) {
577 return ExecuteTouchEvent(session, web_view, kTouchEnd, params);
578 }
579
580 Status ExecuteTouchMove(
581 Session* session,
582 WebView* web_view,
583 const base::DictionaryValue& params,
584 scoped_ptr<base::Value>* value) {
585 return ExecuteTouchEvent(session, web_view, kTouchMove, params);
586 }
587
502 Status ExecuteGetActiveElement( 588 Status ExecuteGetActiveElement(
503 Session* session, 589 Session* session,
504 WebView* web_view, 590 WebView* web_view,
505 const base::DictionaryValue& params, 591 const base::DictionaryValue& params,
506 scoped_ptr<base::Value>* value) { 592 scoped_ptr<base::Value>* value) {
507 base::ListValue args; 593 base::ListValue args;
508 return web_view->CallFunction( 594 return web_view->CallFunction(
509 session->GetCurrentFrameId(), 595 session->GetCurrentFrameId(),
510 "function() { return document.activeElement || document.body }", 596 "function() { return document.activeElement || document.body }",
511 args, 597 args,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 // |accuracy| is not part of the WebDriver spec yet, so if it is not given 841 // |accuracy| is not part of the WebDriver spec yet, so if it is not given
756 // default to 100 meters accuracy. 842 // default to 100 meters accuracy.
757 geoposition.accuracy = 100; 843 geoposition.accuracy = 100;
758 } 844 }
759 845
760 Status status = web_view->OverrideGeolocation(geoposition); 846 Status status = web_view->OverrideGeolocation(geoposition);
761 if (status.IsOk()) 847 if (status.IsOk())
762 session->overridden_geoposition.reset(new Geoposition(geoposition)); 848 session->overridden_geoposition.reset(new Geoposition(geoposition));
763 return status; 849 return status;
764 } 850 }
OLDNEW
« 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