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
5 from telemetry.page import page_set as page_set_module
8 def _GetCurrentLocation(action_runner):
9 return action_runner.EvaluateJavaScript('document.location.href')
12 def _WaitForLocationChange(action_runner, old_href):
13 action_runner.WaitForJavaScriptCondition(
14 'document.location.href != "%s"' % old_href)
17 class Top25Page(page_module.Page):
19 def __init__(self, url, page_set, name='', credentials=None):
20 super(Top25Page, self).__init__(
21 url=url, page_set=page_set, name=name,
22 credentials_path='data/credentials.json')
23 self.user_agent_type = 'desktop'
24 self.archive_data_file = 'data/top_25.json'
25 self.credentials = credentials
27 def RunSmoothness(self, action_runner):
28 interaction = action_runner.BeginGestureInteraction(
29 'ScrollAction', is_smooth=True)
30 action_runner.ScrollPage()
33 def RunRepaint(self, action_runner):
34 action_runner.RepaintContinuously(seconds=5)
37 class GoogleWebSearchPage(Top25Page):
39 """ Why: top google property; a google tab is often open """
41 def __init__(self, page_set):
42 super(GoogleWebSearchPage, self).__init__(
43 url='https://www.google.com/#hl=en&q=barack+obama',
46 def RunNavigateSteps(self, action_runner):
47 action_runner.NavigateToPage(self)
48 action_runner.WaitForElement(text='Next')
51 class GmailPage(Top25Page):
53 """ Why: productivity, top google properties """
55 def __init__(self, page_set):
56 super(GmailPage, self).__init__(
57 url='https://mail.google.com/mail/',
61 def RunNavigateSteps(self, action_runner):
62 action_runner.NavigateToPage(self)
63 action_runner.WaitForJavaScriptCondition(
64 'window.gmonkey !== undefined &&'
65 'document.getElementById("gb") !== null')
67 def RunSmoothness(self, action_runner):
68 action_runner.ExecuteJavaScript('''
69 gmonkey.load('2.0', function(api) {
70 window.__scrollableElementForTelemetry = api.getScrollableElement();
72 action_runner.WaitForJavaScriptCondition(
73 'window.__scrollableElementForTelemetry != null')
74 interaction = action_runner.BeginGestureInteraction(
75 'ScrollAction', is_smooth=True)
76 action_runner.ScrollElement(
77 element_function='window.__scrollableElementForTelemetry')
81 class GoogleCalendarPage(Top25Page):
83 """ Why: productivity, top google properties """
85 def __init__(self, page_set):
86 super(GoogleCalendarPage, self).__init__(
87 url='https://www.google.com/calendar/',
91 def RunNavigateSteps(self, action_runner):
92 action_runner.NavigateToPage(self)
94 action_runner.WaitForElement('div[class~="navForward"]')
95 action_runner.ExecuteJavaScript('''
97 var elem = document.createElement('meta');
99 elem.content='initial-scale=1';
100 document.body.appendChild(elem);
102 action_runner.Wait(1)
104 def RunSmoothness(self, action_runner):
105 interaction = action_runner.BeginGestureInteraction(
106 'ScrollAction', is_smooth=True)
107 action_runner.ScrollElement(selector='#scrolltimedeventswk')
111 class GoogleDocPage(Top25Page):
113 """ Why: productivity, top google properties; Sample doc in the link """
115 def __init__(self, page_set):
116 super(GoogleDocPage, self).__init__(
117 # pylint: disable=C0301
118 url='https://docs.google.com/document/d/1X-IKNjtEnx-WW5JIKRLsyhz5sbsat3mfTpAPUSX3_s4/view',
120 name='Docs (1 open document tab)',
121 credentials='google')
123 def RunNavigateSteps(self, action_runner):
124 action_runner.NavigateToPage(self)
125 action_runner.Wait(2)
126 action_runner.WaitForJavaScriptCondition(
127 'document.getElementsByClassName("kix-appview-editor").length')
129 def RunSmoothness(self, action_runner):
130 interaction = action_runner.BeginGestureInteraction(
131 'ScrollAction', is_smooth=True)
132 action_runner.ScrollElement(selector='.kix-appview-editor')
136 class GooglePlusPage(Top25Page):
138 """ Why: social; top google property; Public profile; infinite scrolls """
140 def __init__(self, page_set):
141 super(GooglePlusPage, self).__init__(
142 url='https://plus.google.com/110031535020051778989/posts',
144 credentials='google')
146 def RunNavigateSteps(self, action_runner):
147 action_runner.NavigateToPage(self)
148 action_runner.WaitForElement(text='Home')
150 def RunSmoothness(self, action_runner):
151 interaction = action_runner.BeginGestureInteraction(
152 'ScrollAction', is_smooth=True)
153 action_runner.ScrollPage()
157 class YoutubePage(Top25Page):
159 """ Why: #3 (Alexa global) """
161 def __init__(self, page_set):
162 super(YoutubePage, self).__init__(
163 url='http://www.youtube.com',
164 page_set=page_set, credentials='google')
166 def RunNavigateSteps(self, action_runner):
167 action_runner.NavigateToPage(self)
168 action_runner.Wait(2)
171 class BlogspotPage(Top25Page):
173 """ Why: #11 (Alexa global), google property; some blogger layouts have
174 infinite scroll but more interesting """
176 def __init__(self, page_set):
177 super(BlogspotPage, self).__init__(
178 url='http://googlewebmastercentral.blogspot.com/',
182 def RunNavigateSteps(self, action_runner):
183 action_runner.NavigateToPage(self)
184 action_runner.WaitForElement(text='accessibility')
187 class WordpressPage(Top25Page):
189 """ Why: #18 (Alexa global), Picked an interesting post """
191 def __init__(self, page_set):
192 super(WordpressPage, self).__init__(
193 # pylint: disable=C0301
194 url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/',
198 def RunNavigateSteps(self, action_runner):
199 action_runner.NavigateToPage(self)
200 action_runner.WaitForElement(
201 # pylint: disable=C0301
202 'a[href="http://en.blog.wordpress.com/2012/08/30/new-themes-able-and-sight/"]')
205 class FacebookPage(Top25Page):
207 """ Why: top social,Public profile """
209 def __init__(self, page_set):
210 super(FacebookPage, self).__init__(
211 url='https://www.facebook.com/barackobama',
213 name='Facebook', credentials='facebook2')
215 def RunNavigateSteps(self, action_runner):
216 action_runner.NavigateToPage(self)
217 action_runner.WaitForElement(text='About')
219 def RunSmoothness(self, action_runner):
220 interaction = action_runner.BeginGestureInteraction(
221 'ScrollAction', is_smooth=True)
222 action_runner.ScrollPage()
226 class TwitterPage(Top25Page):
228 """ Why: #8 (Alexa global),Picked an interesting page """
230 def __init__(self, page_set):
231 super(TwitterPage, self).__init__(
232 url='https://twitter.com/katyperry',
236 def RunNavigateSteps(self, action_runner):
237 action_runner.NavigateToPage(self)
238 action_runner.Wait(2)
240 def RunSmoothness(self, action_runner):
241 interaction = action_runner.BeginGestureInteraction(
242 'ScrollAction', is_smooth=True)
243 action_runner.ScrollPage()
247 class PinterestPage(Top25Page):
249 """ Why: #37 (Alexa global) """
251 def __init__(self, page_set):
252 super(PinterestPage, self).__init__(
253 url='http://pinterest.com',
257 def RunSmoothness(self, action_runner):
258 interaction = action_runner.BeginGestureInteraction(
259 'ScrollAction', is_smooth=True)
260 action_runner.ScrollPage()
264 class ESPNPage(Top25Page):
266 """ Why: #1 sports """
268 def __init__(self, page_set):
269 super(ESPNPage, self).__init__(
270 url='http://espn.go.com',
274 def RunSmoothness(self, action_runner):
275 interaction = action_runner.BeginGestureInteraction(
276 'ScrollAction', is_smooth=True)
277 action_runner.ScrollPage(left_start_ratio=0.1)
281 class YahooGamesPage(Top25Page):
283 """ Why: #1 games according to Alexa (with actual games in it) """
285 def __init__(self, page_set):
286 super(YahooGamesPage, self).__init__(
287 url='http://games.yahoo.com',
290 def RunNavigateSteps(self, action_runner):
291 action_runner.NavigateToPage(self)
292 action_runner.Wait(2)
295 class Top25PageSet(page_set_module.PageSet):
297 """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """
300 super(Top25PageSet, self).__init__(
301 user_agent_type='desktop',
302 archive_data_file='data/top_25.json',
303 bucket=page_set_module.PARTNER_BUCKET)
305 self.AddPage(GoogleWebSearchPage(self))
306 self.AddPage(GmailPage(self))
307 self.AddPage(GoogleCalendarPage(self))
308 # Why: tough image case; top google properties
310 Top25Page('https://www.google.com/search?q=cats&tbm=isch',
311 page_set=self, credentials='google'))
312 self.AddPage(GoogleDocPage(self))
313 self.AddPage(GooglePlusPage(self))
314 self.AddPage(YoutubePage(self))
315 self.AddPage(BlogspotPage(self))
316 self.AddPage(WordpressPage(self))
317 self.AddPage(FacebookPage(self))
318 # Why: #12 (Alexa global), Public profile.
321 'http://www.linkedin.com/in/linustorvalds', page_set=self,
323 # Why: #6 (Alexa) most visited worldwide,Picked an interesting page
326 'http://en.wikipedia.org/wiki/Wikipedia', page_set=self,
327 name='Wikipedia (1 tab)'))
328 self.AddPage(TwitterPage(self))
329 self.AddPage(PinterestPage(self))
330 self.AddPage(ESPNPage(self))
331 # Why: #7 (Alexa news); #27 total time spent, picked interesting page.
332 self.AddPage(Top25Page(
333 url='http://www.weather.com/weather/right-now/Mountain+View+CA+94043',
336 self.AddPage(YahooGamesPage(self))
339 # Why: #1 news worldwide (Alexa global)
340 'http://news.yahoo.com',
341 # Why: #2 news worldwide
342 'http://www.cnn.com',
343 # Why: #1 world commerce website by visits; #3 commerce in the US by
345 'http://www.amazon.com',
346 # Why: #1 commerce website by time spent by users in US
347 'http://www.ebay.com',
348 # Why: #1 Alexa recreation
349 'http://booking.com',
350 # Why: #1 Alexa reference
351 'http://answers.yahoo.com',
352 # Why: #1 Alexa sports
353 'http://sports.yahoo.com/',
355 'http://techcrunch.com'
358 for url in other_urls:
359 self.AddPage(Top25Page(url, self))