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
3 # found in the LICENSE file.
5 from page_sets
import repeatable_synthesize_scroll_gesture_shared_state
7 from telemetry
.page
import page
as page_module
8 from telemetry
import story
11 class SwiffyPage(page_module
.Page
):
13 def __init__(self
, url
, page_set
):
14 super(SwiffyPage
, self
).__init
__(url
=url
, page_set
=page_set
,
15 make_javascript_deterministic
=False)
17 def RunNavigateSteps(self
, action_runner
):
18 super(SwiffyPage
, self
).RunNavigateSteps(action_runner
)
19 # Swiffy overwrites toString() to return a constant string, so "undo" that
20 # here so that we don't think it has stomped over console.time.
21 action_runner
.EvaluateJavaScript(
22 'Function.prototype.toString = function() { return "[native code]"; }')
23 # Make sure we have a reasonable viewport for mobile.
25 'var meta = document.createElement("meta");'
26 'meta.name = "viewport";'
27 'meta.content = "width=device-width";'
28 'document.getElementsByTagName("head")[0].appendChild(meta);')
29 action_runner
.EvaluateJavaScript(viewport_js
)
31 def RunPageInteractions(self
, action_runner
):
32 with action_runner
.CreateInteraction('ToughAd'):
33 action_runner
.Wait(10)
36 class ScrollingPage(page_module
.Page
):
38 def __init__(self
, url
, page_set
, make_javascript_deterministic
=True,
39 y_scroll_distance_multiplier
=0.5, bidirectional_scroll
=False,
40 wait_for_interactive_or_better
=False):
41 super(ScrollingPage
, self
).__init
__(
44 make_javascript_deterministic
=make_javascript_deterministic
,
45 shared_page_state_class
=(
46 repeatable_synthesize_scroll_gesture_shared_state
.\
47 RepeatableSynthesizeScrollGestureSharedState
))
48 self
._y
_scroll
_distance
_multiplier
= y_scroll_distance_multiplier
49 self
._bidirectional
_scroll
= bidirectional_scroll
50 self
._wait
_for
_interactive
_or
_better
= wait_for_interactive_or_better
52 def RunNavigateSteps(self
, action_runner
):
53 # Rewrite file urls to point to the replay server instead.
55 url
= self
.file_path_url_with_scheme
56 url
= action_runner
.tab
.browser
.http_server
.UrlOf(url
[len('file://'):])
59 action_runner
.tab
.Navigate(url
)
61 # Wait for the page to be scrollable. Simultaneously (to reduce latency due
62 # to main thread round trips), insert a no-op touch handler on the body.
63 # Most ads have touch handlers and we want to simulate the worst case of the
64 # user trying to scroll the page by grabbing an ad.
65 if self
._wait
_for
_interactive
_or
_better
:
66 action_runner
.WaitForJavaScriptCondition(
67 '(document.readyState == "interactive" || '
68 'document.readyState == "complete") &&'
69 'document.body != null && '
70 'document.body.scrollHeight > window.innerHeight && '
71 '!document.body.addEventListener("touchstart", function() {})')
73 action_runner
.WaitForJavaScriptCondition(
74 'document.body != null && '
75 'document.body.scrollHeight > window.innerHeight && '
76 '!document.body.addEventListener("touchstart", function() {})')
78 def RunPageInteractions(self
, action_runner
):
79 if self
._bidirectional
_scroll
:
80 action_runner
.RepeatableBrowserDrivenScroll(
81 y_scroll_distance_ratio
=self
._y
_scroll
_distance
_multiplier
,
83 action_runner
.RepeatableBrowserDrivenScroll(
84 y_scroll_distance_ratio
=-self
._y
_scroll
_distance
_multiplier
* .5,
87 action_runner
.RepeatableBrowserDrivenScroll(
88 y_scroll_distance_ratio
=self
._y
_scroll
_distance
_multiplier
,
92 class ScrollingForbesPage(ScrollingPage
):
94 def __init__(self
, url
, page_set
, bidirectional_scroll
=False):
95 # forbes.com uses a strange dynamic transform on the body element,
96 # which occasionally causes us to try scrolling from outside the
97 # screen. Start at the very top of the viewport to avoid this.
98 super(ScrollingForbesPage
, self
).__init
__(
99 url
=url
, page_set
=page_set
, make_javascript_deterministic
=False,
100 bidirectional_scroll
=bidirectional_scroll
,
101 wait_for_interactive_or_better
=True)
103 def RunNavigateSteps(self
, action_runner
):
104 super(ScrollingForbesPage
, self
).RunNavigateSteps(action_runner
)
105 # Wait until the interstitial banner goes away.
106 action_runner
.WaitForJavaScriptCondition(
107 'window.location.pathname.indexOf("welcome") == -1')
110 class ToughAdCasesPageSet(story
.StorySet
):
111 """Pages for measuring rendering performance with advertising content."""
114 super(ToughAdCasesPageSet
, self
).__init
__(
115 archive_data_file
='data/tough_ad_cases.json',
116 cloud_storage_bucket
=story
.INTERNAL_BUCKET
)
118 base_url
= 'http://localhost:8000'
120 # See go/swiffy-chrome-samples for how to add new pages here or how to
121 # update the existing ones.
123 'CICAgICQ15a9NxDIARjIASgBMghBC1XuTk8ezw.swiffy72.html',
124 'shapes-CK7ptO3F8bi2KxDQAhiYAigBMgij6QBQtD2gyA.swiffy72.html',
125 'CNP2xe_LmqPEKBCsAhj6ASgBMggnyMqth81h8Q.swiffy72.html',
126 'clip-paths-CICAgMDO7Ye9-gEQ2AUYWigBMgjZxDii6aoK9w.swiffy72.html',
127 'filters-CNLa0t2T47qJ_wEQoAEY2AQoATIIFaIdc7VMBr4.swiffy72.html',
128 'shapes-CICAgMDO7cfIzwEQ1AMYPCgBMghqY8tqyRCArQ.swiffy72.html',
129 'CICAgIDQ2Pb-MxCsAhj6ASgBMgi5DLoSO0gPbQ.swiffy72.html',
130 'CICAgKCN39CopQEQoAEY2AQoATIID59gK5hjjIg.swiffy72.html',
131 'CICAgKCNj4HgyAEQeBjYBCgBMgjQpPkOjyWNdw.1.swiffy72.html',
132 'clip-paths-CILZhLqO_-27bxB4GNgEKAEyCC46kMLBXnMT.swiffy72.html',
133 'CICAgMDOrcnRGRB4GNgEKAEyCP_ZBSfwUFsj.swiffy72.html',
135 for page_name
in swiffy_pages
:
136 url
= base_url
+ '/' + page_name
137 self
.AddStory(SwiffyPage(url
, self
))
140 class ToughWebglAdCasesPageSet(story
.StorySet
):
141 """Pages for measuring rendering performance with WebGL ad content."""
144 super(ToughWebglAdCasesPageSet
, self
).__init
__(
145 archive_data_file
='data/tough_ad_cases.json',
146 cloud_storage_bucket
=story
.INTERNAL_BUCKET
)
148 base_url
= 'http://localhost:8000'
150 # See go/swiffy-chrome-samples for how to add new pages here or how to
151 # update the existing ones.
153 'CICAgICQ15a9NxDIARjIASgBMghBC1XuTk8ezw.swf.webglbeta.html',
154 'shapes-CK7ptO3F8bi2KxDQAhiYAigBMgij6QBQtD2gyA.swf.webglbeta.html',
155 'CNP2xe_LmqPEKBCsAhj6ASgBMggnyMqth81h8Q.swf.webglbeta.html',
156 'clip-paths-CICAgMDO7Ye9-gEQ2AUYWigBMgjZxDii6aoK9w.swf.webglbeta.html',
157 'filters-CNLa0t2T47qJ_wEQoAEY2AQoATIIFaIdc7VMBr4.swf.webglbeta.html',
158 'shapes-CICAgMDO7cfIzwEQ1AMYPCgBMghqY8tqyRCArQ.swf.webglbeta.html',
159 'CICAgIDQ2Pb-MxCsAhj6ASgBMgi5DLoSO0gPbQ.swf.webglbeta.html',
160 'CICAgKCN39CopQEQoAEY2AQoATIID59gK5hjjIg.swf.webglbeta.html',
161 'CICAgKCNj4HgyAEQeBjYBCgBMgjQpPkOjyWNdw.1.swf.webglbeta.html',
162 'clip-paths-CILZhLqO_-27bxB4GNgEKAEyCC46kMLBXnMT.swf.webglbeta.html',
163 'CICAgMDOrcnRGRB4GNgEKAEyCP_ZBSfwUFsj.swf.webglbeta.html',
165 for page_name
in swiffy_pages
:
166 url
= base_url
+ '/' + page_name
167 self
.AddStory(SwiffyPage(url
, self
))
170 class ScrollingToughAdCasesPageSet(story
.StorySet
):
171 """Pages for measuring scrolling performance with advertising content."""
173 def __init__(self
, bidirectional_scroll
=False):
174 super(ScrollingToughAdCasesPageSet
, self
).__init
__(
175 archive_data_file
='data/tough_ad_cases.json',
176 cloud_storage_bucket
=story
.INTERNAL_BUCKET
)
178 self
.AddStory(ScrollingPage('file://tough_ad_cases/'
179 'swiffy_collection.html', self
, make_javascript_deterministic
=False,
180 y_scroll_distance_multiplier
=0.25,
181 bidirectional_scroll
=bidirectional_scroll
))
182 self
.AddStory(ScrollingPage('file://tough_ad_cases/'
183 'swiffy_webgl_collection.html',
184 self
, make_javascript_deterministic
=False,
185 bidirectional_scroll
=bidirectional_scroll
))
186 self
.AddStory(ScrollingPage('http://www.latimes.com', self
,
187 bidirectional_scroll
=bidirectional_scroll
,
188 wait_for_interactive_or_better
=True))
189 self
.AddStory(ScrollingForbesPage('http://www.forbes.com/sites/parmyolson/'
190 '2015/07/29/jana-mobile-data-facebook-internet-org/', self
,
191 bidirectional_scroll
=bidirectional_scroll
))
192 self
.AddStory(ScrollingPage('http://androidcentral.com', self
,
193 bidirectional_scroll
=bidirectional_scroll
,
194 wait_for_interactive_or_better
=True))
195 self
.AddStory(ScrollingPage('http://mashable.com', self
,
196 y_scroll_distance_multiplier
=0.25,
197 bidirectional_scroll
=bidirectional_scroll
))
198 self
.AddStory(ScrollingPage('http://www.androidauthority.com/'
199 'reduce-data-use-turn-on-data-compression-in-chrome-630064/', self
,
200 bidirectional_scroll
=bidirectional_scroll
))
201 self
.AddStory(ScrollingPage('http://www.cnn.com/2015/01/09/politics/'
202 'nebraska-keystone-pipeline/index.html', self
,
203 bidirectional_scroll
=bidirectional_scroll
))
204 # Disabled: crbug.com/520509
205 #self.AddStory(ScrollingPage('http://time.com/3977891/'
206 # 'donald-trump-debate-republican/', self,
207 # bidirectional_scroll=bidirectional_scroll))
208 self
.AddStory(ScrollingPage('http://www.theguardian.com/uk', self
,
209 bidirectional_scroll
=bidirectional_scroll
))
210 self
.AddStory(ScrollingPage('http://m.tmz.com', self
,
211 y_scroll_distance_multiplier
=0.25,
212 bidirectional_scroll
=bidirectional_scroll
))
213 self
.AddStory(ScrollingPage('http://androidpolice.com', self
,
214 bidirectional_scroll
=bidirectional_scroll
,
215 wait_for_interactive_or_better
=True))
218 class BidirectionallyScrollingToughAdCasesPageSet(ScrollingToughAdCasesPageSet
):
219 """Same as ScrollingAdCasesPageSet except we scroll in two directions."""
222 super(BidirectionallyScrollingToughAdCasesPageSet
, self
).__init
__(
223 bidirectional_scroll
=True)