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 Top25Page(page_module
.Page
):
19 def __init__(self
, url
, page_set
, name
=''):
20 super(Top25Page
, self
).__init
__(url
=url
, page_set
=page_set
, name
=name
)
21 self
.credentials_path
= 'data/credentials.json'
22 self
.user_agent_type
= 'desktop'
23 self
.archive_data_file
= 'data/top_25.json'
25 def RunSmoothness(self
, action_runner
):
26 interaction
= action_runner
.BeginGestureInteraction(
27 'ScrollAction', is_smooth
=True)
28 action_runner
.ScrollPage()
31 def RunRepaint(self
, action_runner
):
32 action_runner
.RepaintContinuously(seconds
=5)
35 class GoogleWebSearchPage(Top25Page
):
37 """ Why: top google property; a google tab is often open """
39 def __init__(self
, page_set
):
40 super(GoogleWebSearchPage
, self
).__init
__(
41 url
='https://www.google.com/#hl=en&q=barack+obama',
44 def RunNavigateSteps(self
, action_runner
):
45 action_runner
.NavigateToPage(self
)
46 action_runner
.WaitForElement(text
='Next')
48 def RunStressMemory(self
, action_runner
):
49 interaction
= action_runner
.BeginGestureInteraction(
50 'ScrollAction', is_smooth
=True)
51 action_runner
.ScrollPage()
53 old_href
= _GetCurrentLocation(action_runner
)
54 action_runner
.ClickElement(text
='Next')
55 _WaitForLocationChange(action_runner
, old_href
)
56 action_runner
.WaitForElement(text
='Next')
57 interaction
= action_runner
.BeginGestureInteraction(
58 'ScrollAction', is_smooth
=True)
59 action_runner
.ScrollPage()
61 old_href
= _GetCurrentLocation(action_runner
)
62 action_runner
.ClickElement(text
='Next')
63 _WaitForLocationChange(action_runner
, old_href
)
64 action_runner
.WaitForElement(text
='Next')
65 interaction
= action_runner
.BeginGestureInteraction(
66 'ScrollAction', is_smooth
=True)
67 action_runner
.ScrollPage()
69 old_href
= _GetCurrentLocation(action_runner
)
70 action_runner
.ClickElement(text
='Next')
71 _WaitForLocationChange(action_runner
, old_href
)
72 action_runner
.WaitForElement(text
='Previous')
73 interaction
= action_runner
.BeginGestureInteraction(
74 'ScrollAction', is_smooth
=True)
75 action_runner
.ScrollPage()
77 old_href
= _GetCurrentLocation(action_runner
)
78 action_runner
.ClickElement(text
='Previous')
79 _WaitForLocationChange(action_runner
, old_href
)
80 action_runner
.WaitForElement(text
='Previous')
81 interaction
= action_runner
.BeginGestureInteraction(
82 'ScrollAction', is_smooth
=True)
83 action_runner
.ScrollPage()
85 old_href
= _GetCurrentLocation(action_runner
)
86 action_runner
.ClickElement(text
='Previous')
87 _WaitForLocationChange(action_runner
, old_href
)
88 action_runner
.WaitForElement(text
='Previous')
89 interaction
= action_runner
.BeginGestureInteraction(
90 'ScrollAction', is_smooth
=True)
91 action_runner
.ScrollPage()
93 old_href
= _GetCurrentLocation(action_runner
)
94 action_runner
.ClickElement(text
='Previous')
95 _WaitForLocationChange(action_runner
, old_href
)
96 action_runner
.WaitForElement(text
='Images')
97 interaction
= action_runner
.BeginGestureInteraction(
98 'ScrollAction', is_smooth
=True)
99 action_runner
.ScrollPage()
101 old_href
= _GetCurrentLocation(action_runner
)
102 action_runner
.ClickElement(text
='Images')
103 _WaitForLocationChange(action_runner
, old_href
)
104 action_runner
.WaitForElement(text
='Images')
107 class GmailPage(Top25Page
):
109 """ Why: productivity, top google properties """
111 def __init__(self
, page_set
):
112 super(GmailPage
, self
).__init
__(
113 url
='https://mail.google.com/mail/',
116 self
.credentials
= 'google'
118 def RunNavigateSteps(self
, action_runner
):
119 action_runner
.NavigateToPage(self
)
120 action_runner
.WaitForJavaScriptCondition(
121 'window.gmonkey !== undefined &&'
122 'document.getElementById("gb") !== null')
124 def RunStressMemory(self
, action_runner
):
125 old_href
= _GetCurrentLocation(action_runner
)
126 action_runner
.ClickElement(
127 'a[href="https://mail.google.com/mail/u/0/?shva=1#starred"]')
128 _WaitForLocationChange(action_runner
, old_href
)
129 old_href
= _GetCurrentLocation(action_runner
)
130 action_runner
.ClickElement(
131 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]')
132 _WaitForLocationChange(action_runner
, old_href
)
134 def RunSmoothness(self
, action_runner
):
135 action_runner
.ExecuteJavaScript('''
136 gmonkey.load('2.0', function(api) {
137 window.__scrollableElementForTelemetry = api.getScrollableElement();
139 action_runner
.WaitForJavaScriptCondition(
140 'window.__scrollableElementForTelemetry != null')
141 interaction
= action_runner
.BeginGestureInteraction(
142 'ScrollAction', is_smooth
=True)
143 action_runner
.ScrollElement(
144 element_function
='window.__scrollableElementForTelemetry')
148 class GoogleCalendarPage(Top25Page
):
150 """ Why: productivity, top google properties """
152 def __init__(self
, page_set
):
153 super(GoogleCalendarPage
, self
).__init
__(
154 url
='https://www.google.com/calendar/',
157 self
.credentials
= 'google'
159 def RunNavigateSteps(self
, action_runner
):
160 action_runner
.NavigateToPage(self
)
161 action_runner
.Wait(2)
162 action_runner
.WaitForElement('div[class~="navForward"]')
163 action_runner
.ExecuteJavaScript('''
165 var elem = document.createElement('meta');
166 elem.name='viewport';
167 elem.content='initial-scale=1';
168 document.body.appendChild(elem);
170 action_runner
.Wait(1)
172 def RunStressMemory(self
, action_runner
):
173 action_runner
.ClickElement('div[class~="navForward"]')
174 action_runner
.Wait(2)
175 action_runner
.WaitForElement('div[class~="navForward"]')
176 action_runner
.ClickElement('div[class~="navForward"]')
177 action_runner
.Wait(2)
178 action_runner
.WaitForElement('div[class~="navForward"]')
179 action_runner
.ClickElement('div[class~="navForward"]')
180 action_runner
.Wait(2)
181 action_runner
.WaitForElement('div[class~="navForward"]')
182 action_runner
.ClickElement('div[class~="navForward"]')
183 action_runner
.Wait(2)
184 action_runner
.WaitForElement('div[class~="navBack"]')
185 action_runner
.ClickElement('div[class~="navBack"]')
186 action_runner
.Wait(2)
187 action_runner
.WaitForElement('div[class~="navBack"]')
188 action_runner
.ClickElement('div[class~="navBack"]')
189 action_runner
.Wait(2)
190 action_runner
.WaitForElement('div[class~="navBack"]')
191 action_runner
.ClickElement('div[class~="navBack"]')
192 action_runner
.Wait(2)
193 action_runner
.WaitForElement('div[class~="navBack"]')
194 action_runner
.ClickElement('div[class~="navBack"]')
195 action_runner
.Wait(2)
196 action_runner
.WaitForElement('div[class~="navBack"]')
198 def RunSmoothness(self
, action_runner
):
199 interaction
= action_runner
.BeginGestureInteraction(
200 'ScrollAction', is_smooth
=True)
201 action_runner
.ScrollElement(selector
='#scrolltimedeventswk')
205 class GoogleImageSearchPage(Top25Page
):
207 """ Why: tough image case; top google properties """
209 def __init__(self
, page_set
):
210 super(GoogleImageSearchPage
, self
).__init
__(
211 url
='https://www.google.com/search?q=cats&tbm=isch',
214 self
.credentials
= 'google'
217 class GoogleDocPage(Top25Page
):
219 """ Why: productivity, top google properties; Sample doc in the link """
221 def __init__(self
, page_set
):
222 super(GoogleDocPage
, self
).__init
__(
223 # pylint: disable=C0301
224 url
='https://docs.google.com/document/d/1X-IKNjtEnx-WW5JIKRLsyhz5sbsat3mfTpAPUSX3_s4/view',
226 name
='Docs (1 open document tab)')
228 self
.credentials
= 'google'
230 def RunNavigateSteps(self
, action_runner
):
231 action_runner
.NavigateToPage(self
)
232 action_runner
.Wait(2)
233 action_runner
.WaitForJavaScriptCondition(
234 'document.getElementsByClassName("kix-appview-editor").length')
236 def RunSmoothness(self
, action_runner
):
237 interaction
= action_runner
.BeginGestureInteraction(
238 'ScrollAction', is_smooth
=True)
239 action_runner
.ScrollElement(selector
='.kix-appview-editor')
243 class GooglePlusPage(Top25Page
):
245 """ Why: social; top google property; Public profile; infinite scrolls """
247 def __init__(self
, page_set
):
248 super(GooglePlusPage
, self
).__init
__(
249 url
='https://plus.google.com/110031535020051778989/posts',
252 self
.credentials
= 'google'
254 def RunNavigateSteps(self
, action_runner
):
255 action_runner
.NavigateToPage(self
)
256 action_runner
.WaitForElement(text
='Home')
258 def RunStressMemory(self
, action_runner
):
259 action_runner
.ClickElement(text
='Home')
260 action_runner
.Wait(2)
261 action_runner
.WaitForElement(text
='Profile')
262 action_runner
.ClickElement(text
='Profile')
263 action_runner
.Wait(2)
264 action_runner
.WaitForElement(text
='Explore')
265 action_runner
.ClickElement(text
='Explore')
266 action_runner
.Wait(2)
267 action_runner
.WaitForElement(text
='Events')
268 action_runner
.ClickElement(text
='Events')
269 action_runner
.Wait(2)
270 action_runner
.WaitForElement(text
='Communities')
271 action_runner
.ClickElement(text
='Communities')
272 action_runner
.Wait(2)
273 action_runner
.WaitForElement(text
='Home')
275 def RunSmoothness(self
, action_runner
):
276 interaction
= action_runner
.BeginGestureInteraction(
277 'ScrollAction', is_smooth
=True)
278 action_runner
.ScrollPage()
282 class YoutubePage(Top25Page
):
284 """ Why: #3 (Alexa global) """
286 def __init__(self
, page_set
):
287 super(YoutubePage
, self
).__init
__(
288 url
='http://www.youtube.com',
291 self
.credentials
= 'google'
293 def RunNavigateSteps(self
, action_runner
):
294 action_runner
.NavigateToPage(self
)
295 action_runner
.Wait(2)
298 class BlogspotPage(Top25Page
):
300 """ Why: #11 (Alexa global), google property; some blogger layouts have
301 infinite scroll but more interesting """
303 def __init__(self
, page_set
):
304 super(BlogspotPage
, self
).__init
__(
305 url
='http://googlewebmastercentral.blogspot.com/',
309 def RunNavigateSteps(self
, action_runner
):
310 action_runner
.NavigateToPage(self
)
311 action_runner
.WaitForElement(text
='accessibility')
313 def RunStressMemory(self
, action_runner
):
314 action_runner
.ClickElement(text
='accessibility')
315 action_runner
.WaitForNavigate()
316 interaction
= action_runner
.BeginGestureInteraction(
317 'ScrollAction', is_smooth
=True)
318 action_runner
.ScrollPage()
320 action_runner
.ClickElement(text
='advanced')
321 action_runner
.WaitForNavigate()
322 interaction
= action_runner
.BeginGestureInteraction(
323 'ScrollAction', is_smooth
=True)
324 action_runner
.ScrollPage()
326 action_runner
.ClickElement(text
='beginner')
327 action_runner
.WaitForNavigate()
328 interaction
= action_runner
.BeginGestureInteraction(
329 'ScrollAction', is_smooth
=True)
330 action_runner
.ScrollPage()
332 action_runner
.ClickElement(text
='Home')
333 action_runner
.WaitForNavigate()
336 class WordpressPage(Top25Page
):
338 """ Why: #18 (Alexa global), Picked an interesting post """
340 def __init__(self
, page_set
):
341 super(WordpressPage
, self
).__init
__(
342 # pylint: disable=C0301
343 url
='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
347 def RunNavigateSteps(self
, action_runner
):
348 action_runner
.NavigateToPage(self
)
349 action_runner
.WaitForElement(
350 # pylint: disable=C0301
351 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
353 def RunStressMemory(self
, action_runner
):
354 interaction
= action_runner
.BeginGestureInteraction(
355 'ScrollAction', is_smooth
=True)
356 action_runner
.ScrollPage()
358 action_runner
.ClickElement(
359 # pylint: disable=C0301
360 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
361 action_runner
.WaitForNavigate()
362 interaction
= action_runner
.BeginGestureInteraction(
363 'ScrollAction', is_smooth
=True)
364 action_runner
.ScrollPage()
366 action_runner
.ClickElement(text
='Features')
367 action_runner
.WaitForNavigate()
368 interaction
= action_runner
.BeginGestureInteraction(
369 'ScrollAction', is_smooth
=True)
370 action_runner
.ScrollPage()
372 action_runner
.ClickElement(text
='News')
373 action_runner
.WaitForNavigate()
374 interaction
= action_runner
.BeginGestureInteraction(
375 'ScrollAction', is_smooth
=True)
376 action_runner
.ScrollPage()
380 class FacebookPage(Top25Page
):
382 """ Why: top social,Public profile """
384 def __init__(self
, page_set
):
385 super(FacebookPage
, self
).__init
__(
386 url
='http://www.facebook.com/barackobama',
389 self
.credentials
= 'facebook'
391 def RunNavigateSteps(self
, action_runner
):
392 action_runner
.NavigateToPage(self
)
393 action_runner
.WaitForElement(text
='About')
395 def RunStressMemory(self
, action_runner
):
396 action_runner
.ClickElement(text
='About')
397 action_runner
.WaitForNavigate()
398 action_runner
.ClickElement(text
='The Audacity of Hope')
399 action_runner
.WaitForNavigate()
400 action_runner
.ClickElement(text
='Back to Barack Obama\'s Timeline')
401 action_runner
.WaitForNavigate()
402 action_runner
.ClickElement(text
='About')
403 action_runner
.WaitForNavigate()
404 action_runner
.ClickElement(text
='Elected to U.S. Senate')
405 action_runner
.WaitForNavigate()
406 action_runner
.ClickElement(text
='Home')
407 action_runner
.WaitForNavigate()
409 def RunSmoothness(self
, action_runner
):
410 interaction
= action_runner
.BeginGestureInteraction(
411 'ScrollAction', is_smooth
=True)
412 action_runner
.ScrollPage()
416 class LinkedinPage(Top25Page
):
418 """ Why: #12 (Alexa global),Public profile """
420 def __init__(self
, page_set
):
421 super(LinkedinPage
, self
).__init
__(
422 url
='http://www.linkedin.com/in/linustorvalds',
427 class WikipediaPage(Top25Page
):
429 """ Why: #6 (Alexa) most visited worldwide,Picked an interesting page """
431 def __init__(self
, page_set
):
432 super(WikipediaPage
, self
).__init
__(
433 url
='http://en.wikipedia.org/wiki/Wikipedia',
435 name
='Wikipedia (1 tab)')
438 class TwitterPage(Top25Page
):
440 """ Why: #8 (Alexa global),Picked an interesting page """
442 def __init__(self
, page_set
):
443 super(TwitterPage
, self
).__init
__(
444 url
='https://twitter.com/katyperry',
448 def RunNavigateSteps(self
, action_runner
):
449 action_runner
.NavigateToPage(self
)
450 action_runner
.Wait(2)
452 def RunSmoothness(self
, action_runner
):
453 interaction
= action_runner
.BeginGestureInteraction(
454 'ScrollAction', is_smooth
=True)
455 action_runner
.ScrollPage()
459 class PinterestPage(Top25Page
):
461 """ Why: #37 (Alexa global) """
463 def __init__(self
, page_set
):
464 super(PinterestPage
, self
).__init
__(
465 url
='http://pinterest.com',
469 def RunSmoothness(self
, action_runner
):
470 interaction
= action_runner
.BeginGestureInteraction(
471 'ScrollAction', is_smooth
=True)
472 action_runner
.ScrollPage()
476 class ESPNPage(Top25Page
):
478 """ Why: #1 sports """
480 def __init__(self
, page_set
):
481 super(ESPNPage
, self
).__init
__(
482 url
='http://espn.go.com',
486 def RunSmoothness(self
, action_runner
):
487 interaction
= action_runner
.BeginGestureInteraction(
488 'ScrollAction', is_smooth
=True)
489 action_runner
.ScrollPage(left_start_ratio
=0.1)
493 class WeatherDotComPage(Top25Page
):
495 """ Why: #7 (Alexa news); #27 total time spent,Picked interesting page """
497 def __init__(self
, page_set
):
498 super(WeatherDotComPage
, self
).__init
__(
499 # pylint: disable=C0301
500 url
='http://www.weather.com/weather/right-now/Mountain+View+CA+94043',
505 class YahooGamesPage(Top25Page
):
507 """ Why: #1 games according to Alexa (with actual games in it) """
509 def __init__(self
, page_set
):
510 super(YahooGamesPage
, self
).__init
__(
511 url
='http://games.yahoo.com',
514 def RunNavigateSteps(self
, action_runner
):
515 action_runner
.NavigateToPage(self
)
516 action_runner
.Wait(2)
519 class Top25PageSet(page_set_module
.PageSet
):
521 """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """
524 super(Top25PageSet
, self
).__init
__(
525 credentials_path
='data/credentials.json',
526 user_agent_type
='desktop',
527 archive_data_file
='data/top_25.json',
528 bucket
=page_set_module
.PARTNER_BUCKET
)
530 self
.AddPage(GoogleWebSearchPage(self
))
531 self
.AddPage(GmailPage(self
))
532 self
.AddPage(GoogleCalendarPage(self
))
533 self
.AddPage(GoogleImageSearchPage(self
))
534 self
.AddPage(GoogleDocPage(self
))
535 self
.AddPage(GooglePlusPage(self
))
536 self
.AddPage(YoutubePage(self
))
537 self
.AddPage(BlogspotPage(self
))
538 self
.AddPage(WordpressPage(self
))
539 self
.AddPage(FacebookPage(self
))
540 self
.AddPage(LinkedinPage(self
))
541 self
.AddPage(WikipediaPage(self
))
542 self
.AddPage(TwitterPage(self
))
543 self
.AddPage(PinterestPage(self
))
544 self
.AddPage(ESPNPage(self
))
545 self
.AddPage(WeatherDotComPage(self
))
546 self
.AddPage(YahooGamesPage(self
))
549 # Why: #1 news worldwide (Alexa global)
550 'http://news.yahoo.com',
551 # Why: #2 news worldwide
552 'http://www.cnn.com',
553 # Why: #1 world commerce website by visits; #3 commerce in the US by time
555 'http://www.amazon.com',
556 # Why: #1 commerce website by time spent by users in US
557 'http://www.ebay.com',
558 # Why: #1 Alexa recreation
559 'http://booking.com',
560 # Why: #1 Alexa reference
561 'http://answers.yahoo.com',
562 # Why: #1 Alexa sports
563 'http://sports.yahoo.com/',
565 'http://techcrunch.com'
568 for url
in other_urls
:
569 self
.AddPage(Top25Page(url
, self
))