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 | 4 |
5 from telemetry.core import exceptions | 5 from page_sets import repeatable_synthesize_scroll_gesture_shared_state |
| 6 |
6 from telemetry.page import page as page_module | 7 from telemetry.page import page as page_module |
7 from telemetry import story | 8 from telemetry import story |
8 | 9 |
9 | 10 |
10 class SwiffyPage(page_module.Page): | 11 class SwiffyPage(page_module.Page): |
11 | 12 |
12 def __init__(self, url, page_set): | 13 def __init__(self, url, page_set): |
13 super(SwiffyPage, self).__init__(url=url, page_set=page_set, | 14 super(SwiffyPage, self).__init__(url=url, page_set=page_set, |
14 make_javascript_deterministic=False) | 15 make_javascript_deterministic=False) |
15 | 16 |
(...skipping 11 matching lines...) Expand all Loading... |
27 'document.getElementsByTagName("head")[0].appendChild(meta);') | 28 'document.getElementsByTagName("head")[0].appendChild(meta);') |
28 action_runner.EvaluateJavaScript(viewport_js) | 29 action_runner.EvaluateJavaScript(viewport_js) |
29 | 30 |
30 def RunPageInteractions(self, action_runner): | 31 def RunPageInteractions(self, action_runner): |
31 with action_runner.CreateInteraction('ToughAd'): | 32 with action_runner.CreateInteraction('ToughAd'): |
32 action_runner.Wait(10) | 33 action_runner.Wait(10) |
33 | 34 |
34 | 35 |
35 class ScrollingPage(page_module.Page): | 36 class ScrollingPage(page_module.Page): |
36 | 37 |
37 def __init__(self, url, page_set, top_start_ratio=.5, | 38 def __init__(self, url, page_set, make_javascript_deterministic=True, |
38 make_javascript_deterministic=True): | 39 y_scroll_distance_multiplier=0.5): |
39 super(ScrollingPage, self).__init__(url=url, page_set=page_set, | 40 super(ScrollingPage, self).__init__( |
40 make_javascript_deterministic=make_javascript_deterministic) | 41 url=url, |
41 self._top_start_ratio = top_start_ratio | 42 page_set=page_set, |
| 43 make_javascript_deterministic=make_javascript_deterministic, |
| 44 shared_page_state_class=( |
| 45 repeatable_synthesize_scroll_gesture_shared_state.\ |
| 46 RepeatableSynthesizeScrollGestureSharedState)) |
| 47 self._y_scroll_distance_multiplier = y_scroll_distance_multiplier |
42 | 48 |
43 def RunNavigateSteps(self, action_runner): | 49 def RunNavigateSteps(self, action_runner): |
44 # Rewrite file urls to point to the replay server instead. | 50 # Rewrite file urls to point to the replay server instead. |
45 if self.is_file: | 51 if self.is_file: |
46 url = self.file_path_url_with_scheme | 52 url = self.file_path_url_with_scheme |
47 url = action_runner.tab.browser.http_server.UrlOf(url[len('file://'):]) | 53 url = action_runner.tab.browser.http_server.UrlOf(url[len('file://'):]) |
48 else: | 54 else: |
49 url = self._url | 55 url = self._url |
50 action_runner.tab.Navigate(url) | 56 action_runner.tab.Navigate(url) |
51 | 57 |
52 # Give the page one second to become interactive and start scrolling after | 58 # Wait for the page to be scrollable. Simultaneously (to reduce latency due |
53 # the timeout regardless of the document's ready state. | 59 # to main thread round trips), insert a no-op touch handler on the body. |
54 try: | 60 # Most ads have touch handlers and we want to simulate the worst case of the |
55 action_runner.tab.WaitForDocumentReadyStateToBeInteractiveOrBetter(1) | 61 # user trying to scroll the page by grabbing an ad. |
56 except exceptions.TimeoutException: | |
57 pass | |
58 # Wait for the document to have a body so that we can scroll. | |
59 # Simultaneously (to reduce latency), insert a no-op touch handler on the | |
60 # body. Most ads have touch handlers and we want to simulate the worst case | |
61 # of the user trying to scroll the page by grabbing an ad. | |
62 action_runner.WaitForJavaScriptCondition( | 62 action_runner.WaitForJavaScriptCondition( |
63 '!(document.body == null || ' | 63 'document.body != null && ' |
64 ' document.body.addEventListener("touchstart", function() {}))') | 64 'document.body.scrollHeight > window.innerHeight && ' |
| 65 '!document.body.addEventListener("touchstart", function() {})') |
65 | 66 |
66 def RunPageInteractions(self, action_runner): | 67 def RunPageInteractions(self, action_runner): |
67 for _ in range(10): | 68 action_runner.RepeatableBrowserDrivenScroll( |
68 with action_runner.CreateGestureInteraction('ScrollAction', | 69 y_scroll_distance_ratio=self._y_scroll_distance_multiplier, |
69 repeatable=True): | 70 repeat_count=9) |
70 action_runner.ScrollPage(distance=500, | |
71 top_start_ratio=self._top_start_ratio) | |
72 action_runner.Wait(.25) | |
73 | 71 |
74 | 72 |
75 class ScrollingForbesPage(ScrollingPage): | 73 class ScrollingForbesPage(ScrollingPage): |
76 | 74 |
77 def __init__(self, url, page_set): | 75 def __init__(self, url, page_set): |
78 # forbes.com uses a strange dynamic transform on the body element, | 76 # forbes.com uses a strange dynamic transform on the body element, |
79 # which occasionally causes us to try scrolling from outside the | 77 # which occasionally causes us to try scrolling from outside the |
80 # screen. Start at the very top of the viewport to avoid this. | 78 # screen. Start at the very top of the viewport to avoid this. |
81 super(ScrollingForbesPage, self).__init__( | 79 super(ScrollingForbesPage, self).__init__( |
82 url=url, page_set=page_set, top_start_ratio=0, | 80 url=url, page_set=page_set, make_javascript_deterministic=False) |
83 make_javascript_deterministic=False) | |
84 | 81 |
85 def RunNavigateSteps(self, action_runner): | 82 def RunNavigateSteps(self, action_runner): |
86 super(ScrollingForbesPage, self).RunNavigateSteps(action_runner) | 83 super(ScrollingForbesPage, self).RunNavigateSteps(action_runner) |
87 # Wait until the interstitial banner goes away. | 84 # Wait until the interstitial banner goes away. |
88 action_runner.WaitForJavaScriptCondition( | 85 action_runner.WaitForJavaScriptCondition( |
89 'window.location.pathname.indexOf("welcome") == -1') | 86 'window.location.pathname.indexOf("welcome") == -1') |
90 | 87 |
91 | 88 |
92 class ToughAdCasesPageSet(story.StorySet): | 89 class ToughAdCasesPageSet(story.StorySet): |
93 """Pages for measuring rendering performance with advertising content.""" | 90 """Pages for measuring rendering performance with advertising content.""" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 148 |
152 class ScrollingToughAdCasesPageSet(story.StorySet): | 149 class ScrollingToughAdCasesPageSet(story.StorySet): |
153 """Pages for measuring scrolling performance with advertising content.""" | 150 """Pages for measuring scrolling performance with advertising content.""" |
154 | 151 |
155 def __init__(self): | 152 def __init__(self): |
156 super(ScrollingToughAdCasesPageSet, self).__init__( | 153 super(ScrollingToughAdCasesPageSet, self).__init__( |
157 archive_data_file='data/tough_ad_cases.json', | 154 archive_data_file='data/tough_ad_cases.json', |
158 cloud_storage_bucket=story.INTERNAL_BUCKET) | 155 cloud_storage_bucket=story.INTERNAL_BUCKET) |
159 | 156 |
160 self.AddStory(ScrollingPage('file://tough_ad_cases/' | 157 self.AddStory(ScrollingPage('file://tough_ad_cases/' |
161 'swiffy_collection.html', self, make_javascript_deterministic=False)) | 158 'swiffy_collection.html', self, make_javascript_deterministic=False, |
| 159 y_scroll_distance_multiplier=0.25)) |
162 self.AddStory(ScrollingPage('file://tough_ad_cases/' | 160 self.AddStory(ScrollingPage('file://tough_ad_cases/' |
163 'swiffy_webgl_collection.html', | 161 'swiffy_webgl_collection.html', |
164 self, make_javascript_deterministic=False)) | 162 self, make_javascript_deterministic=False)) |
165 self.AddStory(ScrollingPage('http://www.latimes.com', self)) | 163 self.AddStory(ScrollingPage('http://www.latimes.com', self)) |
166 self.AddStory(ScrollingForbesPage('http://www.forbes.com/sites/parmyolson/' | 164 self.AddStory(ScrollingForbesPage('http://www.forbes.com/sites/parmyolson/' |
167 '2015/07/29/jana-mobile-data-facebook-internet-org/', self)) | 165 '2015/07/29/jana-mobile-data-facebook-internet-org/', self)) |
168 self.AddStory(ScrollingPage('http://androidcentral.com', self)) | 166 self.AddStory(ScrollingPage('http://androidcentral.com', self)) |
169 self.AddStory(ScrollingPage('http://mashable.com', self, top_start_ratio=0)) | 167 self.AddStory(ScrollingPage('http://mashable.com', self, |
| 168 y_scroll_distance_multiplier=0.25)) |
170 self.AddStory(ScrollingPage('http://www.androidauthority.com/' | 169 self.AddStory(ScrollingPage('http://www.androidauthority.com/' |
171 'reduce-data-use-turn-on-data-compression-in-chrome-630064/', self)) | 170 'reduce-data-use-turn-on-data-compression-in-chrome-630064/', self)) |
172 self.AddStory(ScrollingPage('http://www.cnn.com/2015/01/09/politics/' | 171 self.AddStory(ScrollingPage('http://www.cnn.com/2015/01/09/politics/' |
173 'nebraska-keystone-pipeline/index.html', self, top_start_ratio=0)) | 172 'nebraska-keystone-pipeline/index.html', self)) |
174 # Disabled: crbug.com/520509 | 173 # Disabled: crbug.com/520509 |
175 #self.AddStory(ScrollingPage('http://time.com/3977891/' | 174 #self.AddStory(ScrollingPage('http://time.com/3977891/' |
176 # 'donald-trump-debate-republican/', self)) | 175 # 'donald-trump-debate-republican/', self)) |
177 self.AddStory(ScrollingPage('http://www.theguardian.com/uk', self)) | 176 self.AddStory(ScrollingPage('http://www.theguardian.com/uk', self)) |
178 self.AddStory(ScrollingPage('http://m.tmz.com', self)) | 177 self.AddStory(ScrollingPage('http://m.tmz.com', self, |
179 self.AddStory(ScrollingPage('http://androidpolice.com', self, | 178 y_scroll_distance_multiplier=0.25)) |
180 top_start_ratio=0)) | 179 self.AddStory(ScrollingPage('http://androidpolice.com', self)) |
OLD | NEW |