[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / page_sets / top_7_stress.py
blob5547358b819ed5eac382012adf9dfc604a4dde1a
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
3 # found in the LICENSE file.
4 from telemetry.page import page as page_module
5 from telemetry.page import page_set as page_set_module
8 def _GetCurrentLocation(action_runner):
9 return action_runner.EvaluateJavaScript('document.location.href')
12 def _WaitForLocationChange(action_runner, old_href):
13 action_runner.WaitForJavaScriptCondition(
14 'document.location.href != "%s"' % old_href)
17 class Top7StressPage(page_module.Page):
19 def __init__(self, url, page_set, name=''):
20 super(Top7StressPage, self).__init__(
21 url=url, page_set=page_set, name=name,
22 credentials_path = 'data/credentials.json')
23 self.user_agent_type = 'desktop'
24 self.archive_data_file = 'data/top_7_stress.json'
26 def RunPageInteractions(self, action_runner):
27 raise NotImplementedError()
30 class GoogleWebSearchPage(Top7StressPage):
32 """ Why: top google property; a google tab is often open """
34 def __init__(self, page_set):
35 super(GoogleWebSearchPage, self).__init__(
36 url='https://www.google.com/#hl=en&q=barack+obama',
37 page_set=page_set)
39 def RunNavigateSteps(self, action_runner):
40 super(GoogleWebSearchPage, self).RunNavigateSteps(action_runner)
41 action_runner.WaitForElement(text='Next')
43 def RunPageInteractions(self, action_runner):
44 interaction = action_runner.BeginGestureInteraction(
45 'ScrollAction')
46 action_runner.ScrollPage()
47 interaction.End()
48 old_href = _GetCurrentLocation(action_runner)
49 action_runner.ClickElement(text='Next')
50 _WaitForLocationChange(action_runner, old_href)
51 action_runner.WaitForElement(text='Next')
52 interaction = action_runner.BeginGestureInteraction(
53 'ScrollAction')
54 action_runner.ScrollPage()
55 interaction.End()
56 old_href = _GetCurrentLocation(action_runner)
57 action_runner.ClickElement(text='Next')
58 _WaitForLocationChange(action_runner, old_href)
59 action_runner.WaitForElement(text='Next')
60 interaction = action_runner.BeginGestureInteraction(
61 'ScrollAction')
62 action_runner.ScrollPage()
63 interaction.End()
64 old_href = _GetCurrentLocation(action_runner)
65 action_runner.ClickElement(text='Next')
66 _WaitForLocationChange(action_runner, old_href)
67 action_runner.WaitForElement(text='Previous')
68 interaction = action_runner.BeginGestureInteraction(
69 'ScrollAction')
70 action_runner.ScrollPage()
71 interaction.End()
72 old_href = _GetCurrentLocation(action_runner)
73 action_runner.ClickElement(text='Previous')
74 _WaitForLocationChange(action_runner, old_href)
75 action_runner.WaitForElement(text='Previous')
76 interaction = action_runner.BeginGestureInteraction(
77 'ScrollAction')
78 action_runner.ScrollPage()
79 interaction.End()
80 old_href = _GetCurrentLocation(action_runner)
81 action_runner.ClickElement(text='Previous')
82 _WaitForLocationChange(action_runner, old_href)
83 action_runner.WaitForElement(text='Previous')
84 interaction = action_runner.BeginGestureInteraction(
85 'ScrollAction')
86 action_runner.ScrollPage()
87 interaction.End()
88 old_href = _GetCurrentLocation(action_runner)
89 action_runner.ClickElement(text='Previous')
90 _WaitForLocationChange(action_runner, old_href)
91 action_runner.WaitForElement(text='Images')
92 interaction = action_runner.BeginGestureInteraction(
93 'ScrollAction')
94 action_runner.ScrollPage()
95 interaction.End()
96 old_href = _GetCurrentLocation(action_runner)
97 action_runner.ClickElement(text='Images')
98 _WaitForLocationChange(action_runner, old_href)
99 action_runner.WaitForElement(text='Images')
102 class GmailPage(Top7StressPage):
104 """ Why: productivity, top google properties """
106 def __init__(self, page_set):
107 super(GmailPage, self).__init__(
108 url='https://mail.google.com/mail/',
109 page_set=page_set)
111 self.credentials = 'google'
113 def RunNavigateSteps(self, action_runner):
114 super(GmailPage, self).RunNavigateSteps(action_runner)
115 action_runner.WaitForJavaScriptCondition(
116 'window.gmonkey !== undefined &&'
117 'document.getElementById("gb") !== null')
119 def RunPageInteractions(self, action_runner):
120 old_href = _GetCurrentLocation(action_runner)
121 action_runner.ClickElement(
122 'a[href="https://mail.google.com/mail/u/0/?shva=1#starred"]')
123 _WaitForLocationChange(action_runner, old_href)
124 old_href = _GetCurrentLocation(action_runner)
125 action_runner.ClickElement(
126 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]')
127 _WaitForLocationChange(action_runner, old_href)
130 class GoogleCalendarPage(Top7StressPage):
132 """ Why: productivity, top google properties """
134 def __init__(self, page_set):
135 super(GoogleCalendarPage, self).__init__(
136 url='https://www.google.com/calendar/',
137 page_set=page_set)
139 self.credentials = 'google'
141 def RunNavigateSteps(self, action_runner):
142 super(GoogleCalendarPage, self).RunNavigateSteps(action_runner)
143 action_runner.Wait(2)
144 action_runner.WaitForElement('div[class~="navForward"]')
145 action_runner.ExecuteJavaScript('''
146 (function() {
147 var elem = document.createElement('meta');
148 elem.name='viewport';
149 elem.content='initial-scale=1';
150 document.body.appendChild(elem);
151 })();''')
152 action_runner.Wait(1)
154 def RunPageInteractions(self, action_runner):
155 action_runner.ClickElement('div[class~="navForward"]')
156 action_runner.Wait(2)
157 action_runner.WaitForElement('div[class~="navForward"]')
158 action_runner.ClickElement('div[class~="navForward"]')
159 action_runner.Wait(2)
160 action_runner.WaitForElement('div[class~="navForward"]')
161 action_runner.ClickElement('div[class~="navForward"]')
162 action_runner.Wait(2)
163 action_runner.WaitForElement('div[class~="navForward"]')
164 action_runner.ClickElement('div[class~="navForward"]')
165 action_runner.Wait(2)
166 action_runner.WaitForElement('div[class~="navBack"]')
167 action_runner.ClickElement('div[class~="navBack"]')
168 action_runner.Wait(2)
169 action_runner.WaitForElement('div[class~="navBack"]')
170 action_runner.ClickElement('div[class~="navBack"]')
171 action_runner.Wait(2)
172 action_runner.WaitForElement('div[class~="navBack"]')
173 action_runner.ClickElement('div[class~="navBack"]')
174 action_runner.Wait(2)
175 action_runner.WaitForElement('div[class~="navBack"]')
176 action_runner.ClickElement('div[class~="navBack"]')
177 action_runner.Wait(2)
178 action_runner.WaitForElement('div[class~="navBack"]')
181 class GooglePlusPage(Top7StressPage):
183 """ Why: social; top google property; Public profile; infinite scrolls """
185 def __init__(self, page_set):
186 super(GooglePlusPage, self).__init__(
187 url='https://plus.google.com/110031535020051778989/posts',
188 page_set=page_set)
190 self.credentials = 'google'
192 def RunNavigateSteps(self, action_runner):
193 super(GooglePlusPage, self).RunNavigateSteps(action_runner)
194 action_runner.WaitForElement(text='Home')
196 def RunPageInteractions(self, action_runner):
197 action_runner.ClickElement(text='Home')
198 action_runner.Wait(2)
199 action_runner.WaitForElement(text='Profile')
200 action_runner.ClickElement(text='Profile')
201 action_runner.Wait(2)
202 action_runner.WaitForElement(text='Explore')
203 action_runner.ClickElement(text='Explore')
204 action_runner.Wait(2)
205 action_runner.WaitForElement(text='Events')
206 action_runner.ClickElement(text='Events')
207 action_runner.Wait(2)
208 action_runner.WaitForElement(text='Communities')
209 action_runner.ClickElement(text='Communities')
210 action_runner.Wait(2)
211 action_runner.WaitForElement(text='Home')
214 class BlogspotPage(Top7StressPage):
216 """ Why: #11 (Alexa global), google property; some blogger layouts have
217 infinite scroll but more interesting """
219 def __init__(self, page_set):
220 super(BlogspotPage, self).__init__(
221 url='http://googlewebmastercentral.blogspot.com/',
222 page_set=page_set,
223 name='Blogger')
225 def RunNavigateSteps(self, action_runner):
226 super(BlogspotPage, self).RunNavigateSteps(action_runner)
227 action_runner.WaitForElement(text='accessibility')
229 def RunPageInteractions(self, action_runner):
230 action_runner.ClickElement(text='accessibility')
231 action_runner.WaitForNavigate()
232 interaction = action_runner.BeginGestureInteraction(
233 'ScrollAction')
234 action_runner.ScrollPage()
235 interaction.End()
236 # Insert 300ms wait to simulate user finger movement,
237 # and ensure scheduling of idle tasks.
238 action_runner.Wait(0.3)
239 action_runner.ClickElement(text='advanced')
240 action_runner.WaitForNavigate()
241 interaction = action_runner.BeginGestureInteraction(
242 'ScrollAction')
243 action_runner.ScrollPage()
244 interaction.End()
245 action_runner.Wait(0.3)
246 action_runner.ClickElement(text='beginner')
247 action_runner.WaitForNavigate()
248 interaction = action_runner.BeginGestureInteraction(
249 'ScrollAction')
250 action_runner.ScrollPage()
251 interaction.End()
252 action_runner.Wait(0.3)
253 action_runner.ClickElement(text='Home')
254 action_runner.WaitForNavigate()
257 class WordpressPage(Top7StressPage):
259 """ Why: #18 (Alexa global), Picked an interesting post """
261 def __init__(self, page_set):
262 super(WordpressPage, self).__init__(
263 # pylint: disable=C0301
264 url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
265 page_set=page_set,
266 name='Wordpress')
268 def RunNavigateSteps(self, action_runner):
269 super(WordpressPage, self).RunNavigateSteps(action_runner)
270 action_runner.WaitForElement(
271 # pylint: disable=C0301
272 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
274 def RunPageInteractions(self, action_runner):
275 interaction = action_runner.BeginGestureInteraction(
276 'ScrollAction')
277 action_runner.ScrollPage()
278 interaction.End()
279 # Insert 300ms wait to simulate user finger movement,
280 # and ensure scheduling of idle tasks.
281 action_runner.Wait(0.3)
282 action_runner.ClickElement(
283 # pylint: disable=C0301
284 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
285 action_runner.WaitForNavigate()
286 interaction = action_runner.BeginGestureInteraction(
287 'ScrollAction')
288 action_runner.ScrollPage()
289 interaction.End()
290 action_runner.Wait(0.3)
291 action_runner.ClickElement(text='Features')
292 action_runner.WaitForNavigate()
293 interaction = action_runner.BeginGestureInteraction(
294 'ScrollAction')
295 action_runner.ScrollPage()
296 interaction.End()
297 action_runner.Wait(0.3)
298 action_runner.ClickElement(text='News')
299 action_runner.WaitForNavigate()
300 interaction = action_runner.BeginGestureInteraction(
301 'ScrollAction')
302 action_runner.ScrollPage()
303 interaction.End()
306 class FacebookPage(Top7StressPage):
308 """ Why: top social,Public profile """
310 def __init__(self, page_set):
311 super(FacebookPage, self).__init__(
312 url='https://www.facebook.com/barackobama',
313 page_set=page_set,
314 name='Facebook')
315 self.credentials = 'facebook2'
317 def RunNavigateSteps(self, action_runner):
318 super(FacebookPage, self).RunNavigateSteps(action_runner)
319 action_runner.WaitForElement(text='About')
321 def RunPageInteractions(self, action_runner):
322 # Scroll and wait for the next page to be loaded.
323 interaction = action_runner.BeginGestureInteraction(
324 'ScrollAction')
325 action_runner.ScrollPage()
326 interaction.End()
327 action_runner.WaitForJavaScriptCondition(
328 'document.documentElement.scrollHeight - window.innerHeight - '
329 'window.pageYOffset > 0')
331 # Scroll and wait again.
332 interaction = action_runner.BeginGestureInteraction(
333 'ScrollAction')
334 action_runner.ScrollPage()
335 interaction.End()
336 action_runner.WaitForJavaScriptCondition(
337 'document.documentElement.scrollHeight - window.innerHeight - '
338 'window.pageYOffset > 0')
340 class Top7StressPageSet(page_set_module.PageSet):
342 """ Pages hand-picked for stress testing. """
344 def __init__(self):
345 super(Top7StressPageSet, self).__init__(
346 user_agent_type='desktop',
347 archive_data_file='data/top_7_stress.json',
348 bucket=page_set_module.PARTNER_BUCKET)
350 self.AddUserStory(GoogleWebSearchPage(self))
351 self.AddUserStory(GmailPage(self))
352 self.AddUserStory(GoogleCalendarPage(self))
353 self.AddUserStory(GooglePlusPage(self))
354 self.AddUserStory(BlogspotPage(self))
355 self.AddUserStory(WordpressPage(self))
356 self.AddUserStory(FacebookPage(self))