OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 from telemetry.page import page as page_module | 4 from telemetry.page import page as page_module |
5 from telemetry.page import shared_page_state | 5 from telemetry.page import shared_page_state |
6 from telemetry import story | 6 from telemetry import story |
7 | 7 |
8 | 8 |
9 class KeyDesktopMoveCasesPage(page_module.Page): | 9 class KeyDesktopMoveCasesPage(page_module.Page): |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 self.scrollable_element_function = ''' | 29 self.scrollable_element_function = ''' |
30 function(callback) { | 30 function(callback) { |
31 gmonkey.load('2.0', function(api) { | 31 gmonkey.load('2.0', function(api) { |
32 callback(api.getScrollableElement()); | 32 callback(api.getScrollableElement()); |
33 }); | 33 }); |
34 }''' | 34 }''' |
35 self.credentials = 'google' | 35 self.credentials = 'google' |
36 | 36 |
37 def RunNavigateSteps(self, action_runner): | 37 def RunNavigateSteps(self, action_runner): |
38 super(GmailMouseScrollPage, self).RunNavigateSteps(action_runner) | 38 super(GmailMouseScrollPage, self).RunNavigateSteps(action_runner) |
39 action_runner.WaitForJavaScriptCondition2( | 39 action_runner.WaitForJavaScriptCondition( |
40 'window.gmonkey !== undefined &&' | 40 'window.gmonkey !== undefined &&' |
41 'document.getElementById("gb") !== null') | 41 'document.getElementById("gb") !== null') |
42 # This check is needed for gmonkey to load completely. | 42 # This check is needed for gmonkey to load completely. |
43 action_runner.WaitForJavaScriptCondition2( | 43 action_runner.WaitForJavaScriptCondition( |
44 'document.readyState == "complete"') | 44 'document.readyState == "complete"') |
45 | 45 |
46 def RunPageInteractions(self, action_runner): | 46 def RunPageInteractions(self, action_runner): |
47 action_runner.ExecuteJavaScript2(''' | 47 action_runner.ExecuteJavaScript(''' |
48 gmonkey.load('2.0', function(api) { | 48 gmonkey.load('2.0', function(api) { |
49 window.__scrollableElementForTelemetry = api.getScrollableElement(); | 49 window.__scrollableElementForTelemetry = api.getScrollableElement(); |
50 });''') | 50 });''') |
51 action_runner.WaitForJavaScriptCondition2( | 51 action_runner.WaitForJavaScriptCondition( |
52 'window.__scrollableElementForTelemetry != null') | 52 'window.__scrollableElementForTelemetry != null') |
53 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner) | 53 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner) |
54 | 54 |
55 with action_runner.CreateGestureInteraction('DragAction'): | 55 with action_runner.CreateGestureInteraction('DragAction'): |
56 action_runner.DragPage(left_start_ratio=scrollbar_x, | 56 action_runner.DragPage(left_start_ratio=scrollbar_x, |
57 top_start_ratio=start_y, left_end_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, | 58 top_end_ratio=end_y, speed_in_pixels_per_second=100, |
59 element_function='window.__scrollableElementForTelemetry') | 59 element_function='window.__scrollableElementForTelemetry') |
60 | 60 |
61 def _CalculateScrollBarRatios(self, action_runner): | 61 def _CalculateScrollBarRatios(self, action_runner): |
62 viewport_height = float(action_runner.EvaluateJavaScript2( | 62 viewport_height = float(action_runner.EvaluateJavaScript( |
63 'window.__scrollableElementForTelemetry.clientHeight')) | 63 'window.__scrollableElementForTelemetry.clientHeight')) |
64 content_height = float(action_runner.EvaluateJavaScript2( | 64 content_height = float(action_runner.EvaluateJavaScript( |
65 'window.__scrollableElementForTelemetry.scrollHeight')) | 65 'window.__scrollableElementForTelemetry.scrollHeight')) |
66 viewport_width = float(action_runner.EvaluateJavaScript2( | 66 viewport_width = float(action_runner.EvaluateJavaScript( |
67 'window.__scrollableElementForTelemetry.offsetWidth')) | 67 'window.__scrollableElementForTelemetry.offsetWidth')) |
68 scrollbar_width = float(action_runner.EvaluateJavaScript2(''' | 68 scrollbar_width = float(action_runner.EvaluateJavaScript(''' |
69 window.__scrollableElementForTelemetry.offsetWidth - | 69 window.__scrollableElementForTelemetry.offsetWidth - |
70 window.__scrollableElementForTelemetry.scrollWidth''')) | 70 window.__scrollableElementForTelemetry.scrollWidth''')) |
71 | 71 |
72 # This calculation is correct only when the element doesn't have border or | 72 # This calculation is correct only when the element doesn't have border or |
73 # padding or scroll buttons (eg: gmail mail element). | 73 # padding or scroll buttons (eg: gmail mail element). |
74 # Calculating the mid point of start of scrollbar. | 74 # Calculating the mid point of start of scrollbar. |
75 scrollbar_height_ratio = viewport_height / content_height | 75 scrollbar_height_ratio = viewport_height / content_height |
76 scrollbar_start_mid_y = scrollbar_height_ratio / 2 | 76 scrollbar_start_mid_y = scrollbar_height_ratio / 2 |
77 scrollbar_width_ratio = scrollbar_width / viewport_width | 77 scrollbar_width_ratio = scrollbar_width / viewport_width |
78 scrollbar_mid_x_right_offset = scrollbar_width_ratio / 2 | 78 scrollbar_mid_x_right_offset = scrollbar_width_ratio / 2 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 """ Special cases for move gesture """ | 114 """ Special cases for move gesture """ |
115 | 115 |
116 def __init__(self): | 116 def __init__(self): |
117 super(KeyDesktopMoveCasesPageSet, self).__init__( | 117 super(KeyDesktopMoveCasesPageSet, self).__init__( |
118 archive_data_file='data/key_desktop_move_cases.json', | 118 archive_data_file='data/key_desktop_move_cases.json', |
119 cloud_storage_bucket=story.PARTNER_BUCKET) | 119 cloud_storage_bucket=story.PARTNER_BUCKET) |
120 | 120 |
121 self.AddStory(GmailMouseScrollPage(self)) | 121 self.AddStory(GmailMouseScrollPage(self)) |
122 self.AddStory(GoogleMapsPage(self)) | 122 self.AddStory(GoogleMapsPage(self)) |
OLD | NEW |