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

Unified Diff: tools/telemetry/telemetry/page/actions/swipe.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: 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/actions/swipe.py
diff --git a/tools/telemetry/telemetry/page/actions/swipe.py b/tools/telemetry/telemetry/page/actions/swipe.py
index c8f85880a617b8a64ce11f2d0b7c45f02c695ea5..4bb1e12cac517f547b502932b49581dbe125cea6 100644
--- a/tools/telemetry/telemetry/page/actions/swipe.py
+++ b/tools/telemetry/telemetry/page/actions/swipe.py
@@ -1,14 +1,25 @@
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
import os
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
class SwipeAction(GestureAction):
- def __init__(self, attributes=None):
- super(SwipeAction, self).__init__(attributes)
+ def __init__(self, selector=None, text=None, element_function=None,
+ left_start_ratio=0.5, top_start_ratio=0.5,
+ direction='left', distance=100, speed=800):
+ super(SwipeAction, self).__init__(None)
+ self.selector = selector
+ self.text = text
+ self.element_function = element_function
+ self.left_start_ratio = left_start_ratio
+ self.top_start_ratio = top_start_ratio
+ self.direction = direction
nednguyen 2014/06/14 17:12:13 Check for valid value of direction?
chrishenry 2014/06/14 17:30:51 Done. This was originally done in RunGesture since
+ self.distance = distance
+ self.speed = speed
def WillRunAction(self, tab):
for js_file in ['gesture_common.js', 'swipe.js']:
@@ -37,52 +48,32 @@ class SwipeAction(GestureAction):
% (done_callback))
def RunGesture(self, tab):
- left_start_percentage = 0.5
- top_start_percentage = 0.5
- direction = 'left'
- distance = 100
- speed = 800
- if hasattr(self, 'left_start_percentage'):
- left_start_percentage = self.left_start_percentage
- if hasattr(self, 'top_start_percentage'):
- top_start_percentage = self.top_start_percentage
- if hasattr(self, 'direction'):
- direction = self.direction
- if direction not in ['down', 'up', 'left', 'right']:
- raise page_action.PageActionNotSupported(
- 'Invalid swipe direction: %s' % direction)
- if hasattr(self, 'distance'):
- distance = self.distance
- if hasattr(self, 'speed'):
- speed = self.speed
- if hasattr(self, 'element_function'):
- tab.ExecuteJavaScript("""
- (%s)(function(element) { window.__swipeAction.start(
- { element: element,
- left_start_percentage: %s,
- top_start_percentage: %s,
- direction: '%s',
- distance: %s,
- speed: %s })
- });""" % (self.element_function,
- left_start_percentage,
- top_start_percentage,
- direction,
- distance,
- speed))
- else:
- tab.ExecuteJavaScript("""
- window.__swipeAction.start(
- { element: document.body,
+ if self.direction not in ['down', 'up', 'left', 'right']:
+ raise page_action.PageActionNotSupported(
+ 'Invalid swipe direction: %s' % self.direction)
+
+ if (self.selector is None and self.text is None and
+ self.element_function is None):
+ self.element_function = 'document.body'
+ code = '''
+ function(element, info) {
+ if (!element) {
+ throw Error('Cannot find element: ' + info);
+ }
+ window.__swipeAction.start({
+ element: element,
left_start_percentage: %s,
top_start_percentage: %s,
direction: '%s',
distance: %s,
- speed: %s });"""
- % (left_start_percentage,
- top_start_percentage,
- direction,
- distance,
- speed))
-
+ speed: %s
+ });
+ }''' % (self.left_start_ratio,
+ self.top_start_ratio,
+ self.direction,
+ self.distance,
+ self.speed)
+ page_action.EvaluateCallbackWithElement(
+ tab, code, selector=self.selector, text=self.text,
+ element_function=self.element_function)
tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60)

Powered by Google App Engine
This is Rietveld 408576698