1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry.page.actions import page_action
6 from telemetry.page.actions import wait
7 from telemetry import decorators
8 from telemetry.page.actions import action_runner
9 from telemetry.web_perf import timeline_interaction_record as tir_module
11 class GestureAction(page_action.PageAction):
12 def __init__(self, attributes=None):
13 super(GestureAction, self).__init__(attributes)
14 if hasattr(self, 'wait_after'):
15 self.wait_action = wait.WaitAction(self.wait_after)
17 self.wait_action = None
19 assert self.wait_until is None or self.wait_action is None, (
20 'gesture cannot have wait_after and wait_until at the same time.')
22 def RunAction(self, page, tab):
23 runner = action_runner.ActionRunner(None, tab)
25 interaction_name = 'Action_%s' % self.__class__.__name__
27 interaction_name = 'Gesture_%s' % self.__class__.__name__
28 runner.BeginInteraction(interaction_name, [tir_module.IS_SMOOTH])
29 self.RunGesture(page, tab)
31 self.wait_action.RunAction(page, tab)
32 runner.EndInteraction(interaction_name, [tir_module.IS_SMOOTH])
34 def RunGesture(self, page, tab):
35 raise NotImplementedError()
38 def GetGestureSourceTypeFromOptions(tab):
39 gesture_source_type = tab.browser.synthetic_gesture_source_type
40 return 'chrome.gpuBenchmarking.' + gesture_source_type.upper() + '_INPUT'
44 def IsGestureSourceTypeSupported(tab, gesture_source_type):
45 # TODO(dominikg): remove once support for
46 # 'chrome.gpuBenchmarking.gestureSourceTypeSupported' has
47 # been rolled into reference build.
48 if tab.EvaluateJavaScript("""
49 typeof chrome.gpuBenchmarking.gestureSourceTypeSupported ===
53 return tab.EvaluateJavaScript("""
54 chrome.gpuBenchmarking.gestureSourceTypeSupported(
55 chrome.gpuBenchmarking.%s_INPUT)"""
56 % (gesture_source_type.upper()))