Skip to content

Commit

Permalink
Delete gesture_action.py and remove support for JSON attributes
Browse files Browse the repository at this point in the history
completely from page_action. Make ActionRunner.RunAction private.

BUG=361809

Review URL: https://codereview.chromium.org/356243002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282570 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
chrishenry@google.com committed Jul 11, 2014
1 parent e8a5d06 commit cfda1f5
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 136 deletions.
36 changes: 17 additions & 19 deletions tools/telemetry/telemetry/page/actions/action_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class ActionRunner(object):
def __init__(self, tab):
self._tab = tab

# TODO(nednguyen): remove this (or make private) when
# crbug.com/361809 is marked fixed
def RunAction(self, action):
def _RunAction(self, action):
action.WillRunAction(self._tab)
action.RunAction(self._tab)

Expand Down Expand Up @@ -89,7 +87,7 @@ def NavigateToPage(self, page, timeout_in_seconds=60):
target_side_url = self._tab.browser.http_server.UrlOf(page.file_path_url)
else:
target_side_url = page.url
self.RunAction(NavigateAction(
self._RunAction(NavigateAction(
url=target_side_url,
script_to_evaluate_on_commit=page.script_to_evaluate_on_commit,
timeout_in_seconds=timeout_in_seconds))
Expand Down Expand Up @@ -167,7 +165,7 @@ def WaitForElement(self, selector=None, text=None, element_function=None,
'(function() { return foo.element; })()'.
timeout_in_seconds: The timeout in seconds (default to 60).
"""
self.RunAction(WaitForElementAction(
self._RunAction(WaitForElementAction(
selector=selector, text=text, element_function=element_function,
timeout_in_seconds=timeout_in_seconds))

Expand All @@ -184,7 +182,7 @@ def TapElement(self, selector=None, text=None, element_function=None):
to retrieve the element. For example:
'(function() { return foo.element; })()'.
"""
self.RunAction(TapAction(
self._RunAction(TapAction(
selector=selector, text=text, element_function=element_function))

def ClickElement(self, selector=None, text=None, element_function=None):
Expand All @@ -200,7 +198,7 @@ def ClickElement(self, selector=None, text=None, element_function=None):
to retrieve the element. For example:
'(function() { return foo.element; })()'.
"""
self.RunAction(ClickElementAction(
self._RunAction(ClickElementAction(
selector=selector, text=text, element_function=element_function))

def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5,
Expand All @@ -223,7 +221,7 @@ def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5,
3.0 / (window.outerWidth/window.innerWidth).
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(PinchAction(
self._RunAction(PinchAction(
left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio,
scale_factor=scale_factor,
speed_in_pixels_per_second=speed_in_pixels_per_second))
Expand Down Expand Up @@ -254,7 +252,7 @@ def PinchElement(self, selector=None, text=None, element_function=None,
3.0 / (window.outerWidth/window.innerWidth).
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(PinchAction(
self._RunAction(PinchAction(
selector=selector, text=text, element_function=element_function,
left_anchor_ratio=left_anchor_ratio, top_anchor_ratio=top_anchor_ratio,
scale_factor=scale_factor,
Expand Down Expand Up @@ -285,7 +283,7 @@ def ScrollPage(self, left_start_ratio=0.5, top_start_ratio=0.5,
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
use_touch: Whether scrolling should be done with touch input.
"""
self.RunAction(ScrollAction(
self._RunAction(ScrollAction(
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance, distance_expr=distance_expr,
speed_in_pixels_per_second=speed_in_pixels_per_second,
Expand Down Expand Up @@ -325,7 +323,7 @@ def ScrollElement(self, selector=None, text=None, element_function=None,
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
use_touch: Whether scrolling should be done with touch input.
"""
self.RunAction(ScrollAction(
self._RunAction(ScrollAction(
selector=selector, text=text, element_function=element_function,
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance, distance_expr=distance_expr,
Expand Down Expand Up @@ -358,7 +356,7 @@ def ScrollBouncePage(self, left_start_ratio=0.5, top_start_ratio=0.5,
repeat_count: How often we want to repeat the full gesture.
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(ScrollBounceAction(
self._RunAction(ScrollBounceAction(
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance,
overscroll=overscroll, repeat_count=repeat_count,
Expand Down Expand Up @@ -396,7 +394,7 @@ def ScrollBounceElement(self, selector=None, text=None, element_function=None,
repeat_count: How often we want to repeat the full gesture.
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(ScrollBounceAction(
self._RunAction(ScrollBounceAction(
selector=selector, text=text, element_function=element_function,
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance,
Expand All @@ -419,7 +417,7 @@ def SwipePage(self, left_start_ratio=0.5, top_start_ratio=0.5,
distance: The distance to swipe (in pixel).
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(SwipeAction(
self._RunAction(SwipeAction(
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance,
speed_in_pixels_per_second=speed_in_pixels_per_second))
Expand Down Expand Up @@ -450,7 +448,7 @@ def SwipeElement(self, selector=None, text=None, element_function=None,
distance: The distance to swipe (in pixel).
speed_in_pixels_per_second: The speed of the gesture (in pixels/s).
"""
self.RunAction(SwipeAction(
self._RunAction(SwipeAction(
selector=selector, text=text, element_function=element_function,
left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
direction=direction, distance=distance,
Expand All @@ -476,7 +474,7 @@ def PlayMedia(self, selector=None,
Raises:
TimeoutException: If the maximum waiting time is exceeded.
"""
self.RunAction(PlayAction(
self._RunAction(PlayAction(
selector=selector,
playing_event_timeout_in_seconds=playing_event_timeout_in_seconds,
ended_event_timeout_in_seconds=ended_event_timeout_in_seconds))
Expand All @@ -501,7 +499,7 @@ def SeekMedia(self, seconds, selector=None, timeout_in_seconds=0,
Raises:
TimeoutException: If the maximum waiting time is exceeded.
"""
self.RunAction(SeekAction(
self._RunAction(SeekAction(
seconds=seconds, selector=selector,
timeout_in_seconds=timeout_in_seconds,
log_time=log_time, label=label))
Expand All @@ -522,7 +520,7 @@ def LoopMedia(self, loop_count, selector=None, timeout_in_seconds=None):
Raises:
TimeoutException: If the maximum waiting time is exceeded.
"""
self.RunAction(LoopAction(
self._RunAction(LoopAction(
loop_count=loop_count, selector=selector,
timeout_in_seconds=timeout_in_seconds))

Expand All @@ -546,7 +544,7 @@ def RepaintContinuously(self, seconds):
of seconds have elapsed AND at least three RAFs have been
fired. Times out after max(60, self.seconds), if less than three
RAFs were fired."""
self.RunAction(RepaintContinuouslyAction(seconds=seconds))
self._RunAction(RepaintContinuouslyAction(seconds=seconds))

class Interaction(object):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from telemetry.core import util
from telemetry.core.backends.chrome import tracing_backend
from telemetry.timeline import model
from telemetry.page.actions import gesture_action
from telemetry.page.actions import action_runner as action_runner_module
from telemetry.page.actions import page_action
from telemetry.unittest import tab_test_case
from telemetry.web_perf import timeline_interaction_record as tir_module

Expand Down Expand Up @@ -179,7 +179,7 @@ def WillFail():
self.assertRaises(exceptions.EvaluateException, WillFail)

def testScroll(self):
if not gesture_action.GestureAction.IsGestureSourceTypeSupported(
if not page_action.IsGestureSourceTypeSupported(
self._tab, 'touch'):
return

Expand All @@ -201,7 +201,7 @@ def testScroll(self):
'document.body.scrollLeft') > 75)

def testSwipe(self):
if not gesture_action.GestureAction.IsGestureSourceTypeSupported(
if not page_action.IsGestureSourceTypeSupported(
self._tab, 'touch'):
return

Expand Down
50 changes: 0 additions & 50 deletions tools/telemetry/telemetry/page/actions/gesture_action.py

This file was deleted.

23 changes: 0 additions & 23 deletions tools/telemetry/telemetry/page/actions/gesture_action_unittest.py

This file was deleted.

1 change: 0 additions & 1 deletion tools/telemetry/telemetry/page/actions/javascript_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class ClickElementAction(page_action.PageAction):
def __init__(self, selector=None, text=None, element_function=None):
super(ClickElementAction, self).__init__()
self.automatically_record_interaction = False
self.selector = selector
self.text = text
self.element_function = element_function
Expand Down
28 changes: 22 additions & 6 deletions tools/telemetry/telemetry/page/actions/page_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import re

from telemetry import decorators

class PageActionNotSupported(Exception):
pass

Expand All @@ -14,11 +16,6 @@ class PageActionFailed(Exception):
class PageAction(object):
"""Represents an action that a user might try to perform to a page."""

def __init__(self, attributes=None):
if attributes:
for k, v in attributes.iteritems():
setattr(self, k, v)

def WillRunAction(self, tab):
"""Override to do action-specific setup before
Test.WillRunAction is called."""
Expand All @@ -30,7 +27,6 @@ def RunAction(self, tab):
def CleanUp(self, tab):
pass


def EvaluateCallbackWithElement(
tab, callback_js, selector=None, text=None, element_function=None,
wait=False, timeout_in_seconds=60):
Expand Down Expand Up @@ -114,3 +110,23 @@ def EvaluateCallbackWithElement(

def _EscapeSelector(selector):
return selector.replace('\'', '\\\'')

def GetGestureSourceTypeFromOptions(tab):
gesture_source_type = tab.browser.synthetic_gesture_source_type
return 'chrome.gpuBenchmarking.' + gesture_source_type.upper() + '_INPUT'

@decorators.Cache
def IsGestureSourceTypeSupported(tab, gesture_source_type):
# TODO(dominikg): remove once support for
# 'chrome.gpuBenchmarking.gestureSourceTypeSupported' has
# been rolled into reference build.
if tab.EvaluateJavaScript("""
typeof chrome.gpuBenchmarking.gestureSourceTypeSupported ===
'undefined'"""):
return (tab.browser.platform.GetOSName() != 'mac' or
gesture_source_type.lower() != 'touch')

return tab.EvaluateJavaScript("""
chrome.gpuBenchmarking.gestureSourceTypeSupported(
chrome.gpuBenchmarking.%s_INPUT)"""
% (gesture_source_type.upper()))
10 changes: 4 additions & 6 deletions tools/telemetry/telemetry/page/actions/pinch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
# found in the LICENSE file.
import os

from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action

class PinchAction(GestureAction):
class PinchAction(page_action.PageAction):
def __init__(self, selector=None, text=None, element_function=None,
left_anchor_ratio=0.5, top_anchor_ratio=0.5,
scale_factor=None, speed_in_pixels_per_second=800):
super(PinchAction, self).__init__()
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
Expand Down Expand Up @@ -41,12 +39,12 @@ def WillRunAction(self, tab):
'This version of the browser doesn\'t support the new JS interface '
'for pinch gestures.')

if (GestureAction.GetGestureSourceTypeFromOptions(tab) ==
if (page_action.GetGestureSourceTypeFromOptions(tab) ==
'chrome.gpuBenchmarking.MOUSE_INPUT'):
raise page_action.PageActionNotSupported(
'Pinch page action does not support mouse input')

if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'):
if not page_action.IsGestureSourceTypeSupported(tab, 'touch'):
raise page_action.PageActionNotSupported(
'Touch input not supported for this browser')

Expand All @@ -62,7 +60,7 @@ def _GetDefaultScaleFactorForPage(tab):
'window.outerWidth / window.innerWidth')
return 3.0 / current_scale_factor

def RunGesture(self, tab):
def RunAction(self, tab):
scale_factor = (self._scale_factor if self._scale_factor else
PinchAction._GetDefaultScaleFactorForPage(tab))
code = '''
Expand Down
4 changes: 2 additions & 2 deletions tools/telemetry/telemetry/page/actions/pinch_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# found in the LICENSE file.

from telemetry.page.actions import action_runner as action_runner_module
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
from telemetry.unittest import tab_test_case


Expand All @@ -13,7 +13,7 @@ def setUp(self):

def testPinchByApiCalledWithCorrectArguments(self):
self.Navigate('blank.html')
if not GestureAction.IsGestureSourceTypeSupported(self._tab, 'touch'):
if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'):
return

action_runner = action_runner_module.ActionRunner(self._tab)
Expand Down
Loading

0 comments on commit cfda1f5

Please sign in to comment.