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