Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / gesture_action.py
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.
4
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
10
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)
16     else:
17       self.wait_action = None
18
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.')
21
22   def RunAction(self, page, tab):
23     runner = action_runner.ActionRunner(None, tab)
24     if self.wait_action:
25       interaction_name = 'Action_%s' % self.__class__.__name__
26     else:
27       interaction_name = 'Gesture_%s' % self.__class__.__name__
28     runner.BeginInteraction(interaction_name, [tir_module.IS_SMOOTH])
29     self.RunGesture(page, tab)
30     if self.wait_action:
31       self.wait_action.RunAction(page, tab)
32     runner.EndInteraction(interaction_name, [tir_module.IS_SMOOTH])
33
34   def RunGesture(self, page, tab):
35     raise NotImplementedError()
36
37   @staticmethod
38   def GetGestureSourceTypeFromOptions(tab):
39     gesture_source_type = tab.browser.synthetic_gesture_source_type
40     return 'chrome.gpuBenchmarking.' + gesture_source_type.upper() + '_INPUT'
41
42   @staticmethod
43   @decorators.Cache
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 ===
50             'undefined'"""):
51       return True
52
53     return tab.EvaluateJavaScript("""
54         chrome.gpuBenchmarking.gestureSourceTypeSupported(
55             chrome.gpuBenchmarking.%s_INPUT)"""
56         % (gesture_source_type.upper()))