OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 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 from telemetry.page import page as page_module | |
5 from telemetry.page import page_set as page_set_module | |
6 | |
7 | |
8 class KeyDesktopMoveCasesPage(page_module.Page): | |
9 | |
10 def __init__(self, url, page_set, name='', credentials=None): | |
11 super(KeyDesktopMoveCasesPage, self).__init__( | |
12 url=url, page_set=page_set, name=name, | |
13 credentials_path = 'data/credentials.json') | |
Sami
2015/03/25 20:55:00
nit: no spaces around the '='.
ssid
2015/03/27 10:43:05
Done.
| |
14 self.archive_data_file = 'data/key_desktop_move_cases.json' | |
15 self.user_agent_type = 'desktop' | |
16 self.credentials = credentials | |
17 | |
18 | |
19 class GmailMouseScrollPage(KeyDesktopMoveCasesPage): | |
20 | |
21 """ Why: productivity, top google properties """ | |
22 | |
23 def __init__(self, page_set): | |
24 super(GmailMouseScrollPage, self).__init__( | |
25 url='https://mail.google.com/mail/', | |
26 page_set=page_set) | |
27 | |
28 self.scrollable_element_function = ''' | |
29 function(callback) { | |
30 gmonkey.load('2.0', function(api) { | |
31 callback(api.getScrollableElement()); | |
32 }); | |
33 }''' | |
34 self.credentials = 'google' | |
35 | |
36 def RunNavigateSteps(self, action_runner): | |
37 super(GmailMouseScrollPage, self).RunNavigateSteps(action_runner) | |
38 action_runner.WaitForJavaScriptCondition( | |
39 'window.gmonkey !== undefined &&' | |
40 'document.getElementById("gb") !== null') | |
41 # This check is needed for gmonkey to load completely. | |
42 action_runner.WaitForJavaScriptCondition( | |
43 'document.readyState == "complete"') | |
44 | |
45 def RunPageInteractions(self, action_runner): | |
46 action_runner.ExecuteJavaScript(''' | |
47 gmonkey.load('2.0', function(api) { | |
48 window.__scrollableElementForTelemetry = api.getScrollableElement(); | |
49 });''') | |
50 action_runner.WaitForJavaScriptCondition( | |
51 'window.__scrollableElementForTelemetry != null') | |
52 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner) | |
53 | |
54 interaction = action_runner.BeginGestureInteraction( | |
55 'DragAction') | |
56 action_runner.DragPage(left_start_ratio=scrollbar_x, | |
57 top_start_ratio=start_y, left_end_ratio=scrollbar_x, | |
58 top_end_ratio=end_y, speed_in_pixels_per_second=100, | |
59 element_function='window.__scrollableElementForTelemetry') | |
60 interaction.End() | |
61 | |
62 def _CalculateScrollBarRatios(self, action_runner): | |
63 viewport_height = float(action_runner.EvaluateJavaScript( | |
64 'window.__scrollableElementForTelemetry.clientHeight')) | |
65 content_height = float(action_runner.EvaluateJavaScript( | |
66 'window.__scrollableElementForTelemetry.scrollHeight')) | |
67 viewport_width = float(action_runner.EvaluateJavaScript( | |
68 'window.__scrollableElementForTelemetry.offsetWidth')) | |
69 scrollbar_width = float(action_runner.EvaluateJavaScript(''' | |
70 window.__scrollableElementForTelemetry.offsetWidth - | |
71 window.__scrollableElementForTelemetry.scrollWidth''')) | |
72 | |
73 # This calculation is correct only when the element doesn't have border or | |
74 # padding or scroll buttons (eg: gmail mail element). | |
75 scrollbar_start_mid_y = viewport_height / (2 * content_height) | |
76 scrollbar_end_mid_y = 1 - scrollbar_start_mid_y | |
77 scrollbar_mid_x_offset = scrollbar_width / (2 * viewport_width) | |
78 scrollbar_mid_x = 1 - scrollbar_mid_x_offset | |
79 return scrollbar_mid_x, scrollbar_start_mid_y, scrollbar_end_mid_y | |
picksi
2015/03/25 14:13:05
As per our conversation: The purpose of the scroll
ssid
2015/03/27 10:43:04
Done.
| |
80 | |
81 | |
82 class GoogleMapsPage(KeyDesktopMoveCasesPage): | |
83 | |
84 """ Why: productivity, top google properties; Supports drag gesturee """ | |
85 | |
86 def __init__(self, page_set): | |
87 super(GoogleMapsPage, self).__init__( | |
88 url='https://www.google.co.uk/maps/@51.5043968,-0.1526806', | |
89 page_set=page_set, | |
90 name='Maps') | |
91 | |
92 def RunNavigateSteps(self, action_runner): | |
93 super(GoogleMapsPage, self).RunNavigateSteps(action_runner) | |
94 action_runner.WaitForElement(selector='.widget-scene-canvas') | |
95 action_runner.WaitForElement(selector='.widget-zoom-in') | |
96 action_runner.WaitForElement(selector='.widget-zoom-out') | |
97 | |
98 def RunPageInteractions(self, action_runner): | |
99 for _ in range(3): | |
picksi
2015/03/25 14:13:04
I didn't know you could do this! I assume this is
| |
100 action_runner.Wait(2) | |
101 interaction = action_runner.BeginGestureInteraction( | |
102 'DragAction', repeatable=True) | |
103 action_runner.DragPage(left_start_ratio=0.5, top_start_ratio=0.75, | |
104 left_end_ratio=0.75, top_end_ratio=0.5) | |
105 interaction.End() | |
106 # TODO(ssid): Add zoom gestures after fixing bug crbug.com/462214. | |
107 | |
108 | |
109 class KeyDesktopMoveCasesPageSet(page_set_module.PageSet): | |
110 | |
111 """ Special cases for move gesture """ | |
112 | |
113 def __init__(self): | |
114 super(KeyDesktopMoveCasesPageSet, self).__init__( | |
115 archive_data_file='data/key_desktop_move_cases.json', | |
116 bucket=page_set_module.PARTNER_BUCKET) | |
117 | |
118 self.AddUserStory(GmailMouseScrollPage(self)) | |
119 self.AddUserStory(GoogleMapsPage(self)) | |
OLD | NEW |