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

Side by Side Diff: tools/telemetry/telemetry/page/actions/action_runner.py

Issue 337643002: Add SwipePage/SwipeElement API to action_runner, wrapping over (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more comments. Created 6 years, 6 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 from telemetry.page.actions.javascript_click import ClickElementAction 5 from telemetry.page.actions.javascript_click import ClickElementAction
6 from telemetry.page.actions.navigate import NavigateAction 6 from telemetry.page.actions.navigate import NavigateAction
7 from telemetry.page.actions.swipe import SwipeAction
7 from telemetry.page.actions.tap import TapAction 8 from telemetry.page.actions.tap import TapAction
8 from telemetry.page.actions.wait import WaitAction 9 from telemetry.page.actions.wait import WaitAction
9 from telemetry.web_perf import timeline_interaction_record as tir_module 10 from telemetry.web_perf import timeline_interaction_record as tir_module
10 11
11 12
12 class ActionRunner(object): 13 class ActionRunner(object):
13 14
14 def __init__(self, tab): 15 def __init__(self, tab):
15 self._tab = tab 16 self._tab = tab
16 17
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 Args: 187 Args:
187 selector: A CSS selector describing the element. 188 selector: A CSS selector describing the element.
188 text: The element must contains this exact text. 189 text: The element must contains this exact text.
189 element_function: A JavaScript function (as string) that is used 190 element_function: A JavaScript function (as string) that is used
190 to retrieve the element. For example: 191 to retrieve the element. For example:
191 '(function() { return foo.element; })()'. 192 '(function() { return foo.element; })()'.
192 """ 193 """
193 self.RunAction(ClickElementAction( 194 self.RunAction(ClickElementAction(
194 selector=selector, text=text, element_function=element_function)) 195 selector=selector, text=text, element_function=element_function))
195 196
197 def SwipePage(self, left_start_ratio=0.5, top_start_ratio=0.5,
198 direction='left', distance=100, speed=800):
199 """Perform swipe gesture on the page.
200
201 Args:
202 left_start_ratio: The horizontal starting coordinate of the
203 gesture, as a ratio of the visible bounding rectangle for
204 document.body.
205 top_start_ratio: The vertical starting coordinate of the
206 gesture, as a ratio of the visible bounding rectangle for
207 document.body.
208 direction: The direction of swipe, either 'left', 'right',
209 'up', or 'down'
210 distance: The distance to swipe (in pixel).
211 speed: The speed of the gesture.
212 """
213 self.RunAction(SwipeAction(
214 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
215 direction=direction, distance=distance, speed=speed))
216
217 def SwipeElement(self, selector=None, text=None, element_function=None,
218 left_start_ratio=0.5, top_start_ratio=0.5,
219 direction='left', distance=100, speed=800):
220 """Perform swipe gesture on the element.
221
222 Args:
223 selector: A CSS selector describing the element.
224 text: The element must contains this exact text.
225 element_function: A JavaScript function (as string) that is used
226 to retrieve the element. For example:
227 'function() { return foo.element; }'.
228 left_start_ratio: The horizontal starting coordinate of the
229 gesture, as a ratio of the visible bounding rectangle for
230 the element.
231 top_start_ratio: The vertical starting coordinate of the
232 gesture, as a ratio of the visible bounding rectangle for
233 the element.
234 direction: The direction of swipe, either 'left', 'right',
235 'up', or 'down'
236 distance: The distance to swipe (in pixel).
237 speed: The speed of the gesture.
238 """
239 self.RunAction(SwipeAction(
240 selector=selector, text=text, element_function=element_function,
241 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
242 direction=direction, distance=distance, speed=speed))
243
196 244
197 class Interaction(object): 245 class Interaction(object):
198 246
199 def __init__(self, action_runner, label, flags): 247 def __init__(self, action_runner, label, flags):
200 assert action_runner 248 assert action_runner
201 assert label 249 assert label
202 assert isinstance(flags, list) 250 assert isinstance(flags, list)
203 251
204 self._action_runner = action_runner 252 self._action_runner = action_runner
205 self._label = label 253 self._label = label
206 self._flags = flags 254 self._flags = flags
207 self._started = False 255 self._started = False
208 256
209 def Begin(self): 257 def Begin(self):
210 assert not self._started 258 assert not self._started
211 self._started = True 259 self._started = True
212 self._action_runner.ExecuteJavaScript('console.time("%s");' % 260 self._action_runner.ExecuteJavaScript('console.time("%s");' %
213 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 261 tir_module.TimelineInteractionRecord.GetJavaScriptMarker(
214 self._label, self._flags)) 262 self._label, self._flags))
215 263
216 def End(self): 264 def End(self):
217 assert self._started 265 assert self._started
218 self._started = False 266 self._started = False
219 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % 267 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' %
220 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 268 tir_module.TimelineInteractionRecord.GetJavaScriptMarker(
221 self._label, self._flags)) 269 self._label, self._flags))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698