top_10.py revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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
5from telemetry.page.actions.navigate import NavigateAction
6from telemetry.page.actions.javascript import JavascriptAction
7from telemetry.page.actions.scroll import ScrollAction
8from telemetry.page.actions.wait import WaitAction
9from telemetry.page.page_set import PageSet
10from telemetry.page.page import Page
11
12
13class SimpleScrollPage(Page):
14  def __init__(self, url, page_set, credentials=''):
15    super(SimpleScrollPage, self).__init__(url, page_set=page_set)
16    self.credentials = credentials
17
18  def RunSmoothness(self, action_runner):
19    action_runner.RunAction(ScrollAction())
20
21  def RunNavigateSteps(self, action_runner):
22    action_runner.RunAction(NavigateAction())
23
24
25class Google(SimpleScrollPage):
26  def __init__(self, page_set):
27    super(Google, self).__init__(
28      url='https://www.google.com/#hl=en&q=barack+obama', page_set=page_set)
29
30  def RunNavigateSteps(self, action_runner):
31    super(Google, self).RunNavigateSteps(action_runner)
32    action_runner.RunAction(WaitAction(
33      {'condition': 'element', 'text': 'Next'}))
34
35
36class Gmail(SimpleScrollPage):
37  def __init__(self, page_set):
38    super(Gmail, self).__init__(
39      url='https://mail.google.com/mail/',
40      page_set=page_set,
41      credentials='google')
42
43  def RunNavigateSteps(self, action_runner):
44    super(Gmail, self).RunNavigateSteps(action_runner)
45    action_runner.RunAction(WaitAction(
46      {'javascript' : 'window.gmonkey !== undefined &&'
47       'document.getElementById("gb") !== null'}))
48
49
50class GoogleCalendar(SimpleScrollPage):
51  def __init__(self, page_set):
52    super(GoogleCalendar, self).__init__(
53      url='https://www.google.com/calendar/',
54      page_set=page_set,
55      credentials='google')
56
57  def RunNavigateSteps(self, action_runner):
58    super(GoogleCalendar, self).RunNavigateSteps(action_runner)
59    action_runner.RunAction(JavascriptAction(
60      { 'expression' :
61       '(function() { var elem = document.createElement("meta");'
62      'elem.name="viewport";'
63      'elem.content="initial-scale=1";'
64      'document.body.appendChild(elem); })();'}))
65    action_runner.RunAction(WaitAction({'seconds' : 2}))
66    action_runner.RunAction(WaitAction({
67      'condition' : 'element', 'selector' : 'div[class~="navForward"]'}))
68
69
70class Youtube(SimpleScrollPage):
71  def __init__(self, page_set):
72    super(Youtube, self).__init__(
73      url='http://www.youtube.com',
74      page_set=page_set,
75      credentials='google')
76
77  def RunNavigateSteps(self, action_runner):
78    super(Youtube, self).RunNavigateSteps(action_runner)
79    action_runner.RunAction(WaitAction({'seconds' : 2}))
80
81
82class Facebook(SimpleScrollPage):
83  def __init__(self, page_set):
84    super(Facebook, self).__init__(
85      url='http://www.facebook.com/barackobama',
86      page_set=page_set,
87      credentials='facebook')
88    self.name = "Facebook"
89
90  def RunNavigateSteps(self, action_runner):
91    super(Facebook, self).RunNavigateSteps(action_runner)
92    action_runner.RunAction(WaitAction(
93      {'condition': 'element', 'text': 'About'}))
94
95
96class Top10PageSet(PageSet):
97  def __init__(self):
98    super(Top10PageSet, self).__init__(
99      description='10 Pages chosen from Alexa top sites',
100      archive_data_file='data/top_10.json',
101      credentials_path='data/credentials.json',
102      user_agent_type='desktop')
103
104    # top google property; a google tab is often open
105    self.AddPage(Google(self))
106
107    # productivity, top google properties
108    self.AddPage(Gmail(self))
109
110    # productivity, top google properties
111    self.AddPage(GoogleCalendar(self))
112
113    # #3 (Alexa global)
114    self.AddPage(Youtube(self))
115
116    # top social, Public profile
117    self.AddPage(Facebook(self))
118
119    # #6 (Alexa) most visited worldwide,Picked an interesting page
120    wikipedia_page = SimpleScrollPage('http://en.wikipedia.org/wiki/Wikipedia',
121                                      self)
122    wikipedia_page.name = "Wikipedia"
123    self.AddPage(wikipedia_page)
124
125    # #1 world commerce website by visits; #3 commerce in the US by time spent
126    self.AddPage(SimpleScrollPage('http://www.amazon.com', self))
127
128    # #4 Alexa
129    self.AddPage(SimpleScrollPage('http://www.yahoo.com/', self))
130
131    # #16 Alexa
132    self.AddPage(SimpleScrollPage('http://www.bing.com/', self))
133
134    # #20 Alexa
135    self.AddPage(SimpleScrollPage('http://www.ask.com/', self))
136