• 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.
4# pylint: disable=W0401,W0614
5from telemetry.page.actions.all_page_actions import *
6from telemetry.page import page as page_module
7from telemetry.page import page_set as page_set_module
8
9
10def _GetCurrentLocation(action_runner):
11  return action_runner.EvaluateJavaScript('document.location.href')
12
13
14def _WaitForLocationChange(action_runner, old_href):
15  action_runner.WaitForJavaScriptCondition(
16      'document.location.href != "%s"' % old_href)
17
18
19class Top25Page(page_module.Page):
20
21  def __init__(self, url, page_set, name=''):
22    super(Top25Page, self).__init__(url=url, page_set=page_set, name=name)
23    self.credentials_path = 'data/credentials.json'
24    self.user_agent_type = 'desktop'
25    self.archive_data_file = 'data/top_25.json'
26
27  def RunSmoothness(self, action_runner):
28    action_runner.RunAction(ScrollAction())
29
30  def RunRepaint(self, action_runner):
31    action_runner.RunAction(RepaintContinuouslyAction(
32      {
33        'seconds': 5
34      }))
35
36
37class GoogleWebSearchPage(Top25Page):
38
39  """ Why: top google property; a google tab is often open """
40
41  def __init__(self, page_set):
42    super(GoogleWebSearchPage, self).__init__(
43      url='https://www.google.com/#hl=en&q=barack+obama',
44      page_set=page_set)
45
46  def RunNavigateSteps(self, action_runner):
47    action_runner.NavigateToPage(self)
48    action_runner.WaitForElement(text='Next')
49
50  def RunStressMemory(self, action_runner):
51    action_runner.RunAction(ScrollAction())
52    old_href = _GetCurrentLocation(action_runner)
53    action_runner.ClickElement(text='Next')
54    _WaitForLocationChange(action_runner, old_href)
55    action_runner.WaitForElement(text='Next')
56    action_runner.RunAction(ScrollAction())
57    old_href = _GetCurrentLocation(action_runner)
58    action_runner.ClickElement(text='Next')
59    _WaitForLocationChange(action_runner, old_href)
60    action_runner.WaitForElement(text='Next')
61    action_runner.RunAction(ScrollAction())
62    old_href = _GetCurrentLocation(action_runner)
63    action_runner.ClickElement(text='Next')
64    _WaitForLocationChange(action_runner, old_href)
65    action_runner.WaitForElement(text='Previous')
66    action_runner.RunAction(ScrollAction())
67    old_href = _GetCurrentLocation(action_runner)
68    action_runner.ClickElement(text='Previous')
69    _WaitForLocationChange(action_runner, old_href)
70    action_runner.WaitForElement(text='Previous')
71    action_runner.RunAction(ScrollAction())
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    action_runner.RunAction(ScrollAction())
77    old_href = _GetCurrentLocation(action_runner)
78    action_runner.ClickElement(text='Previous')
79    _WaitForLocationChange(action_runner, old_href)
80    action_runner.WaitForElement(text='Images')
81    action_runner.RunAction(ScrollAction())
82    old_href = _GetCurrentLocation(action_runner)
83    action_runner.ClickElement(text='Images')
84    _WaitForLocationChange(action_runner, old_href)
85    action_runner.WaitForElement(text='Images')
86
87
88class GmailPage(Top25Page):
89
90  """ Why: productivity, top google properties """
91
92  def __init__(self, page_set):
93    super(GmailPage, self).__init__(
94      url='https://mail.google.com/mail/',
95      page_set=page_set)
96
97    self.credentials = 'google'
98
99  def RunNavigateSteps(self, action_runner):
100    action_runner.NavigateToPage(self)
101    action_runner.WaitForJavaScriptCondition(
102        'window.gmonkey !== undefined &&'
103        'document.getElementById("gb") !== null')
104
105  def RunStressMemory(self, action_runner):
106    old_href = _GetCurrentLocation(action_runner)
107    action_runner.ClickElement(
108        'a[href="https://mail.google.com/mail/u/0/?shva=1#starred"]')
109    _WaitForLocationChange(action_runner, old_href)
110    old_href = _GetCurrentLocation(action_runner)
111    action_runner.ClickElement(
112        'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]')
113    _WaitForLocationChange(action_runner, old_href)
114
115  def RunSmoothness(self, action_runner):
116    action_runner.RunAction(ScrollAction(
117      {
118        'scrollable_element_function': '''
119          function(callback) {
120            gmonkey.load('2.0', function(api) {
121              callback(api.getScrollableElement());
122            });
123          }'''
124      }))
125
126
127class GoogleCalendarPage(Top25Page):
128
129  """ Why: productivity, top google properties """
130
131  def __init__(self, page_set):
132    super(GoogleCalendarPage, self).__init__(
133      url='https://www.google.com/calendar/',
134      page_set=page_set)
135
136    self.credentials = 'google'
137
138  def RunNavigateSteps(self, action_runner):
139    action_runner.NavigateToPage(self)
140    action_runner.Wait(2)
141    action_runner.WaitForElement('div[class~="navForward"]')
142    action_runner.ExecuteJavaScript('''
143        (function() {
144          var elem = document.createElement('meta');
145          elem.name='viewport';
146          elem.content='initial-scale=1';
147          document.body.appendChild(elem);
148        })();''')
149    action_runner.Wait(1)
150
151  def RunStressMemory(self, action_runner):
152    action_runner.ClickElement('div[class~="navForward"]')
153    action_runner.Wait(2)
154    action_runner.WaitForElement('div[class~="navForward"]')
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~="navBack"]')
164    action_runner.ClickElement('div[class~="navBack"]')
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
177  def RunSmoothness(self, action_runner):
178    action_runner.RunAction(ScrollAction(
179      {
180        'scrollable_element_function': '''
181          function(callback) {
182            callback(document.getElementById('scrolltimedeventswk'));
183          }'''
184      }))
185
186
187class GoogleImageSearchPage(Top25Page):
188
189  """ Why: tough image case; top google properties """
190
191  def __init__(self, page_set):
192    super(GoogleImageSearchPage, self).__init__(
193      url='https://www.google.com/search?q=cats&tbm=isch',
194      page_set=page_set)
195
196    self.credentials = 'google'
197
198
199class GoogleDocPage(Top25Page):
200
201  """ Why: productivity, top google properties; Sample doc in the link """
202
203  def __init__(self, page_set):
204    super(GoogleDocPage, self).__init__(
205      # pylint: disable=C0301
206      url='https://docs.google.com/document/d/1X-IKNjtEnx-WW5JIKRLsyhz5sbsat3mfTpAPUSX3_s4/view',
207      page_set=page_set,
208      name='Docs  (1 open document tab)')
209
210    self.credentials = 'google'
211
212  def RunNavigateSteps(self, action_runner):
213    action_runner.NavigateToPage(self)
214    action_runner.Wait(2)
215    action_runner.WaitForJavaScriptCondition(
216        'document.getElementsByClassName("kix-appview-editor").length')
217
218  def RunSmoothness(self, action_runner):
219    action_runner.RunAction(ScrollAction(
220      {
221        'scrollable_element_function': '''
222          function(callback) {
223            callback(document.getElementsByClassName('kix-appview-editor')[0]);
224          }'''
225      }))
226
227
228class GooglePlusPage(Top25Page):
229
230  """ Why: social; top google property; Public profile; infinite scrolls """
231
232  def __init__(self, page_set):
233    super(GooglePlusPage, self).__init__(
234      url='https://plus.google.com/110031535020051778989/posts',
235      page_set=page_set)
236
237    self.credentials = 'google'
238
239  def RunNavigateSteps(self, action_runner):
240    action_runner.NavigateToPage(self)
241    action_runner.WaitForElement(text='Home')
242
243  def RunStressMemory(self, action_runner):
244    action_runner.ClickElement(text='Home')
245    action_runner.Wait(2)
246    action_runner.WaitForElement(text='Profile')
247    action_runner.ClickElement(text='Profile')
248    action_runner.Wait(2)
249    action_runner.WaitForElement(text='Explore')
250    action_runner.ClickElement(text='Explore')
251    action_runner.Wait(2)
252    action_runner.WaitForElement(text='Events')
253    action_runner.ClickElement(text='Events')
254    action_runner.Wait(2)
255    action_runner.WaitForElement(text='Communities')
256    action_runner.ClickElement(text='Communities')
257    action_runner.Wait(2)
258    action_runner.WaitForElement(text='Home')
259
260  def RunSmoothness(self, action_runner):
261    action_runner.RunAction(ScrollAction(
262      {
263        "scroll_is_infinite": True
264      }))
265
266
267class YoutubePage(Top25Page):
268
269  """ Why: #3 (Alexa global) """
270
271  def __init__(self, page_set):
272    super(YoutubePage, self).__init__(
273      url='http://www.youtube.com',
274      page_set=page_set)
275
276    self.credentials = 'google'
277
278  def RunNavigateSteps(self, action_runner):
279    action_runner.NavigateToPage(self)
280    action_runner.Wait(2)
281
282
283class BlogspotPage(Top25Page):
284
285  """ Why: #11 (Alexa global), google property; some blogger layouts have
286  infinite scroll but more interesting """
287
288  def __init__(self, page_set):
289    super(BlogspotPage, self).__init__(
290      url='http://googlewebmastercentral.blogspot.com/',
291      page_set=page_set,
292      name='Blogger')
293
294  def RunNavigateSteps(self, action_runner):
295    action_runner.NavigateToPage(self)
296    action_runner.WaitForElement(text='accessibility')
297
298  def RunStressMemory(self, action_runner):
299    action_runner.ClickElement(text='accessibility')
300    action_runner.WaitForNavigate()
301    action_runner.RunAction(ScrollAction())
302    action_runner.ClickElement(text='advanced')
303    action_runner.WaitForNavigate()
304    action_runner.RunAction(ScrollAction())
305    action_runner.ClickElement(text='beginner')
306    action_runner.WaitForNavigate()
307    action_runner.RunAction(ScrollAction())
308    action_runner.ClickElement(text='Home')
309    action_runner.WaitForNavigate()
310
311
312class WordpressPage(Top25Page):
313
314  """ Why: #18 (Alexa global), Picked an interesting post """
315
316  def __init__(self, page_set):
317    super(WordpressPage, self).__init__(
318      # pylint: disable=C0301
319      url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
320      page_set=page_set,
321      name='Wordpress')
322
323  def RunNavigateSteps(self, action_runner):
324    action_runner.NavigateToPage(self)
325    action_runner.WaitForElement(
326        # pylint: disable=C0301
327        'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
328
329  def RunStressMemory(self, action_runner):
330    action_runner.RunAction(ScrollAction())
331    action_runner.ClickElement(
332        # pylint: disable=C0301
333        'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
334    action_runner.WaitForNavigate()
335    action_runner.RunAction(ScrollAction())
336    action_runner.ClickElement(text='Features')
337    action_runner.WaitForNavigate()
338    action_runner.RunAction(ScrollAction())
339    action_runner.ClickElement(text='News')
340    action_runner.WaitForNavigate()
341    action_runner.RunAction(ScrollAction())
342
343
344class FacebookPage(Top25Page):
345
346  """ Why: top social,Public profile """
347
348  def __init__(self, page_set):
349    super(FacebookPage, self).__init__(
350      url='http://www.facebook.com/barackobama',
351      page_set=page_set,
352      name='Facebook')
353    self.credentials = 'facebook'
354
355  def RunNavigateSteps(self, action_runner):
356    action_runner.NavigateToPage(self)
357    action_runner.WaitForElement(text='About')
358
359  def RunStressMemory(self, action_runner):
360    action_runner.ClickElement(text='About')
361    action_runner.WaitForNavigate()
362    action_runner.ClickElement(text='The Audacity of Hope')
363    action_runner.WaitForNavigate()
364    action_runner.ClickElement(text='Back to Barack Obama\'s Timeline')
365    action_runner.WaitForNavigate()
366    action_runner.ClickElement(text='About')
367    action_runner.WaitForNavigate()
368    action_runner.ClickElement(text='Elected to U.S. Senate')
369    action_runner.WaitForNavigate()
370    action_runner.ClickElement(text='Home')
371    action_runner.WaitForNavigate()
372
373  def RunSmoothness(self, action_runner):
374    action_runner.RunAction(ScrollAction(
375      {
376        'scroll_is_infinite': True
377      }))
378
379
380class LinkedinPage(Top25Page):
381
382  """ Why: #12 (Alexa global),Public profile """
383
384  def __init__(self, page_set):
385    super(LinkedinPage, self).__init__(
386      url='http://www.linkedin.com/in/linustorvalds',
387      page_set=page_set,
388      name='LinkedIn')
389
390
391class WikipediaPage(Top25Page):
392
393  """ Why: #6 (Alexa) most visited worldwide,Picked an interesting page """
394
395  def __init__(self, page_set):
396    super(WikipediaPage, self).__init__(
397      url='http://en.wikipedia.org/wiki/Wikipedia',
398      page_set=page_set,
399      name='Wikipedia (1 tab)')
400
401
402class TwitterPage(Top25Page):
403
404  """ Why: #8 (Alexa global),Picked an interesting page """
405
406  def __init__(self, page_set):
407    super(TwitterPage, self).__init__(
408      url='https://twitter.com/katyperry',
409      page_set=page_set,
410      name='Twitter')
411
412  def RunNavigateSteps(self, action_runner):
413    action_runner.NavigateToPage(self)
414    action_runner.Wait(2)
415
416  def RunSmoothness(self, action_runner):
417    action_runner.RunAction(ScrollAction(
418      {
419        'scroll_is_infinite': True
420      }))
421
422
423class PinterestPage(Top25Page):
424
425  """ Why: #37 (Alexa global) """
426
427  def __init__(self, page_set):
428    super(PinterestPage, self).__init__(
429      url='http://pinterest.com',
430      page_set=page_set,
431      name='Pinterest')
432
433  def RunSmoothness(self, action_runner):
434    action_runner.RunAction(ScrollAction(
435      {
436        'scroll_is_infinite': True
437      }))
438
439
440class ESPNPage(Top25Page):
441
442  """ Why: #1 sports """
443
444  def __init__(self, page_set):
445    super(ESPNPage, self).__init__(
446      url='http://espn.go.com',
447      page_set=page_set,
448      name='ESPN')
449
450  def RunSmoothness(self, action_runner):
451    action_runner.RunAction(ScrollAction(
452      {
453        'left_start_percentage': 0.1
454      }))
455
456
457class WeatherDotComPage(Top25Page):
458
459  """ Why: #7 (Alexa news); #27 total time spent,Picked interesting page """
460
461  def __init__(self, page_set):
462    super(WeatherDotComPage, self).__init__(
463      # pylint: disable=C0301
464      url='http://www.weather.com/weather/right-now/Mountain+View+CA+94043',
465      page_set=page_set,
466      name='Weather.com')
467
468
469class YahooGamesPage(Top25Page):
470
471  """ Why: #1 games according to Alexa (with actual games in it) """
472
473  def __init__(self, page_set):
474    super(YahooGamesPage, self).__init__(
475      url='http://games.yahoo.com',
476      page_set=page_set)
477
478  def RunNavigateSteps(self, action_runner):
479    action_runner.NavigateToPage(self)
480    action_runner.Wait(2)
481
482
483class Top25PageSet(page_set_module.PageSet):
484
485  """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """
486
487  def __init__(self):
488    super(Top25PageSet, self).__init__(
489      credentials_path='data/credentials.json',
490      user_agent_type='desktop',
491      archive_data_file='data/top_25.json',
492      bucket=page_set_module.PARTNER_BUCKET)
493
494    self.AddPage(GoogleWebSearchPage(self))
495    self.AddPage(GmailPage(self))
496    self.AddPage(GoogleCalendarPage(self))
497    self.AddPage(GoogleImageSearchPage(self))
498    self.AddPage(GoogleDocPage(self))
499    self.AddPage(GooglePlusPage(self))
500    self.AddPage(YoutubePage(self))
501    self.AddPage(BlogspotPage(self))
502    self.AddPage(WordpressPage(self))
503    self.AddPage(FacebookPage(self))
504    self.AddPage(LinkedinPage(self))
505    self.AddPage(WikipediaPage(self))
506    self.AddPage(TwitterPage(self))
507    self.AddPage(PinterestPage(self))
508    self.AddPage(ESPNPage(self))
509    self.AddPage(WeatherDotComPage(self))
510    self.AddPage(YahooGamesPage(self))
511
512    other_urls = [
513      # Why: #1 news worldwide (Alexa global)
514      'http://news.yahoo.com',
515      # Why: #2 news worldwide
516      'http://www.cnn.com',
517      # Why: #1 world commerce website by visits; #3 commerce in the US by time
518      # spent
519      'http://www.amazon.com',
520      # Why: #1 commerce website by time spent by users in US
521      'http://www.ebay.com',
522      # Why: #1 Alexa recreation
523      'http://booking.com',
524      # Why: #1 Alexa reference
525      'http://answers.yahoo.com',
526      # Why: #1 Alexa sports
527      'http://sports.yahoo.com/',
528      # Why: top tech blog
529      'http://techcrunch.com'
530    ]
531
532    for url in other_urls:
533      self.AddPage(Top25Page(url, self))
534