• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4from telemetry.page import page as page_module
5from telemetry.page import page_set as page_set_module
6
7
8def _GetCurrentLocation(action_runner):
9  return action_runner.EvaluateJavaScript('document.location.href')
10
11
12def _WaitForLocationChange(action_runner, old_href):
13  action_runner.WaitForJavaScriptCondition(
14      'document.location.href != "%s"' % old_href)
15
16
17class Top25Page(page_module.Page):
18
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'
24
25  def RunSmoothness(self, action_runner):
26    interaction = action_runner.BeginGestureInteraction(
27        'ScrollAction', is_smooth=True)
28    action_runner.ScrollPage()
29    interaction.End()
30
31  def RunRepaint(self, action_runner):
32    action_runner.RepaintContinuously(seconds=5)
33
34
35class GoogleWebSearchPage(Top25Page):
36
37  """ Why: top google property; a google tab is often open """
38
39  def __init__(self, page_set):
40    super(GoogleWebSearchPage, self).__init__(
41      url='https://www.google.com/#hl=en&q=barack+obama',
42      page_set=page_set)
43
44  def RunNavigateSteps(self, action_runner):
45    action_runner.NavigateToPage(self)
46    action_runner.WaitForElement(text='Next')
47
48  def RunStressMemory(self, action_runner):
49    interaction = action_runner.BeginGestureInteraction(
50        'ScrollAction', is_smooth=True)
51    action_runner.ScrollPage()
52    interaction.End()
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()
60    interaction.End()
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()
68    interaction.End()
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()
76    interaction.End()
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()
84    interaction.End()
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()
92    interaction.End()
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()
100    interaction.End()
101    old_href = _GetCurrentLocation(action_runner)
102    action_runner.ClickElement(text='Images')
103    _WaitForLocationChange(action_runner, old_href)
104    action_runner.WaitForElement(text='Images')
105
106
107class GmailPage(Top25Page):
108
109  """ Why: productivity, top google properties """
110
111  def __init__(self, page_set):
112    super(GmailPage, self).__init__(
113      url='https://mail.google.com/mail/',
114      page_set=page_set)
115
116    self.credentials = 'google'
117
118  def RunNavigateSteps(self, action_runner):
119    action_runner.NavigateToPage(self)
120    action_runner.WaitForJavaScriptCondition(
121        'window.gmonkey !== undefined &&'
122        'document.getElementById("gb") !== null')
123
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)
133
134  def RunSmoothness(self, action_runner):
135    action_runner.ExecuteJavaScript('''
136        gmonkey.load('2.0', function(api) {
137          window.__scrollableElementForTelemetry = api.getScrollableElement();
138        });''')
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')
145    interaction.End()
146
147
148class GoogleCalendarPage(Top25Page):
149
150  """ Why: productivity, top google properties """
151
152  def __init__(self, page_set):
153    super(GoogleCalendarPage, self).__init__(
154      url='https://www.google.com/calendar/',
155      page_set=page_set)
156
157    self.credentials = 'google'
158
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('''
164        (function() {
165          var elem = document.createElement('meta');
166          elem.name='viewport';
167          elem.content='initial-scale=1';
168          document.body.appendChild(elem);
169        })();''')
170    action_runner.Wait(1)
171
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"]')
197
198  def RunSmoothness(self, action_runner):
199    interaction = action_runner.BeginGestureInteraction(
200        'ScrollAction', is_smooth=True)
201    action_runner.ScrollElement(selector='#scrolltimedeventswk')
202    interaction.End()
203
204
205class GoogleImageSearchPage(Top25Page):
206
207  """ Why: tough image case; top google properties """
208
209  def __init__(self, page_set):
210    super(GoogleImageSearchPage, self).__init__(
211      url='https://www.google.com/search?q=cats&tbm=isch',
212      page_set=page_set)
213
214    self.credentials = 'google'
215
216
217class GoogleDocPage(Top25Page):
218
219  """ Why: productivity, top google properties; Sample doc in the link """
220
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',
225      page_set=page_set,
226      name='Docs  (1 open document tab)')
227
228    self.credentials = 'google'
229
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')
235
236  def RunSmoothness(self, action_runner):
237    interaction = action_runner.BeginGestureInteraction(
238        'ScrollAction', is_smooth=True)
239    action_runner.ScrollElement(selector='.kix-appview-editor')
240    interaction.End()
241
242
243class GooglePlusPage(Top25Page):
244
245  """ Why: social; top google property; Public profile; infinite scrolls """
246
247  def __init__(self, page_set):
248    super(GooglePlusPage, self).__init__(
249      url='https://plus.google.com/110031535020051778989/posts',
250      page_set=page_set)
251
252    self.credentials = 'google'
253
254  def RunNavigateSteps(self, action_runner):
255    action_runner.NavigateToPage(self)
256    action_runner.WaitForElement(text='Home')
257
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')
274
275  def RunSmoothness(self, action_runner):
276    interaction = action_runner.BeginGestureInteraction(
277        'ScrollAction', is_smooth=True)
278    action_runner.ScrollPage()
279    interaction.End()
280
281
282class YoutubePage(Top25Page):
283
284  """ Why: #3 (Alexa global) """
285
286  def __init__(self, page_set):
287    super(YoutubePage, self).__init__(
288      url='http://www.youtube.com',
289      page_set=page_set)
290
291    self.credentials = 'google'
292
293  def RunNavigateSteps(self, action_runner):
294    action_runner.NavigateToPage(self)
295    action_runner.Wait(2)
296
297
298class BlogspotPage(Top25Page):
299
300  """ Why: #11 (Alexa global), google property; some blogger layouts have
301  infinite scroll but more interesting """
302
303  def __init__(self, page_set):
304    super(BlogspotPage, self).__init__(
305      url='http://googlewebmastercentral.blogspot.com/',
306      page_set=page_set,
307      name='Blogger')
308
309  def RunNavigateSteps(self, action_runner):
310    action_runner.NavigateToPage(self)
311    action_runner.WaitForElement(text='accessibility')
312
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()
319    interaction.End()
320    action_runner.ClickElement(text='advanced')
321    action_runner.WaitForNavigate()
322    interaction = action_runner.BeginGestureInteraction(
323        'ScrollAction', is_smooth=True)
324    action_runner.ScrollPage()
325    interaction.End()
326    action_runner.ClickElement(text='beginner')
327    action_runner.WaitForNavigate()
328    interaction = action_runner.BeginGestureInteraction(
329        'ScrollAction', is_smooth=True)
330    action_runner.ScrollPage()
331    interaction.End()
332    action_runner.ClickElement(text='Home')
333    action_runner.WaitForNavigate()
334
335
336class WordpressPage(Top25Page):
337
338  """ Why: #18 (Alexa global), Picked an interesting post """
339
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/',
344      page_set=page_set,
345      name='Wordpress')
346
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/"]')
352
353  def RunStressMemory(self, action_runner):
354    interaction = action_runner.BeginGestureInteraction(
355        'ScrollAction', is_smooth=True)
356    action_runner.ScrollPage()
357    interaction.End()
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()
365    interaction.End()
366    action_runner.ClickElement(text='Features')
367    action_runner.WaitForNavigate()
368    interaction = action_runner.BeginGestureInteraction(
369        'ScrollAction', is_smooth=True)
370    action_runner.ScrollPage()
371    interaction.End()
372    action_runner.ClickElement(text='News')
373    action_runner.WaitForNavigate()
374    interaction = action_runner.BeginGestureInteraction(
375        'ScrollAction', is_smooth=True)
376    action_runner.ScrollPage()
377    interaction.End()
378
379
380class FacebookPage(Top25Page):
381
382  """ Why: top social,Public profile """
383
384  def __init__(self, page_set):
385    super(FacebookPage, self).__init__(
386      url='http://www.facebook.com/barackobama',
387      page_set=page_set,
388      name='Facebook')
389    self.credentials = 'facebook'
390
391  def RunNavigateSteps(self, action_runner):
392    action_runner.NavigateToPage(self)
393    action_runner.WaitForElement(text='About')
394
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()
408
409  def RunSmoothness(self, action_runner):
410    interaction = action_runner.BeginGestureInteraction(
411        'ScrollAction', is_smooth=True)
412    action_runner.ScrollPage()
413    interaction.End()
414
415
416class LinkedinPage(Top25Page):
417
418  """ Why: #12 (Alexa global),Public profile """
419
420  def __init__(self, page_set):
421    super(LinkedinPage, self).__init__(
422      url='http://www.linkedin.com/in/linustorvalds',
423      page_set=page_set,
424      name='LinkedIn')
425
426
427class WikipediaPage(Top25Page):
428
429  """ Why: #6 (Alexa) most visited worldwide,Picked an interesting page """
430
431  def __init__(self, page_set):
432    super(WikipediaPage, self).__init__(
433      url='http://en.wikipedia.org/wiki/Wikipedia',
434      page_set=page_set,
435      name='Wikipedia (1 tab)')
436
437
438class TwitterPage(Top25Page):
439
440  """ Why: #8 (Alexa global),Picked an interesting page """
441
442  def __init__(self, page_set):
443    super(TwitterPage, self).__init__(
444      url='https://twitter.com/katyperry',
445      page_set=page_set,
446      name='Twitter')
447
448  def RunNavigateSteps(self, action_runner):
449    action_runner.NavigateToPage(self)
450    action_runner.Wait(2)
451
452  def RunSmoothness(self, action_runner):
453    interaction = action_runner.BeginGestureInteraction(
454        'ScrollAction', is_smooth=True)
455    action_runner.ScrollPage()
456    interaction.End()
457
458
459class PinterestPage(Top25Page):
460
461  """ Why: #37 (Alexa global) """
462
463  def __init__(self, page_set):
464    super(PinterestPage, self).__init__(
465      url='http://pinterest.com',
466      page_set=page_set,
467      name='Pinterest')
468
469  def RunSmoothness(self, action_runner):
470    interaction = action_runner.BeginGestureInteraction(
471        'ScrollAction', is_smooth=True)
472    action_runner.ScrollPage()
473    interaction.End()
474
475
476class ESPNPage(Top25Page):
477
478  """ Why: #1 sports """
479
480  def __init__(self, page_set):
481    super(ESPNPage, self).__init__(
482      url='http://espn.go.com',
483      page_set=page_set,
484      name='ESPN')
485
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)
490    interaction.End()
491
492
493class WeatherDotComPage(Top25Page):
494
495  """ Why: #7 (Alexa news); #27 total time spent,Picked interesting page """
496
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',
501      page_set=page_set,
502      name='Weather.com')
503
504
505class YahooGamesPage(Top25Page):
506
507  """ Why: #1 games according to Alexa (with actual games in it) """
508
509  def __init__(self, page_set):
510    super(YahooGamesPage, self).__init__(
511      url='http://games.yahoo.com',
512      page_set=page_set)
513
514  def RunNavigateSteps(self, action_runner):
515    action_runner.NavigateToPage(self)
516    action_runner.Wait(2)
517
518
519class Top25PageSet(page_set_module.PageSet):
520
521  """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """
522
523  def __init__(self):
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)
529
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))
547
548    other_urls = [
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
554      # spent
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/',
564      # Why: top tech blog
565      'http://techcrunch.com'
566    ]
567
568    for url in other_urls:
569      self.AddPage(Top25Page(url, self))
570