Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: tools/telemetry/telemetry/page/actions/pinch.py

Issue 293683002: Synthetic pinch gesture take scale factor as parameter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import os 4 import os
5 5
6 from telemetry.page.actions.gesture_action import GestureAction 6 from telemetry.page.actions.gesture_action import GestureAction
7 from telemetry.page.actions import page_action 7 from telemetry.page.actions import page_action
8 8
9 class PinchAction(GestureAction): 9 class PinchAction(GestureAction):
10 def __init__(self, attributes=None): 10 def __init__(self, attributes=None):
11 super(PinchAction, self).__init__(attributes) 11 super(PinchAction, self).__init__(attributes)
12 12
13 def WillRunAction(self, page, tab): 13 def WillRunAction(self, page, tab):
14 for js_file in ['gesture_common.js', 'pinch.js']: 14 for js_file in ['gesture_common.js', 'pinch.js']:
15 with open(os.path.join(os.path.dirname(__file__), js_file)) as f: 15 with open(os.path.join(os.path.dirname(__file__), js_file)) as f:
16 js = f.read() 16 js = f.read()
17 tab.ExecuteJavaScript(js) 17 tab.ExecuteJavaScript(js)
18 18
19 # Fail if browser doesn't support synthetic pinch gestures. 19 # Fail if browser doesn't support synthetic pinch gestures.
20 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'): 20 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'):
21 raise page_action.PageActionNotSupported( 21 raise page_action.PageActionNotSupported(
22 'Synthetic pinch not supported for this browser') 22 'Synthetic pinch not supported for this browser')
23 23
24 # TODO(dominikg): Remove once JS interface changes have rolled into stable.
25 if not tab.EvaluateJavaScript('chrome.gpuBenchmarking.newPinchInterface'):
26 raise page_action.PageActionNotSupported("""
Sami 2014/05/19 14:49:04 Nit: use single instead of triple quotes since oth
Dominik Grewe 2014/05/19 17:31:43 Done.
27 This version of the browser doesn't support the new JS interface for
28 pinch gestures.""")
29
24 if (GestureAction.GetGestureSourceTypeFromOptions(tab) == 30 if (GestureAction.GetGestureSourceTypeFromOptions(tab) ==
25 'chrome.gpuBenchmarking.MOUSE_INPUT'): 31 'chrome.gpuBenchmarking.MOUSE_INPUT'):
26 raise page_action.PageActionNotSupported( 32 raise page_action.PageActionNotSupported(
27 'Pinch page action does not support mouse input') 33 'Pinch page action does not support mouse input')
28 34
29 if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'): 35 if not GestureAction.IsGestureSourceTypeSupported(tab, 'touch'):
30 raise page_action.PageActionNotSupported( 36 raise page_action.PageActionNotSupported(
31 'Touch input not supported for this browser') 37 'Touch input not supported for this browser')
32 38
33 done_callback = 'function() { window.__pinchActionDone = true; }' 39 done_callback = 'function() { window.__pinchActionDone = true; }'
34 tab.ExecuteJavaScript(""" 40 tab.ExecuteJavaScript("""
35 window.__pinchActionDone = false; 41 window.__pinchActionDone = false;
36 window.__pinchAction = new __PinchAction(%s);""" 42 window.__pinchAction = new __PinchAction(%s);"""
37 % done_callback) 43 % done_callback)
38 44
45 @staticmethod
46 def _GetDefaultScaleFactorForPage(tab):
47 current_scale_factor = tab.EvaluateJavaScript(
48 'window.outerWidth / window.innerWidth')
49 return 3.0 / current_scale_factor
50
39 def RunGesture(self, page, tab): 51 def RunGesture(self, page, tab):
40 left_anchor_percentage = getattr(self, 'left_anchor_percentage', 0.5) 52 left_anchor_percentage = getattr(self, 'left_anchor_percentage', 0.5)
41 top_anchor_percentage = getattr(self, 'top_anchor_percentage', 0.5) 53 top_anchor_percentage = getattr(self, 'top_anchor_percentage', 0.5)
42 zoom_in = getattr(self, 'zoom_in', True) 54 scale_factor = getattr(self, 'scale_factor',
43 pixels_to_cover = getattr(self, 'pixels_to_cover', 500) 55 PinchAction._GetDefaultScaleFactorForPage(tab))
44 speed = getattr(self, 'speed', 800) 56 speed = getattr(self, 'speed', 800)
45 57
46 if hasattr(self, 'element_function'): 58 if hasattr(self, 'element_function'):
47 tab.ExecuteJavaScript(""" 59 tab.ExecuteJavaScript("""
48 (%s)(function(element) { window.__pinchAction.start( 60 (%s)(function(element) { window.__pinchAction.start(
49 { element: element, 61 { element: element,
50 left_anchor_percentage: %s, 62 left_anchor_percentage: %s,
51 top_anchor_percentage: %s, 63 top_anchor_percentage: %s,
52 zoom_in: %s, 64 scale_factor: %s,
53 pixels_to_cover: %s,
54 speed: %s }) 65 speed: %s })
55 });""" % (self.element_function, 66 });""" % (self.element_function,
56 left_anchor_percentage, 67 left_anchor_percentage,
57 top_anchor_percentage, 68 top_anchor_percentage,
58 'true' if zoom_in else 'false', 69 scale_factor,
59 pixels_to_cover,
60 speed)) 70 speed))
61 else: 71 else:
62 tab.ExecuteJavaScript(""" 72 tab.ExecuteJavaScript("""
63 window.__pinchAction.start( 73 window.__pinchAction.start(
64 { element: document.body, 74 { element: document.body,
65 left_anchor_percentage: %s, 75 left_anchor_percentage: %s,
66 top_anchor_percentage: %s, 76 top_anchor_percentage: %s,
67 zoom_in: %s, 77 scale_factor: %s,
68 pixels_to_cover: %s,
69 speed: %s });""" 78 speed: %s });"""
70 % (left_anchor_percentage, 79 % (left_anchor_percentage,
71 top_anchor_percentage, 80 top_anchor_percentage,
72 'true' if zoom_in else 'false', 81 scale_factor,
73 pixels_to_cover,
74 speed)) 82 speed))
75 83
76 tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60) 84 tab.WaitForJavaScriptExpression('window.__pinchActionDone', 60)
77 85
78 def CanBeBound(self): 86 def CanBeBound(self):
79 return True 87 return True
80 88
81 def BindMeasurementJavaScript(self, tab, start_js, stop_js): 89 def BindMeasurementJavaScript(self, tab, start_js, stop_js):
82 # Make the pinch action start and stop measurement automatically. 90 # Make the pinch action start and stop measurement automatically.
83 tab.ExecuteJavaScript(""" 91 tab.ExecuteJavaScript("""
84 window.__pinchAction.beginMeasuringHook = function() { %s }; 92 window.__pinchAction.beginMeasuringHook = function() { %s };
85 window.__pinchAction.endMeasuringHook = function() { %s }; 93 window.__pinchAction.endMeasuringHook = function() { %s };
86 """ % (start_js, stop_js)) 94 """ % (start_js, stop_js))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698