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