Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / perf / page_sets / key_silk_cases.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 # pylint: disable=W0401,W0614
5 from telemetry.page.actions.all_page_actions import *
6 from telemetry.page import page as page_module
7 from telemetry.page import page_set as page_set_module
8 from telemetry.web_perf import timeline_interaction_record as tir_module
9
10
11 class KeySilkCasesPage(page_module.Page):
12
13   def __init__(self, url, page_set):
14     super(KeySilkCasesPage, self).__init__(url=url, page_set=page_set)
15     self.credentials_path = 'data/credentials.json'
16     self.user_agent_type = 'mobile'
17     self.archive_data_file = 'data/key_silk_cases.json'
18
19   def RunNavigateSteps(self, action_runner):
20     action_runner.RunAction(NavigateAction())
21     action_runner.RunAction(WaitAction(
22       {
23         'seconds': 2
24       }))
25
26   def RunSmoothness(self, action_runner):
27     action_runner.RunAction(ScrollAction())
28
29
30 class Page1(KeySilkCasesPage):
31
32   """ Why: Infinite scroll. Brings out all of our perf issues. """
33
34   def __init__(self, page_set):
35     super(Page1, self).__init__(
36       url='http://groupcloned.com/test/plain/list-recycle-transform.html',
37       page_set=page_set)
38
39   def RunSmoothness(self, action_runner):
40     action_runner.RunAction(ScrollAction(
41       {
42         'scrollable_element_function': '''
43           function(callback) {
44             callback(document.getElementById('scrollable'));
45           }'''
46       }))
47
48
49 class Page2(KeySilkCasesPage):
50
51   """ Why: Brings out layer management bottlenecks. """
52
53   def __init__(self, page_set):
54     super(Page2, self).__init__(
55       url='http://groupcloned.com/test/plain/list-animation-simple.html',
56       page_set=page_set)
57
58   def RunSmoothness(self, action_runner):
59     action_runner.RunAction(WaitAction({'seconds': 2}))
60
61
62 class Page3(KeySilkCasesPage):
63
64   """
65   Why: Best-known method for fake sticky. Janks sometimes. Interacts badly with
66   compositor scrolls.
67   """
68
69   def __init__(self, page_set):
70     super(Page3, self).__init__(
71       # pylint: disable=C0301
72       url='http://groupcloned.com/test/plain/sticky-using-webkit-backface-visibility.html',
73       page_set=page_set)
74
75   def RunSmoothness(self, action_runner):
76     action_runner.RunAction(ScrollAction(
77       {
78         'scrollable_element_function': '''
79           function(callback) {
80             callback(document.getElementById('container'));
81           }'''
82       }))
83
84
85 class Page4(KeySilkCasesPage):
86
87   """
88   Why: Card expansion: only the card should repaint, but in reality lots of
89   storms happen.
90   """
91
92   def __init__(self, page_set):
93     super(Page4, self).__init__(
94       url='http://jsfiddle.net/3yDKh/4/embedded/result',
95       page_set=page_set)
96
97   def RunSmoothness(self, action_runner):
98     action_runner.RunAction(WaitAction({'seconds': 3}))
99
100
101 class Page5(KeySilkCasesPage):
102
103   """
104   Why: Card expansion with animated contents, using will-change on the card
105   """
106
107   def __init__(self, page_set):
108     super(Page5, self).__init__(
109       url='http://jsfiddle.net/jx5De/13/embedded/result',
110       page_set=page_set)
111
112     self.gpu_raster = True
113
114   def RunSmoothness(self, action_runner):
115     action_runner.RunAction(WaitAction({'seconds': 4}))
116
117
118 class Page6(KeySilkCasesPage):
119
120   """
121   Why: Card fly-in: It should be fast to animate in a bunch of cards using
122   margin-top and letting layout do the rest.
123   """
124
125   def __init__(self, page_set):
126     super(Page6, self).__init__(
127       url='http://jsfiddle.net/3yDKh/6/embedded/result',
128       page_set=page_set)
129
130   def RunSmoothness(self, action_runner):
131     action_runner.RunAction(WaitAction({'seconds': 3}))
132
133
134 class Page7(KeySilkCasesPage):
135
136   """
137   Why: Image search expands a spacer div when you click an image to accomplish
138   a zoomin effect. Each image has a layer. Even so, this triggers a lot of
139   unnecessary repainting.
140   """
141
142   def __init__(self, page_set):
143     super(Page7, self).__init__(
144       url='http://jsfiddle.net/R8DX9/1/embedded/result/',
145       page_set=page_set)
146
147   def RunSmoothness(self, action_runner):
148     action_runner.RunAction(WaitAction({'seconds': 3}))
149
150
151 class Page8(KeySilkCasesPage):
152
153   """
154   Why: Swipe to dismiss of an element that has a fixed-position child that is
155   its pseudo-sticky header. Brings out issues with layer creation and
156   repainting.
157   """
158
159   def __init__(self, page_set):
160     super(Page8, self).__init__(
161       url='http://jsfiddle.net/rF9Gh/3/embedded/result/',
162       page_set=page_set)
163
164   def RunSmoothness(self, action_runner):
165     action_runner.RunAction(WaitAction({'seconds': 3}))
166
167
168 class Page9(KeySilkCasesPage):
169
170   """
171   Why: Horizontal and vertical expansion of a card that is cheap to layout but
172   costly to rasterize.
173   """
174
175   def __init__(self, page_set):
176     super(Page9, self).__init__(
177       url='http://jsfiddle.net/TLXLu/2/embedded/result/',
178       page_set=page_set)
179
180     self.gpu_raster = True
181
182   def RunSmoothness(self, action_runner):
183     action_runner.RunAction(WaitAction({'seconds': 4}))
184
185
186 class Page10(KeySilkCasesPage):
187
188   """
189   Why: Vertical Expansion of a card that is cheap to layout but costly to
190   rasterize.
191   """
192
193   def __init__(self, page_set):
194     super(Page10, self).__init__(
195       url='http://jsfiddle.net/cKB9D/6/embedded/result/',
196       page_set=page_set)
197
198     self.gpu_raster = True
199
200   def RunSmoothness(self, action_runner):
201     action_runner.RunAction(WaitAction({'seconds': 4}))
202
203
204 class Page11(KeySilkCasesPage):
205
206   """
207   Why: Parallax effect is common on photo-viewer-like applications, overloading
208   software rasterization
209   """
210
211   def __init__(self, page_set):
212     super(Page11, self).__init__(
213       url='http://jsfiddle.net/vBQHH/10/embedded/result/',
214       page_set=page_set)
215
216     self.gpu_raster = True
217
218   def RunSmoothness(self, action_runner):
219     action_runner.RunAction(WaitAction({'seconds': 4}))
220
221
222 class Page12(KeySilkCasesPage):
223
224   """ Why: Addressing paint storms during coordinated animations. """
225
226   def __init__(self, page_set):
227     super(Page12, self).__init__(
228       url='http://jsfiddle.net/ugkd4/9/embedded/result/',
229       page_set=page_set)
230
231   def RunSmoothness(self, action_runner):
232     action_runner.RunAction(WaitAction({'seconds': 5}))
233
234
235 class Page13(KeySilkCasesPage):
236
237   """ Why: Mask transitions are common mobile use cases. """
238
239   def __init__(self, page_set):
240     super(Page13, self).__init__(
241       url='http://jsfiddle.net/xLuvC/embedded/result/',
242       page_set=page_set)
243
244     self.gpu_raster = True
245
246   def RunSmoothness(self, action_runner):
247     action_runner.RunAction(WaitAction({'seconds': 4}))
248
249
250 class Page14(KeySilkCasesPage):
251
252   """ Why: Card expansions with images and text are pretty and common. """
253
254   def __init__(self, page_set):
255     super(Page14, self).__init__(
256       url='http://jsfiddle.net/bNp2h/1/embedded/result/',
257       page_set=page_set)
258
259     self.gpu_raster = True
260
261   def RunSmoothness(self, action_runner):
262     action_runner.RunAction(WaitAction({'seconds': 4}))
263
264
265 class Page15(KeySilkCasesPage):
266
267   """ Why: Coordinated animations for expanding elements. """
268
269   def __init__(self, page_set):
270     super(Page15, self).__init__(
271       url='file://key_silk_cases/font_wipe.html',
272       page_set=page_set)
273
274   def RunSmoothness(self, action_runner):
275     action_runner.RunAction(WaitAction({'seconds': 5}))
276
277
278 class Page16(KeySilkCasesPage):
279
280   def __init__(self, page_set):
281     super(Page16, self).__init__(
282       url='file://key_silk_cases/inbox_app.html?swipe_to_dismiss',
283       page_set=page_set)
284
285   def RunNavigateSteps(self, action_runner):
286     action_runner.RunAction(NavigateAction())
287     action_runner.RunAction(WaitAction({'seconds': 2}))
288
289   def SwipeToDismiss(self, action_runner):
290     action_runner.RunAction(SwipeAction(
291       {
292         'left_start_percentage': 0.8,
293         'distance': 200,
294         'direction': 'left',
295         'top_start_percentage': 0.2,
296         'element_function': '''
297           function(callback) {
298             callback(document.getElementsByClassName('message')[2]);
299           }''',
300         'speed': 5000
301       }))
302     action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH])
303     action_runner.RunAction(WaitAction({
304       'javascript': 'document.getElementsByClassName("message").length < 18'
305     }))
306     action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH])
307
308   def RunSmoothness(self, action_runner):
309     self.SwipeToDismiss(action_runner)
310
311
312 class Page17(KeySilkCasesPage):
313
314   def __init__(self, page_set):
315     super(Page17, self).__init__(
316       url='file://key_silk_cases/inbox_app.html?stress_hidey_bars',
317       page_set=page_set)
318
319   def RunNavigateSteps(self, action_runner):
320     action_runner.RunAction(NavigateAction())
321     action_runner.RunAction(WaitAction({'seconds': 2}))
322
323   def RunSmoothness(self, action_runner):
324     self.StressHideyBars(action_runner)
325
326   def StressHideyBars(self, action_runner):
327     action_runner.RunAction(ScrollAction(
328       {
329         'direction': 'down',
330         'speed': 200,
331         'scrollable_element_function': '''
332           function(callback) {
333             callback(document.getElementById('messages'));
334           }'''
335       }))
336     action_runner.RunAction(ScrollAction(
337       {
338         'direction': 'up',
339         'speed': 200,
340         'scrollable_element_function': '''
341           function(callback) {
342             callback(document.getElementById('messages'));
343           }'''
344       }))
345     action_runner.RunAction(ScrollAction(
346       {
347         'direction': 'down',
348         'speed': 200,
349         'scrollable_element_function': '''
350           function(callback) {
351             callback(document.getElementById('messages'));
352           }'''
353       }))
354
355
356 class Page18(KeySilkCasesPage):
357
358   def __init__(self, page_set):
359     super(Page18, self).__init__(
360       url='file://key_silk_cases/inbox_app.html?toggle_drawer',
361       page_set=page_set)
362
363   def RunNavigateSteps(self, action_runner):
364     action_runner.RunAction(NavigateAction())
365     action_runner.RunAction(WaitAction(
366       {
367         'seconds': 2
368       }))
369
370   def RunSmoothness(self, action_runner):
371     for _ in xrange(6):
372       self.ToggleDrawer(action_runner)
373
374   def ToggleDrawer(self, action_runner):
375     action_runner.RunAction(TapAction(
376       {
377         'selector': '#menu-button',
378         'wait_after' : {'seconds': 1}
379       }))
380
381
382 class Page19(KeySilkCasesPage):
383
384   def __init__(self, page_set):
385     super(Page19, self).__init__(
386       url='file://key_silk_cases/inbox_app.html?slide_drawer',
387       page_set=page_set)
388
389   def ToggleDrawer(self, action_runner):
390     action_runner.RunAction(TapAction(
391       {
392         'selector': '#menu-button'
393       }))
394     action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH])
395     action_runner.RunAction(WaitAction({
396       'javascript': 'document.getElementById("nav-drawer").active'
397     }))
398     action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH])
399
400
401   def RunNavigateSteps(self, action_runner):
402     action_runner.RunAction(NavigateAction())
403     action_runner.RunAction(WaitAction({'seconds': 2}))
404     self.ToggleDrawer(action_runner)
405
406   def RunSmoothness(self, action_runner):
407     self.SlideDrawer(action_runner)
408
409   def SlideDrawer(self, action_runner):
410     action_runner.RunAction(SwipeAction(
411       {
412         'left_start_percentage': 0.8,
413         'distance': 200,
414         'direction': 'left',
415         'top_start_percentage': 0.2,
416         'element_function': '''
417           function(callback) {
418             callback(document.getElementById('nav-drawer').children[0]);
419           }''',
420         'wait_after' : {
421           'javascript': '!document.getElementById("nav-drawer").active'
422         }
423       }))
424
425
426 class Page20(KeySilkCasesPage):
427
428   """ Why: Shadow DOM infinite scrolling. """
429
430   def __init__(self, page_set):
431     super(Page20, self).__init__(
432       url='file://key_silk_cases/infinite_scrolling.html',
433       page_set=page_set)
434
435   def RunSmoothness(self, action_runner):
436     action_runner.RunAction(ScrollAction(
437       {
438         'speed': 5000,
439         'scrollable_element_function': '''
440           function(callback) {
441             callback(document.getElementById('container'));
442           }'''
443       }))
444
445
446 class Page21(KeySilkCasesPage):
447
448   def __init__(self, page_set):
449     super(Page21, self).__init__(
450       url='http://www.google.com/#q=google',
451       page_set=page_set)
452
453   def ScrollKnowledgeCardToTop(self, action_runner):
454     # scroll until the knowledge card is at the top
455     action_runner.RunAction(ScrollAction(
456       {
457         'scroll_distance_function': '''
458           function() {
459             var el = document.getElementById('kno-result');
460             var bound = el.getBoundingClientRect();
461             return bound.top - document.body.scrollTop;
462           }
463         '''
464       }))
465
466   def ExpandKnowledgeCard(self, action_runner):
467     # expand card
468     action_runner.RunAction(TapAction(
469       {
470         'element_function': '''
471           function(callback) {
472             callback(document.getElementsByClassName("vk_arc")[0]);
473           }''',
474         'wait_after': {'seconds': 2}
475       }))
476
477
478   def RunNavigateSteps(self, action_runner):
479     action_runner.RunAction(NavigateAction())
480     action_runner.RunAction(WaitAction({'seconds': 3}))
481     self.ScrollKnowledgeCardToTop(action_runner)
482
483   def RunSmoothness(self, action_runner):
484     self.ExpandKnowledgeCard(action_runner)
485
486
487 class Page22(KeySilkCasesPage):
488
489   def __init__(self, page_set):
490     super(Page22, self).__init__(
491       url='http://plus.google.com/app/basic/stream',
492       page_set=page_set)
493
494     self.disabled = 'Times out on Windows; crbug.com/338838'
495     self.credentials = 'google'
496
497   def RunNavigateSteps(self, action_runner):
498     action_runner.RunAction(NavigateAction())
499     action_runner.RunAction(WaitAction(
500       {
501         'javascript': 'document.getElementsByClassName("fHa").length > 0'
502       }))
503     action_runner.RunAction(WaitAction(
504       {
505         'seconds': 2
506       }))
507
508   def RunSmoothness(self, action_runner):
509     action_runner.RunAction(ScrollAction(
510       {
511         'scrollable_element_function': '''
512           function(callback) {
513             callback(document.getElementById('mainContent'));
514           }'''
515       }))
516
517
518 class Page23(KeySilkCasesPage):
519
520   """
521   Why: Physical simulation demo that does a lot of element.style mutation
522   triggering JS and recalc slowness
523   """
524
525   def __init__(self, page_set):
526     super(Page23, self).__init__(
527       url='http://jsbin.com/UVIgUTa/6/quiet',
528       page_set=page_set)
529
530   def RunSmoothness(self, action_runner):
531     action_runner.RunAction(ScrollAction(
532       {
533         'direction': 'down',
534         'scroll_requires_touch': True,
535         'scroll_distance_function':
536           'function() { return window.innerHeight / 2; }'
537       }))
538     action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH])
539     action_runner.RunAction(WaitAction({'seconds' : 1}))
540     action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH])
541
542
543 class Page24(KeySilkCasesPage):
544
545   """
546   Why: Google News: this iOS version is slower than accelerated scrolling
547   """
548
549   def __init__(self, page_set):
550     super(Page24, self).__init__(
551       url='http://mobile-news.sandbox.google.com/news/pt0?scroll',
552       page_set=page_set)
553
554   def RunNavigateSteps(self, action_runner):
555     action_runner.RunAction(NavigateAction())
556     action_runner.RunAction(WaitAction(
557       {
558         'javascript': 'document.getElementById(":h") != null'
559       }))
560     action_runner.RunAction(WaitAction(
561       {
562         'seconds': 1
563       }))
564
565   def RunSmoothness(self, action_runner):
566     action_runner.RunAction(ScrollAction(
567       {
568         'scroll_distance_function': 'function() { return 2500; }',
569         'scrollable_element_function':
570           'function(callback) { callback(document.getElementById(":5")); }',
571         'scroll_requires_touch': True
572       }))
573
574
575 class Page25(KeySilkCasesPage):
576
577   def __init__(self, page_set):
578     super(Page25, self).__init__(
579       url='http://mobile-news.sandbox.google.com/news/pt0?swipe',
580       page_set=page_set)
581
582   def RunNavigateSteps(self, action_runner):
583     action_runner.RunAction(NavigateAction())
584     action_runner.RunAction(WaitAction(
585       {
586         'javascript': 'document.getElementById(":h") != null'
587       }))
588     action_runner.RunAction(WaitAction(
589       {
590         'seconds': 1
591       }))
592
593   def RunSmoothness(self, action_runner):
594     action_runner.RunAction(SwipeAction(
595       {
596         'distance': 100,
597         'direction': "left",
598         'element_function': '''
599           function(callback) {
600             callback(document.getElementById(':f'));
601           }'''
602       }))
603     action_runner.BeginInteraction('Wait', [tir_module.IS_SMOOTH])
604     action_runner.RunAction(WaitAction({'seconds' : 1}))
605     action_runner.EndInteraction('Wait', [tir_module.IS_SMOOTH])
606
607
608 class Page26(KeySilkCasesPage):
609
610   """ Why: famo.us twitter demo """
611
612   def __init__(self, page_set):
613     super(Page26, self).__init__(
614       url='http://s.codepen.io/befamous/fullpage/pFsqb?scroll',
615       page_set=page_set)
616
617   def RunNavigateSteps(self, action_runner):
618     action_runner.RunAction(NavigateAction())
619     action_runner.RunAction(WaitAction(
620       {
621         'javascript': 'document.getElementsByClassName("tweet").length > 0'
622       }))
623     action_runner.RunAction(WaitAction(
624       {
625         'seconds': 1
626       }))
627
628   def RunSmoothness(self, action_runner):
629     action_runner.RunAction(ScrollAction(
630       {
631         'scroll_distance_function': 'function() { return 5000; }'
632       }))
633
634
635 class KeySilkCasesPageSet(page_set_module.PageSet):
636
637   """ Pages hand-picked for project Silk. """
638
639   def __init__(self):
640     super(KeySilkCasesPageSet, self).__init__(
641       credentials_path='data/credentials.json',
642       user_agent_type='mobile',
643       archive_data_file='data/key_silk_cases.json')
644
645     self.AddPage(Page1(self))
646     self.AddPage(Page2(self))
647     self.AddPage(Page3(self))
648     self.AddPage(Page4(self))
649     self.AddPage(Page5(self))
650     self.AddPage(Page6(self))
651     self.AddPage(Page7(self))
652     self.AddPage(Page8(self))
653     self.AddPage(Page9(self))
654     self.AddPage(Page10(self))
655     self.AddPage(Page11(self))
656     self.AddPage(Page12(self))
657     self.AddPage(Page13(self))
658     self.AddPage(Page14(self))
659     self.AddPage(Page15(self))
660     self.AddPage(Page16(self))
661     self.AddPage(Page17(self))
662     self.AddPage(Page18(self))
663     self.AddPage(Page19(self))
664     self.AddPage(Page20(self))
665     self.AddPage(Page21(self))
666     self.AddPage(Page22(self))
667     self.AddPage(Page23(self))
668     self.AddPage(Page24(self))
669     self.AddPage(Page25(self))
670     # self.AddPage(Page26(self))  # crbug.com/366371