- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / pinch.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 import os
5
6 from telemetry.page.actions import page_action
7
8 class PinchAction(page_action.PageAction):
9   def __init__(self, attributes=None):
10     super(PinchAction, self).__init__(attributes)
11
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:
15         js = f.read()
16         tab.ExecuteJavaScript(js)
17
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')
22
23     done_callback = 'function() { window.__pinchActionDone = true; }'
24     tab.ExecuteJavaScript("""
25         window.__pinchActionDone = false;
26         window.__pinchAction = new __PinchAction(%s);"""
27         % done_callback)
28
29   def RunAction(self, page, tab, previous_action):
30     zoom_in = True
31     if hasattr(self, 'zoom_in'):
32       zoom_in = self.zoom_in
33
34     pixels_to_move = 4000
35     if hasattr(self, 'pixels_to_move'):
36       pixels_to_move = self.pixels_to_move
37
38     tab.ExecuteJavaScript('window.__pinchAction.start(%s, %f)'
39                           % ("true" if zoom_in else "false", pixels_to_move))
40
41     tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
42
43   def CanBeBound(self):
44     return True
45
46   def CustomizeBrowserOptions(self, options):
47     options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
48
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))
55
56   def GetTimelineMarkerLabel(self):
57     return 'SyntheticGestureController::running'