Commit cfda1f5b authored by chrishenry@google.com's avatar chrishenry@google.com

Delete gesture_action.py and remove support for JSON attributes

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
parent e8a5d067
......@@ -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)
......@@ -89,7 +87,7 @@ class ActionRunner(object):
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))
......@@ -167,7 +165,7 @@ class ActionRunner(object):
'(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))
......@@ -184,7 +182,7 @@ class ActionRunner(object):
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):
......@@ -200,7 +198,7 @@ class ActionRunner(object):
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,
......@@ -223,7 +221,7 @@ class ActionRunner(object):
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))
......@@ -254,7 +252,7 @@ class ActionRunner(object):
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,
......@@ -285,7 +283,7 @@ class ActionRunner(object):
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,
......@@ -325,7 +323,7 @@ class ActionRunner(object):
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,
......@@ -358,7 +356,7 @@ class ActionRunner(object):
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,
......@@ -396,7 +394,7 @@ class ActionRunner(object):
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,
......@@ -419,7 +417,7 @@ class ActionRunner(object):
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))
......@@ -450,7 +448,7 @@ class ActionRunner(object):
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,
......@@ -476,7 +474,7 @@ class ActionRunner(object):
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))
......@@ -501,7 +499,7 @@ class ActionRunner(object):
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))
......@@ -522,7 +520,7 @@ class ActionRunner(object):
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))
......@@ -546,7 +544,7 @@ class ActionRunner(object):
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):
......
......@@ -7,8 +7,8 @@ from telemetry.core import exceptions
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
......@@ -179,7 +179,7 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
self.assertRaises(exceptions.EvaluateException, WillFail)
def testScroll(self):
if not gesture_action.GestureAction.IsGestureSourceTypeSupported(
if not page_action.IsGestureSourceTypeSupported(
self._tab, 'touch'):
return
......@@ -201,7 +201,7 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
'document.body.scrollLeft') > 75)
def testSwipe(self):
if not gesture_action.GestureAction.IsGestureSourceTypeSupported(
if not page_action.IsGestureSourceTypeSupported(
self._tab, 'touch'):
return
......
# 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.
from telemetry.page.actions import page_action
from telemetry import decorators
from telemetry.web_perf import timeline_interaction_record as tir_module
class GestureAction(page_action.PageAction):
def __init__(self, attributes=None):
super(GestureAction, self).__init__(attributes)
if not hasattr(self, 'automatically_record_interaction'):
self.automatically_record_interaction = True
def RunAction(self, tab):
interaction_name = 'Gesture_%s' % self.__class__.__name__
if self.automatically_record_interaction:
tab.ExecuteJavaScript('console.time("%s");' %
tir_module.TimelineInteractionRecord.GetJavaScriptMarker(
interaction_name, [tir_module.IS_SMOOTH]))
self.RunGesture(tab)
if self.automatically_record_interaction:
tab.ExecuteJavaScript('console.timeEnd("%s");' %
tir_module.TimelineInteractionRecord.GetJavaScriptMarker(
interaction_name, [tir_module.IS_SMOOTH]))
def RunGesture(self, tab):
raise NotImplementedError()
@staticmethod
def GetGestureSourceTypeFromOptions(tab):
gesture_source_type = tab.browser.synthetic_gesture_source_type
return 'chrome.gpuBenchmarking.' + gesture_source_type.upper() + '_INPUT'
@staticmethod
@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()))
# Copyright 2014 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.
from telemetry.page.actions import gesture_action
from telemetry.unittest import tab_test_case
class MockGestureAction(gesture_action.GestureAction):
"""Mock gesture action that simply sleeps for a specified amount of time."""
def __init__(self):
super(MockGestureAction, self).__init__()
self.was_run = False
def RunGesture(self, tab):
self.was_run = True
class GestureActionTest(tab_test_case.TabTestCase):
def testGestureAction(self):
"""Test that GestureAction.RunAction() calls RunGesture()."""
action = MockGestureAction()
action.RunAction(self._tab)
self.assertTrue(action.was_run)
......@@ -7,7 +7,6 @@ from telemetry.page.actions import page_action
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
......
......@@ -4,6 +4,8 @@
import re
from telemetry import decorators
class PageActionNotSupported(Exception):
pass
......@@ -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."""
......@@ -30,7 +27,6 @@ class PageAction(object):
def CleanUp(self, tab):
pass
def EvaluateCallbackWithElement(
tab, callback_js, selector=None, text=None, element_function=None,
wait=False, timeout_in_seconds=60):
......@@ -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()))
......@@ -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
......@@ -41,12 +39,12 @@ class PinchAction(GestureAction):
'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')
......@@ -62,7 +60,7 @@ class PinchAction(GestureAction):
'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 = '''
......
......@@ -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
......@@ -13,7 +13,7 @@ class PinchActionTest(tab_test_case.TabTestCase):
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)
......
......@@ -3,14 +3,12 @@
# found in the LICENSE file.
import os
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
class ScrollAction(GestureAction):
class ScrollAction(page_action.PageAction):
# TODO(chrishenry): Ignore attributes, to be deleted when usage in
# other repo is cleaned up.
def __init__(self, attributes=None,
selector=None, text=None, element_function=None,
def __init__(self, selector=None, text=None, element_function=None,
left_start_ratio=0.5, top_start_ratio=0.5, direction='down',
distance=None, distance_expr=None,
speed_in_pixels_per_second=800, use_touch=False):
......@@ -18,7 +16,6 @@ class ScrollAction(GestureAction):
if direction not in ['down', 'up', 'left', 'right']:
raise page_action.PageActionNotSupported(
'Invalid scroll direction: %s' % self.direction)
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
......@@ -49,11 +46,11 @@ class ScrollAction(GestureAction):
# Fail if this action requires touch and we can't send touch events.
if self._use_touch:
if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'):
if not page_action.IsGestureSourceTypeSupported(tab, 'touch'):
raise page_action.PageActionNotSupported(
'Touch scroll not supported for this browser')
if (GestureAction.GetGestureSourceTypeFromOptions(tab) ==
if (page_action.GetGestureSourceTypeFromOptions(tab) ==
'chrome.gpuBenchmarking.MOUSE_INPUT'):
raise page_action.PageActionNotSupported(
'Scroll requires touch on this page but mouse input was requested')
......@@ -64,12 +61,12 @@ class ScrollAction(GestureAction):
window.__scrollAction = new __ScrollAction(%s, %s);"""
% (done_callback, self._distance_func))
def RunGesture(self, tab):
def RunAction(self, tab):
if (self._selector is None and self._text is None and
self._element_function is None):
self._element_function = 'document.body'
gesture_source_type = GestureAction.GetGestureSourceTypeFromOptions(tab)
gesture_source_type = page_action.GetGestureSourceTypeFromOptions(tab)
if self._use_touch:
gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
......
......@@ -3,10 +3,9 @@
# found in the LICENSE file.
import os
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
class ScrollBounceAction(GestureAction):
class ScrollBounceAction(page_action.PageAction):
def __init__(self, selector=None, text=None, element_function=None,
left_start_ratio=0.5, top_start_ratio=0.5,
direction='down', distance=100,
......@@ -16,7 +15,6 @@ class ScrollBounceAction(GestureAction):
if direction not in ['down', 'up', 'left', 'right']:
raise page_action.PageActionNotSupported(
'Invalid scroll direction: %s' % self.direction)
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
......@@ -52,11 +50,11 @@ class ScrollBounceAction(GestureAction):
# Fail if we can't send touch events (bouncing is really only
# interesting for touch)
if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'):
if not page_action.IsGestureSourceTypeSupported(tab, 'touch'):
raise page_action.PageActionNotSupported(
'Touch scroll not supported for this browser')
if (GestureAction.GetGestureSourceTypeFromOptions(tab) ==
if (page_action.GetGestureSourceTypeFromOptions(tab) ==
'chrome.gpuBenchmarking.MOUSE_INPUT'):
raise page_action.PageActionNotSupported(
'ScrollBounce page action does not support mouse input')
......@@ -67,7 +65,7 @@ class ScrollBounceAction(GestureAction):
window.__scrollBounceAction = new __ScrollBounceAction(%s);"""
% (done_callback))
def RunGesture(self, tab):
def RunAction(self, tab):
code = '''
function(element, info) {
if (!element) {
......
......@@ -4,10 +4,9 @@
import os
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
class SwipeAction(GestureAction):
class SwipeAction(page_action.PageAction):
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_in_pixels_per_second=800):
......@@ -15,7 +14,6 @@ class SwipeAction(GestureAction):
if direction not in ['down', 'up', 'left', 'right']:
raise page_action.PageActionNotSupported(
'Invalid swipe direction: %s' % self.direction)
self.automatically_record_interaction = False
self._selector = selector
self._text = text
self._element_function = element_function
......@@ -36,12 +34,12 @@ class SwipeAction(GestureAction):
raise page_action.PageActionNotSupported(
'Synthetic swipe not supported for this browser')
if (GestureAction.GetGestureSourceTypeFromOptions(tab) ==
if (page_action.GetGestureSourceTypeFromOptions(tab) ==
'chrome.gpuBenchmarking.MOUSE_INPUT'):
raise page_action.PageActionNotSupported(
'Swipe 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')
......@@ -51,7 +49,7 @@ class SwipeAction(GestureAction):
window.__swipeAction = new __SwipeAction(%s);"""
% (done_callback))
def RunGesture(self, tab):
def RunAction(self, tab):
if (self._selector is None and self._text is None and
self._element_function is None):
self._element_function = 'document.body'
......
......@@ -4,15 +4,13 @@
import os
from telemetry.page.actions.gesture_action import GestureAction
from telemetry.page.actions import page_action
class TapAction(GestureAction):
class TapAction(page_action.PageAction):
def __init__(self, selector=None, text=None, element_function=None,
left_position_percentage=0.5, top_position_percentage=0.5,
duration_ms=50):
super(TapAction, self).__init__()
self.automatically_record_interaction = False
self.selector = selector
self.text = text
self.element_function = element_function
......@@ -41,10 +39,10 @@ class TapAction(GestureAction):
return (self.element_function is not None or self.selector is not None or
self.text is not None)
def RunGesture(self, tab):
def RunAction(self, tab):
if not self.HasElementSelector():
self.element_function = 'document.body'
gesture_source_type = GestureAction.GetGestureSourceTypeFromOptions(tab)
gesture_source_type = page_action.GetGestureSourceTypeFromOptions(tab)
tap_cmd = ('''
window.__tapAction.start({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment