| 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 from telemetry.page import page_set as page_set_module | 5 from telemetry.page import page_set as page_set_module |
| 6 | 6 |
| 7 from page_sets import top_pages | 7 from page_sets import top_pages |
| 8 | 8 |
| 9 | 9 |
| 10 def _IssueMarkerAndScroll(action_runner): | 10 def _IssueMarkerAndScroll(action_runner): |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 });''') | 46 });''') |
| 47 action_runner.WaitForJavaScriptCondition( | 47 action_runner.WaitForJavaScriptCondition( |
| 48 'window.__scrollableElementForTelemetry != null') | 48 'window.__scrollableElementForTelemetry != null') |
| 49 interaction = action_runner.BeginGestureInteraction( | 49 interaction = action_runner.BeginGestureInteraction( |
| 50 'ScrollAction', is_smooth=True) | 50 'ScrollAction', is_smooth=True) |
| 51 action_runner.ScrollElement( | 51 action_runner.ScrollElement( |
| 52 element_function='window.__scrollableElementForTelemetry') | 52 element_function='window.__scrollableElementForTelemetry') |
| 53 interaction.End() | 53 interaction.End() |
| 54 | 54 |
| 55 | 55 |
| 56 class GmailMouseScrollPage(top_pages.GmailPage): | |
| 57 | |
| 58 """ Why: productivity, top google properties """ | |
| 59 | |
| 60 def RunPageInteractions(self, action_runner): | |
| 61 action_runner.ExecuteJavaScript(''' | |
| 62 gmonkey.load('2.0', function(api) { | |
| 63 window.__scrollableElementForTelemetry = api.getScrollableElement(); | |
| 64 });''') | |
| 65 action_runner.WaitForJavaScriptCondition( | |
| 66 'window.__scrollableElementForTelemetry != null') | |
| 67 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner) | |
| 68 | |
| 69 interaction = action_runner.BeginGestureInteraction( | |
| 70 'DragAction', is_smooth=True) | |
| 71 action_runner.DragPage(left_start_ratio=scrollbar_x, | |
| 72 top_start_ratio=start_y, left_end_ratio=scrollbar_x, | |
| 73 top_end_ratio=end_y, speed_in_pixels_per_second=100, | |
| 74 element_function='window.__scrollableElementForTelemetry') | |
| 75 interaction.End() | |
| 76 | |
| 77 def CanRunOnBrowser(self, browser_info): | |
| 78 return (browser_info._browser._platform_backend.platform.GetOSName() != | |
| 79 'android') | |
| 80 | |
| 81 def _CalculateScrollBarRatios(self, action_runner): | |
| 82 viewport_height = float(action_runner.EvaluateJavaScript( | |
| 83 'window.__scrollableElementForTelemetry.clientHeight')) | |
| 84 content_height = float(action_runner.EvaluateJavaScript( | |
| 85 'window.__scrollableElementForTelemetry.scrollHeight')) | |
| 86 viewport_width = float(action_runner.EvaluateJavaScript( | |
| 87 'window.__scrollableElementForTelemetry.offsetWidth')) | |
| 88 scrollbar_width = float(action_runner.EvaluateJavaScript(''' | |
| 89 window.__scrollableElementForTelemetry.offsetWidth - | |
| 90 window.__scrollableElementForTelemetry.scrollWidth''')) | |
| 91 | |
| 92 # This calculation is correct only when the element doesn't have border or | |
| 93 # padding or scroll buttons (eg: gmail mail element). | |
| 94 scrollbar_start_mid_y = viewport_height / (2 * content_height) | |
| 95 scrollbar_end_mid_y = 1 - scrollbar_start_mid_y | |
| 96 scrollbar_mid_x_offset = scrollbar_width / (2 * viewport_width) | |
| 97 scrollbar_mid_x = 1 - scrollbar_mid_x_offset | |
| 98 return scrollbar_mid_x, scrollbar_start_mid_y, scrollbar_end_mid_y | |
| 99 | |
| 100 | |
| 101 class GoogleCalendarSmoothPage(top_pages.GoogleCalendarPage): | 56 class GoogleCalendarSmoothPage(top_pages.GoogleCalendarPage): |
| 102 | 57 |
| 103 """ Why: productivity, top google properties """ | 58 """ Why: productivity, top google properties """ |
| 104 | 59 |
| 105 def RunPageInteractions(self, action_runner): | 60 def RunPageInteractions(self, action_runner): |
| 106 interaction = action_runner.BeginGestureInteraction( | 61 interaction = action_runner.BeginGestureInteraction( |
| 107 'ScrollAction', is_smooth=True) | 62 'ScrollAction', is_smooth=True) |
| 108 action_runner.ScrollElement(selector='#scrolltimedeventswk') | 63 action_runner.ScrollElement(selector='#scrolltimedeventswk') |
| 109 interaction.End() | 64 interaction.End() |
| 110 | 65 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 111 |
| 157 def __init__(self): | 112 def __init__(self): |
| 158 super(Top25SmoothPageSet, self).__init__( | 113 super(Top25SmoothPageSet, self).__init__( |
| 159 user_agent_type='desktop', | 114 user_agent_type='desktop', |
| 160 archive_data_file='data/top_25_smooth.json', | 115 archive_data_file='data/top_25_smooth.json', |
| 161 bucket=page_set_module.PARTNER_BUCKET) | 116 bucket=page_set_module.PARTNER_BUCKET) |
| 162 | 117 |
| 163 self.AddUserStory(_CreatePageClassWithSmoothInteractions( | 118 self.AddUserStory(_CreatePageClassWithSmoothInteractions( |
| 164 top_pages.GoogleWebSearchPage)(self)) | 119 top_pages.GoogleWebSearchPage)(self)) |
| 165 self.AddUserStory(GmailSmoothPage(self)) | 120 self.AddUserStory(GmailSmoothPage(self)) |
| 166 self.AddUserStory(GmailMouseScrollPage(self)) | |
| 167 self.AddUserStory(GoogleCalendarSmoothPage(self)) | 121 self.AddUserStory(GoogleCalendarSmoothPage(self)) |
| 168 self.AddUserStory(_CreatePageClassWithSmoothInteractions( | 122 self.AddUserStory(_CreatePageClassWithSmoothInteractions( |
| 169 top_pages.GoogleImageSearchPage)(self)) | 123 top_pages.GoogleImageSearchPage)(self)) |
| 170 self.AddUserStory(GoogleDocSmoothPage(self)) | 124 self.AddUserStory(GoogleDocSmoothPage(self)) |
| 171 self.AddUserStory(_CreatePageClassWithSmoothInteractions( | 125 self.AddUserStory(_CreatePageClassWithSmoothInteractions( |
| 172 top_pages.GooglePlusPage)(self)) | 126 top_pages.GooglePlusPage)(self)) |
| 173 self.AddUserStory(_CreatePageClassWithSmoothInteractions( | 127 self.AddUserStory(_CreatePageClassWithSmoothInteractions( |
| 174 top_pages.YoutubePage)(self)) | 128 top_pages.YoutubePage)(self)) |
| 175 self.AddUserStory(_CreatePageClassWithSmoothInteractions( | 129 self.AddUserStory(_CreatePageClassWithSmoothInteractions( |
| 176 top_pages.BlogspotPage)(self)) | 130 top_pages.BlogspotPage)(self)) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 # Why: #1 Alexa reference | 162 # Why: #1 Alexa reference |
| 209 'http://answers.yahoo.com', | 163 'http://answers.yahoo.com', |
| 210 # Why: #1 Alexa sports | 164 # Why: #1 Alexa sports |
| 211 'http://sports.yahoo.com/', | 165 'http://sports.yahoo.com/', |
| 212 # Why: top tech blog | 166 # Why: top tech blog |
| 213 'http://techcrunch.com' | 167 'http://techcrunch.com' |
| 214 ] | 168 ] |
| 215 | 169 |
| 216 for url in other_urls: | 170 for url in other_urls: |
| 217 self.AddUserStory(TopSmoothPage(url, self)) | 171 self.AddUserStory(TopSmoothPage(url, self)) |
| OLD | NEW |