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 5from telemetry.page.actions import page_action 6from telemetry import decorators 7from telemetry.web_perf import timeline_interaction_record as tir_module 8 9class GestureAction(page_action.PageAction): 10 def __init__(self, attributes=None): 11 super(GestureAction, self).__init__(attributes) 12 if not hasattr(self, 'automatically_record_interaction'): 13 self.automatically_record_interaction = True 14 15 def RunAction(self, tab): 16 interaction_name = 'Gesture_%s' % self.__class__.__name__ 17 if self.automatically_record_interaction: 18 tab.ExecuteJavaScript('console.time("%s");' % 19 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 20 interaction_name, [tir_module.IS_SMOOTH])) 21 self.RunGesture(tab) 22 if self.automatically_record_interaction: 23 tab.ExecuteJavaScript('console.timeEnd("%s");' % 24 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( 25 interaction_name, [tir_module.IS_SMOOTH])) 26 27 def RunGesture(self, tab): 28 raise NotImplementedError() 29 30 @staticmethod 31 def GetGestureSourceTypeFromOptions(tab): 32 gesture_source_type = tab.browser.synthetic_gesture_source_type 33 return 'chrome.gpuBenchmarking.' + gesture_source_type.upper() + '_INPUT' 34 35 @staticmethod 36 @decorators.Cache 37 def IsGestureSourceTypeSupported(tab, gesture_source_type): 38 # TODO(dominikg): remove once support for 39 # 'chrome.gpuBenchmarking.gestureSourceTypeSupported' has 40 # been rolled into reference build. 41 if tab.EvaluateJavaScript(""" 42 typeof chrome.gpuBenchmarking.gestureSourceTypeSupported === 43 'undefined'"""): 44 return (tab.browser.platform.GetOSName() != 'mac' or 45 gesture_source_type.lower() != 'touch') 46 47 return tab.EvaluateJavaScript(""" 48 chrome.gpuBenchmarking.gestureSourceTypeSupported( 49 chrome.gpuBenchmarking.%s_INPUT)""" 50 % (gesture_source_type.upper())) 51