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.
6 from telemetry.page.actions import page_action
8 class PinchAction(page_action.PageAction):
9 def __init__(self, attributes=None):
10 super(PinchAction, self).__init__(attributes)
12 def WillRunAction(self, page, tab):
13 for js_file in ['gesture_common.js', 'pinch.js']:
14 with open(os.path.join(os.path.dirname(__file__), js_file)) as f:
16 tab.ExecuteJavaScript(js)
18 # Fail if browser doesn't support synthetic pinch gestures.
19 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'):
20 raise page_action.PageActionNotSupported(
21 'Synthetic pinch not supported for this browser')
23 done_callback = 'function() { window.__pinchActionDone = true; }'
24 tab.ExecuteJavaScript("""
25 window.__pinchActionDone = false;
26 window.__pinchAction = new __PinchAction(%s);"""
29 def RunAction(self, page, tab, previous_action):
31 if hasattr(self, 'zoom_in'):
32 zoom_in = self.zoom_in
35 if hasattr(self, 'pixels_to_move'):
36 pixels_to_move = self.pixels_to_move
38 tab.ExecuteJavaScript('window.__pinchAction.start(%s, %f)'
39 % ("true" if zoom_in else "false", pixels_to_move))
41 tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
46 def CustomizeBrowserOptions(self, options):
47 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
49 def BindMeasurementJavaScript(self, tab, start_js, stop_js):
50 # Make the pinch action start and stop measurement automatically.
51 tab.ExecuteJavaScript("""
52 window.__pinchAction.beginMeasuringHook = function() { %s };
53 window.__pinchAction.endMeasuringHook = function() { %s };
54 """ % (start_js, stop_js))
56 def GetTimelineMarkerLabel(self):
57 return 'SyntheticGestureController::running'