Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / perf / page_sets / top_25.py
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
6
7
8 def _GetCurrentLocation(action_runner):
9   return action_runner.EvaluateJavaScript('document.location.href')
10
11
12 def _WaitForLocationChange(action_runner, old_href):
13   action_runner.WaitForJavaScriptCondition(
14       'document.location.href != "%s"' % old_href)
15
16
17 class Top25Page(page_module.Page):
18
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
26
27   def RunSmoothness(self, action_runner):
28     interaction = action_runner.BeginGestureInteraction(
29         'ScrollAction', is_smooth=True)
30     action_runner.ScrollPage()
31     interaction.End()
32
33   def RunRepaint(self, action_runner):
34     action_runner.RepaintContinuously(seconds=5)
35
36
37 class 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
51 class GmailPage(Top25Page):
52
53   """ Why: productivity, top google properties """
54
55   def __init__(self, page_set):
56     super(GmailPage, self).__init__(
57         url='https://mail.google.com/mail/',
58         page_set=page_set,
59         credentials='google')
60
61   def RunNavigateSteps(self, action_runner):
62     action_runner.NavigateToPage(self)
63     action_runner.WaitForJavaScriptCondition(
64         'window.gmonkey !== undefined &&'
65         'document.getElementById("gb") !== null')
66
67   def RunSmoothness(self, action_runner):
68     action_runner.ExecuteJavaScript('''
69         gmonkey.load('2.0', function(api) {
70           window.__scrollableElementForTelemetry = api.getScrollableElement();
71         });''')
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')
78     interaction.End()
79
80
81 class GoogleCalendarPage(Top25Page):
82
83   """ Why: productivity, top google properties """
84
85   def __init__(self, page_set):
86     super(GoogleCalendarPage, self).__init__(
87         url='https://www.google.com/calendar/',
88         page_set=page_set,
89         credentials='google')
90
91   def RunNavigateSteps(self, action_runner):
92     action_runner.NavigateToPage(self)
93     action_runner.Wait(2)
94     action_runner.WaitForElement('div[class~="navForward"]')
95     action_runner.ExecuteJavaScript('''
96         (function() {
97           var elem = document.createElement('meta');
98           elem.name='viewport';
99           elem.content='initial-scale=1';
100           document.body.appendChild(elem);
101         })();''')
102     action_runner.Wait(1)
103
104   def RunSmoothness(self, action_runner):
105     interaction = action_runner.BeginGestureInteraction(
106         'ScrollAction', is_smooth=True)
107     action_runner.ScrollElement(selector='#scrolltimedeventswk')
108     interaction.End()
109
110
111 class GoogleDocPage(Top25Page):
112
113   """ Why: productivity, top google properties; Sample doc in the link """
114
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',
119         page_set=page_set,
120         name='Docs  (1 open document tab)',
121         credentials='google')
122
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')
128
129   def RunSmoothness(self, action_runner):
130     interaction = action_runner.BeginGestureInteraction(
131         'ScrollAction', is_smooth=True)
132     action_runner.ScrollElement(selector='.kix-appview-editor')
133     interaction.End()
134
135
136 class GooglePlusPage(Top25Page):
137
138   """ Why: social; top google property; Public profile; infinite scrolls """
139
140   def __init__(self, page_set):
141     super(GooglePlusPage, self).__init__(
142         url='https://plus.google.com/110031535020051778989/posts',
143         page_set=page_set,
144         credentials='google')
145
146   def RunNavigateSteps(self, action_runner):
147     action_runner.NavigateToPage(self)
148     action_runner.WaitForElement(text='Home')
149
150   def RunSmoothness(self, action_runner):
151     interaction = action_runner.BeginGestureInteraction(
152         'ScrollAction', is_smooth=True)
153     action_runner.ScrollPage()
154     interaction.End()
155
156
157 class YoutubePage(Top25Page):
158
159   """ Why: #3 (Alexa global) """
160
161   def __init__(self, page_set):
162     super(YoutubePage, self).__init__(
163         url='http://www.youtube.com',
164         page_set=page_set, credentials='google')
165
166   def RunNavigateSteps(self, action_runner):
167     action_runner.NavigateToPage(self)
168     action_runner.Wait(2)
169
170
171 class BlogspotPage(Top25Page):
172
173   """ Why: #11 (Alexa global), google property; some blogger layouts have
174   infinite scroll but more interesting """
175
176   def __init__(self, page_set):
177     super(BlogspotPage, self).__init__(
178         url='http://googlewebmastercentral.blogspot.com/',
179         page_set=page_set,
180         name='Blogger')
181
182   def RunNavigateSteps(self, action_runner):
183     action_runner.NavigateToPage(self)
184     action_runner.WaitForElement(text='accessibility')
185
186
187 class WordpressPage(Top25Page):
188
189   """ Why: #18 (Alexa global), Picked an interesting post """
190
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/',
195         page_set=page_set,
196         name='Wordpress')
197
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/"]')
203
204
205 class FacebookPage(Top25Page):
206
207   """ Why: top social,Public profile """
208
209   def __init__(self, page_set):
210     super(FacebookPage, self).__init__(
211         url='https://www.facebook.com/barackobama',
212         page_set=page_set,
213         name='Facebook', credentials='facebook2')
214
215   def RunNavigateSteps(self, action_runner):
216     action_runner.NavigateToPage(self)
217     action_runner.WaitForElement(text='About')
218
219   def RunSmoothness(self, action_runner):
220     interaction = action_runner.BeginGestureInteraction(
221         'ScrollAction', is_smooth=True)
222     action_runner.ScrollPage()
223     interaction.End()
224
225
226 class TwitterPage(Top25Page):
227
228   """ Why: #8 (Alexa global),Picked an interesting page """
229
230   def __init__(self, page_set):
231     super(TwitterPage, self).__init__(
232         url='https://twitter.com/katyperry',
233         page_set=page_set,
234         name='Twitter')
235
236   def RunNavigateSteps(self, action_runner):
237     action_runner.NavigateToPage(self)
238     action_runner.Wait(2)
239
240   def RunSmoothness(self, action_runner):
241     interaction = action_runner.BeginGestureInteraction(
242         'ScrollAction', is_smooth=True)
243     action_runner.ScrollPage()
244     interaction.End()
245
246
247 class PinterestPage(Top25Page):
248
249   """ Why: #37 (Alexa global) """
250
251   def __init__(self, page_set):
252     super(PinterestPage, self).__init__(
253         url='http://pinterest.com',
254         page_set=page_set,
255         name='Pinterest')
256
257   def RunSmoothness(self, action_runner):
258     interaction = action_runner.BeginGestureInteraction(
259         'ScrollAction', is_smooth=True)
260     action_runner.ScrollPage()
261     interaction.End()
262
263
264 class ESPNPage(Top25Page):
265
266   """ Why: #1 sports """
267
268   def __init__(self, page_set):
269     super(ESPNPage, self).__init__(
270         url='http://espn.go.com',
271         page_set=page_set,
272         name='ESPN')
273
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)
278     interaction.End()
279
280
281 class YahooGamesPage(Top25Page):
282
283   """ Why: #1 games according to Alexa (with actual games in it) """
284
285   def __init__(self, page_set):
286     super(YahooGamesPage, self).__init__(
287         url='http://games.yahoo.com',
288         page_set=page_set)
289
290   def RunNavigateSteps(self, action_runner):
291     action_runner.NavigateToPage(self)
292     action_runner.Wait(2)
293
294
295 class Top25PageSet(page_set_module.PageSet):
296
297   """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """
298
299   def __init__(self):
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)
304
305     self.AddPage(GoogleWebSearchPage(self))
306     self.AddPage(GmailPage(self))
307     self.AddPage(GoogleCalendarPage(self))
308     # Why: tough image case; top google properties
309     self.AddPage(
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.
319     self.AddPage(
320         Top25Page(
321             'http://www.linkedin.com/in/linustorvalds', page_set=self,
322             name='LinkedIn'))
323     # Why: #6 (Alexa) most visited worldwide,Picked an interesting page
324     self.AddPage(
325         Top25Page(
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',
334         page_set=self,
335         name='Weather.com'))
336     self.AddPage(YahooGamesPage(self))
337
338     other_urls = [
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
344         # time spent
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/',
354         # Why: top tech blog
355         'http://techcrunch.com'
356     ]
357
358     for url in other_urls:
359       self.AddPage(Top25Page(url, self))