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
7 class TopPages(page_module
.Page
):
9 def __init__(self
, url
, page_set
, name
='', credentials
=None):
10 super(TopPages
, self
).__init
__(
11 url
=url
, page_set
=page_set
, name
=name
,
12 credentials_path
='data/credentials.json')
13 self
.user_agent_type
= 'desktop'
14 self
.archive_data_file
= 'data/top_25.json'
15 self
.credentials
= credentials
18 class GoogleWebSearchPage(TopPages
):
20 """ Why: top google property; a google tab is often open """
22 def __init__(self
, page_set
):
23 super(GoogleWebSearchPage
, self
).__init
__(
24 url
='https://www.google.com/#hl=en&q=barack+obama',
27 def RunNavigateSteps(self
, action_runner
):
28 super(GoogleWebSearchPage
, self
).RunNavigateSteps(action_runner
)
29 action_runner
.WaitForElement(text
='Next')
32 class GoogleImageSearchPage(TopPages
):
34 """ Why: tough image case; top google properties """
36 def __init__(self
, page_set
):
37 super(GoogleImageSearchPage
, self
).__init
__(
38 'https://www.google.com/search?q=cats&tbm=isch',
39 page_set
=page_set
, credentials
='google')
42 class GmailPage(TopPages
):
44 """ Why: productivity, top google properties """
46 def __init__(self
, page_set
):
47 super(GmailPage
, self
).__init
__(
48 url
='https://mail.google.com/mail/',
52 def RunNavigateSteps(self
, action_runner
):
53 super(GmailPage
, self
).RunNavigateSteps(action_runner
)
54 action_runner
.WaitForJavaScriptCondition(
55 'window.gmonkey !== undefined &&'
56 'document.getElementById("gb") !== null')
57 # This check is needed for gmonkey to load completely.
58 action_runner
.WaitForJavaScriptCondition(
59 'document.readyState == "complete"')
62 class GmailMouseScrollPage(GmailPage
):
64 """ Why: productivity, top google properties """
66 def RunPageInteractions(self
, action_runner
):
67 action_runner
.ExecuteJavaScript('''
68 gmonkey.load('2.0', function(api) {
69 window.__scrollableElementForTelemetry = api.getScrollableElement();
71 action_runner
.WaitForJavaScriptCondition(
72 'window.__scrollableElementForTelemetry != null')
73 scrollbar_x
, start_y
, end_y
= self
._CalculateScrollBarRatios
(action_runner
)
75 interaction
= action_runner
.BeginGestureInteraction(
77 action_runner
.DragPage(left_start_ratio
=scrollbar_x
,
78 top_start_ratio
=start_y
, left_end_ratio
=scrollbar_x
,
79 top_end_ratio
=end_y
, speed_in_pixels_per_second
=100,
80 element_function
='window.__scrollableElementForTelemetry')
83 def _CalculateScrollBarRatios(self
, action_runner
):
84 viewport_height
= float(action_runner
.EvaluateJavaScript(
85 'window.__scrollableElementForTelemetry.clientHeight'))
86 content_height
= float(action_runner
.EvaluateJavaScript(
87 'window.__scrollableElementForTelemetry.scrollHeight'))
88 viewport_width
= float(action_runner
.EvaluateJavaScript(
89 'window.__scrollableElementForTelemetry.offsetWidth'))
90 scrollbar_width
= float(action_runner
.EvaluateJavaScript('''
91 window.__scrollableElementForTelemetry.offsetWidth -
92 window.__scrollableElementForTelemetry.scrollWidth'''))
94 # This calculation is correct only when the element doesn't have border or
95 # padding or scroll buttons (eg: gmail mail element).
96 scrollbar_start_mid_y
= viewport_height
/ (2 * content_height
)
97 scrollbar_end_mid_y
= 1 - scrollbar_start_mid_y
98 scrollbar_mid_x_offset
= scrollbar_width
/ (2 * viewport_width
)
99 scrollbar_mid_x
= 1 - scrollbar_mid_x_offset
100 return scrollbar_mid_x
, scrollbar_start_mid_y
, scrollbar_end_mid_y
103 class GoogleCalendarPage(TopPages
):
105 """ Why: productivity, top google properties """
107 def __init__(self
, page_set
):
108 super(GoogleCalendarPage
, self
).__init
__(
109 url
='https://www.google.com/calendar/',
111 credentials
='google')
113 def RunNavigateSteps(self
, action_runner
):
114 super(GoogleCalendarPage
, self
).RunNavigateSteps(action_runner
)
115 action_runner
.Wait(2)
116 action_runner
.WaitForElement('div[class~="navForward"]')
117 action_runner
.ExecuteJavaScript('''
119 var elem = document.createElement('meta');
120 elem.name='viewport';
121 elem.content='initial-scale=1';
122 document.body.appendChild(elem);
124 action_runner
.Wait(1)
127 class GoogleDocPage(TopPages
):
129 """ Why: productivity, top google properties; Sample doc in the link """
131 def __init__(self
, page_set
):
132 super(GoogleDocPage
, self
).__init
__(
133 # pylint: disable=C0301
134 url
='https://docs.google.com/document/d/1X-IKNjtEnx-WW5JIKRLsyhz5sbsat3mfTpAPUSX3_s4/view',
136 name
='Docs (1 open document tab)',
137 credentials
='google')
139 def RunNavigateSteps(self
, action_runner
):
140 super(GoogleDocPage
, self
).RunNavigateSteps(action_runner
)
141 action_runner
.Wait(2)
142 action_runner
.WaitForJavaScriptCondition(
143 'document.getElementsByClassName("kix-appview-editor").length')
145 class GoogleMapsPage(TopPages
):
147 """ Why: productivity, top google properties; Supports drag gesturee """
149 def __init__(self
, page_set
):
150 super(GoogleMapsPage
, self
).__init
__(
151 url
='https://www.google.co.uk/maps/@51.5043968,-0.1526806',
155 def RunNavigateSteps(self
, action_runner
):
156 super(GoogleMapsPage
, self
).RunNavigateSteps(action_runner
)
157 action_runner
.WaitForElement(selector
='.widget-scene-canvas')
158 action_runner
.WaitForElement(selector
='.widget-zoom-in')
159 action_runner
.WaitForElement(selector
='.widget-zoom-out')
161 class GooglePlusPage(TopPages
):
163 """ Why: social; top google property; Public profile; infinite scrolls """
165 def __init__(self
, page_set
):
166 super(GooglePlusPage
, self
).__init
__(
167 url
='https://plus.google.com/110031535020051778989/posts',
169 credentials
='google')
171 def RunNavigateSteps(self
, action_runner
):
172 super(GooglePlusPage
, self
).RunNavigateSteps(action_runner
)
173 action_runner
.WaitForElement(text
='Home')
176 class YoutubePage(TopPages
):
178 """ Why: #3 (Alexa global) """
180 def __init__(self
, page_set
):
181 super(YoutubePage
, self
).__init
__(
182 url
='http://www.youtube.com',
183 page_set
=page_set
, credentials
='google')
185 def RunNavigateSteps(self
, action_runner
):
186 super(YoutubePage
, self
).RunNavigateSteps(action_runner
)
187 action_runner
.Wait(2)
190 class BlogspotPage(TopPages
):
192 """ Why: #11 (Alexa global), google property; some blogger layouts have
193 infinite scroll but more interesting """
195 def __init__(self
, page_set
):
196 super(BlogspotPage
, self
).__init
__(
197 url
='http://googlewebmastercentral.blogspot.com/',
201 def RunNavigateSteps(self
, action_runner
):
202 super(BlogspotPage
, self
).RunNavigateSteps(action_runner
)
203 action_runner
.WaitForElement(text
='accessibility')
206 class WordpressPage(TopPages
):
208 """ Why: #18 (Alexa global), Picked an interesting post """
210 def __init__(self
, page_set
):
211 super(WordpressPage
, self
).__init
__(
212 # pylint: disable=C0301
213 url
='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
217 def RunNavigateSteps(self
, action_runner
):
218 super(WordpressPage
, self
).RunNavigateSteps(action_runner
)
219 action_runner
.WaitForElement(
220 # pylint: disable=C0301
221 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
224 class FacebookPage(TopPages
):
226 """ Why: top social,Public profile """
228 def __init__(self
, page_set
):
229 super(FacebookPage
, self
).__init
__(
230 url
='https://www.facebook.com/barackobama',
232 name
='Facebook', credentials
='facebook2')
234 def RunNavigateSteps(self
, action_runner
):
235 super(FacebookPage
, self
).RunNavigateSteps(action_runner
)
236 action_runner
.WaitForElement(text
='Chat')
239 class LinkedinPage(TopPages
):
241 """ Why: #12 (Alexa global), Public profile. """
243 def __init__(self
, page_set
):
244 super(LinkedinPage
, self
).__init
__(
245 url
='http://www.linkedin.com/in/linustorvalds', page_set
=page_set
,
249 class WikipediaPage(TopPages
):
251 """ Why: #6 (Alexa) most visited worldwide,Picked an interesting page. """
253 def __init__(self
, page_set
):
254 super(WikipediaPage
, self
).__init
__(
255 url
='http://en.wikipedia.org/wiki/Wikipedia', page_set
=page_set
,
256 name
='Wikipedia (1 tab)')
259 class TwitterPage(TopPages
):
261 """ Why: #8 (Alexa global),Picked an interesting page """
263 def __init__(self
, page_set
):
264 super(TwitterPage
, self
).__init
__(
265 url
='https://twitter.com/katyperry',
269 def RunNavigateSteps(self
, action_runner
):
270 super(TwitterPage
, self
).RunNavigateSteps(action_runner
)
271 action_runner
.Wait(2)
274 class PinterestPage(TopPages
):
276 """ Why: #37 (Alexa global) """
278 def __init__(self
, page_set
):
279 super(PinterestPage
, self
).__init
__(
280 url
='http://pinterest.com',
285 class ESPNPage(TopPages
):
287 """ Why: #1 sports """
289 def __init__(self
, page_set
):
290 super(ESPNPage
, self
).__init
__(
291 url
='http://espn.go.com',
296 class WeatherPage(TopPages
):
298 """ Why: #7 (Alexa news); #27 total time spent, picked interesting page. """
300 def __init__(self
, page_set
):
301 super(WeatherPage
, self
).__init
__(
302 url
='http://www.weather.com/weather/right-now/Mountain+View+CA+94043',
307 class YahooGamesPage(TopPages
):
309 """ Why: #1 games according to Alexa (with actual games in it) """
311 def __init__(self
, page_set
):
312 super(YahooGamesPage
, self
).__init
__(
313 url
='http://games.yahoo.com',
316 def RunNavigateSteps(self
, action_runner
):
317 super(YahooGamesPage
, self
).RunNavigateSteps(action_runner
)
318 action_runner
.Wait(2)