| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 | 5 |
| 6 | 6 |
| 7 class TopPages(page_module.Page): | 7 class TopPages(page_module.Page): |
| 8 | 8 |
| 9 def __init__(self, url, page_set, name='', credentials=None): | 9 def __init__(self, url, page_set, name='', credentials=None): |
| 10 super(TopPages, self).__init__( | 10 super(TopPages, self).__init__( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 super(GmailPage, self).__init__( | 47 super(GmailPage, self).__init__( |
| 48 url='https://mail.google.com/mail/', | 48 url='https://mail.google.com/mail/', |
| 49 page_set=page_set, | 49 page_set=page_set, |
| 50 credentials='google') | 50 credentials='google') |
| 51 | 51 |
| 52 def RunNavigateSteps(self, action_runner): | 52 def RunNavigateSteps(self, action_runner): |
| 53 super(GmailPage, self).RunNavigateSteps(action_runner) | 53 super(GmailPage, self).RunNavigateSteps(action_runner) |
| 54 action_runner.WaitForJavaScriptCondition( | 54 action_runner.WaitForJavaScriptCondition( |
| 55 'window.gmonkey !== undefined &&' | 55 'window.gmonkey !== undefined &&' |
| 56 'document.getElementById("gb") !== null') | 56 'document.getElementById("gb") !== null') |
| 57 # This check is needed for gmonkey to load completely. | |
| 58 action_runner.WaitForJavaScriptCondition( | |
| 59 'document.readyState == "complete"') | |
| 60 | |
| 61 | |
| 62 class GmailMouseScrollPage(GmailPage): | |
| 63 | |
| 64 """ Why: productivity, top google properties """ | |
| 65 | |
| 66 def RunPageInteractions(self, action_runner): | |
| 67 action_runner.ExecuteJavaScript(''' | |
| 68 gmonkey.load('2.0', function(api) { | |
| 69 window.__scrollableElementForTelemetry = api.getScrollableElement(); | |
| 70 });''') | |
| 71 action_runner.WaitForJavaScriptCondition( | |
| 72 'window.__scrollableElementForTelemetry != null') | |
| 73 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner) | |
| 74 | |
| 75 interaction = action_runner.BeginGestureInteraction( | |
| 76 'DragAction') | |
| 77 action_runner.DragPage(left_start_ratio=scrollbar_x, | |
| 78 top_start_ratio=start_y, left_end_ratio=scrollbar_x, | |
| 79 top_end_ratio=end_y, speed_in_pixels_per_second=100, | |
| 80 element_function='window.__scrollableElementForTelemetry') | |
| 81 interaction.End() | |
| 82 | |
| 83 def _CalculateScrollBarRatios(self, action_runner): | |
| 84 viewport_height = float(action_runner.EvaluateJavaScript( | |
| 85 'window.__scrollableElementForTelemetry.clientHeight')) | |
| 86 content_height = float(action_runner.EvaluateJavaScript( | |
| 87 'window.__scrollableElementForTelemetry.scrollHeight')) | |
| 88 viewport_width = float(action_runner.EvaluateJavaScript( | |
| 89 'window.__scrollableElementForTelemetry.offsetWidth')) | |
| 90 scrollbar_width = float(action_runner.EvaluateJavaScript(''' | |
| 91 window.__scrollableElementForTelemetry.offsetWidth - | |
| 92 window.__scrollableElementForTelemetry.scrollWidth''')) | |
| 93 | |
| 94 # This calculation is correct only when the element doesn't have border or | |
| 95 # padding or scroll buttons (eg: gmail mail element). | |
| 96 scrollbar_start_mid_y = viewport_height / (2 * content_height) | |
| 97 scrollbar_end_mid_y = 1 - scrollbar_start_mid_y | |
| 98 scrollbar_mid_x_offset = scrollbar_width / (2 * viewport_width) | |
| 99 scrollbar_mid_x = 1 - scrollbar_mid_x_offset | |
| 100 return scrollbar_mid_x, scrollbar_start_mid_y, scrollbar_end_mid_y | |
| 101 | 57 |
| 102 | 58 |
| 103 class GoogleCalendarPage(TopPages): | 59 class GoogleCalendarPage(TopPages): |
| 104 | 60 |
| 105 """ Why: productivity, top google properties """ | 61 """ Why: productivity, top google properties """ |
| 106 | 62 |
| 107 def __init__(self, page_set): | 63 def __init__(self, page_set): |
| 108 super(GoogleCalendarPage, self).__init__( | 64 super(GoogleCalendarPage, self).__init__( |
| 109 url='https://www.google.com/calendar/', | 65 url='https://www.google.com/calendar/', |
| 110 page_set=page_set, | 66 page_set=page_set, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 135 page_set=page_set, | 91 page_set=page_set, |
| 136 name='Docs (1 open document tab)', | 92 name='Docs (1 open document tab)', |
| 137 credentials='google') | 93 credentials='google') |
| 138 | 94 |
| 139 def RunNavigateSteps(self, action_runner): | 95 def RunNavigateSteps(self, action_runner): |
| 140 super(GoogleDocPage, self).RunNavigateSteps(action_runner) | 96 super(GoogleDocPage, self).RunNavigateSteps(action_runner) |
| 141 action_runner.Wait(2) | 97 action_runner.Wait(2) |
| 142 action_runner.WaitForJavaScriptCondition( | 98 action_runner.WaitForJavaScriptCondition( |
| 143 'document.getElementsByClassName("kix-appview-editor").length') | 99 'document.getElementsByClassName("kix-appview-editor").length') |
| 144 | 100 |
| 145 class GoogleMapsPage(TopPages): | |
| 146 | |
| 147 """ Why: productivity, top google properties; Supports drag gesturee """ | |
| 148 | |
| 149 def __init__(self, page_set): | |
| 150 super(GoogleMapsPage, self).__init__( | |
| 151 url='https://www.google.co.uk/maps/@51.5043968,-0.1526806', | |
| 152 page_set=page_set, | |
| 153 name='Maps') | |
| 154 | |
| 155 def RunNavigateSteps(self, action_runner): | |
| 156 super(GoogleMapsPage, self).RunNavigateSteps(action_runner) | |
| 157 action_runner.WaitForElement(selector='.widget-scene-canvas') | |
| 158 action_runner.WaitForElement(selector='.widget-zoom-in') | |
| 159 action_runner.WaitForElement(selector='.widget-zoom-out') | |
| 160 | 101 |
| 161 class GooglePlusPage(TopPages): | 102 class GooglePlusPage(TopPages): |
| 162 | 103 |
| 163 """ Why: social; top google property; Public profile; infinite scrolls """ | 104 """ Why: social; top google property; Public profile; infinite scrolls """ |
| 164 | 105 |
| 165 def __init__(self, page_set): | 106 def __init__(self, page_set): |
| 166 super(GooglePlusPage, self).__init__( | 107 super(GooglePlusPage, self).__init__( |
| 167 url='https://plus.google.com/110031535020051778989/posts', | 108 url='https://plus.google.com/110031535020051778989/posts', |
| 168 page_set=page_set, | 109 page_set=page_set, |
| 169 credentials='google') | 110 credentials='google') |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 """ Why: #1 games according to Alexa (with actual games in it) """ | 250 """ Why: #1 games according to Alexa (with actual games in it) """ |
| 310 | 251 |
| 311 def __init__(self, page_set): | 252 def __init__(self, page_set): |
| 312 super(YahooGamesPage, self).__init__( | 253 super(YahooGamesPage, self).__init__( |
| 313 url='http://games.yahoo.com', | 254 url='http://games.yahoo.com', |
| 314 page_set=page_set) | 255 page_set=page_set) |
| 315 | 256 |
| 316 def RunNavigateSteps(self, action_runner): | 257 def RunNavigateSteps(self, action_runner): |
| 317 super(YahooGamesPage, self).RunNavigateSteps(action_runner) | 258 super(YahooGamesPage, self).RunNavigateSteps(action_runner) |
| 318 action_runner.Wait(2) | 259 action_runner.Wait(2) |
| OLD | NEW |