Mojo C++ bindings: better log message for serialization warnings.
[chromium-blink-merge.git] / tools / perf / page_sets / polymer.py
blob2ec270a9af99c7fc1b9b92bd4519246e579350d2
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
7 class PolymerPage(page_module.Page):
9 def __init__(self, url, page_set):
10 super(PolymerPage, self).__init__(
11 url=url,
12 page_set=page_set)
13 self.script_to_evaluate_on_commit = '''
14 document.addEventListener("polymer-ready", function() {
15 window.__polymer_ready = true;
16 });
17 '''
19 def RunNavigateSteps(self, action_runner):
20 action_runner.NavigateToPage(self)
21 action_runner.WaitForJavaScriptCondition(
22 'window.__polymer_ready')
25 class PolymerCalculatorPage(PolymerPage):
27 def __init__(self, page_set):
28 super(PolymerCalculatorPage, self).__init__(
29 url=('http://www.polymer-project.org/components/paper-calculator/'
30 'demo.html'),
31 page_set=page_set)
33 def RunSmoothness(self, action_runner):
34 self.TapButton(action_runner)
35 self.SlidePanel(action_runner)
37 def TapButton(self, action_runner):
38 interaction = action_runner.BeginInteraction(
39 'Action_TapAction', is_smooth=True)
40 action_runner.TapElement(element_function='''
41 document.querySelector(
42 'body /deep/ #outerPanels'
43 ).querySelector(
44 '#standard'
45 ).shadowRoot.querySelector(
46 'paper-calculator-key[label="5"]'
47 )''')
48 action_runner.Wait(2)
49 interaction.End()
51 def SlidePanel(self, action_runner):
52 interaction = action_runner.BeginInteraction(
53 'Action_SwipeAction', is_smooth=True)
54 action_runner.SwipeElement(
55 left_start_ratio=0.1, top_start_ratio=0.2,
56 direction='left', distance=300, speed_in_pixels_per_second=5000,
57 element_function='''
58 document.querySelector(
59 'body /deep/ #outerPanels'
60 ).querySelector(
61 '#advanced'
62 ).shadowRoot.querySelector(
63 '.handle-bar'
64 )''')
65 action_runner.WaitForJavaScriptCondition('''
66 var outer = document.querySelector("body /deep/ #outerPanels");
67 outer.opened || outer.wideMode;''')
68 interaction.End()
71 class PolymerShadowPage(PolymerPage):
73 def __init__(self, page_set):
74 super(PolymerShadowPage, self).__init__(
75 url='http://www.polymer-project.org/components/paper-shadow/demo.html',
76 page_set=page_set)
78 def RunSmoothness(self, action_runner):
79 action_runner.ExecuteJavaScript(
80 "document.getElementById('fab').scrollIntoView()")
81 action_runner.Wait(5)
82 self.AnimateShadow(action_runner, 'card')
83 #FIXME(wiltzius) disabling until this issue is fixed:
84 # https://github.com/Polymer/paper-shadow/issues/12
85 #self.AnimateShadow(action_runner, 'fab')
87 def AnimateShadow(self, action_runner, eid):
88 for i in range(1, 6):
89 action_runner.ExecuteJavaScript(
90 'document.getElementById("{0}").z = {1}'.format(eid, i))
91 action_runner.Wait(1)
94 class PolymerSampler(PolymerPage):
96 def __init__(self, page_set, anchor, scrolling_page=False):
97 """Page exercising interactions with a single Paper Sampler subpage.
99 Args:
100 page_set: Page set to inforporate this page into.
101 anchor: string indicating which subpage to load (matches the element
102 type that page is displaying)
103 scrolling_page: Whether scrolling the content pane is relevant to this
104 content page or not.
106 super(PolymerSampler, self).__init__(
107 url=('http://www.polymer-project.org/components/%s/demo.html' % anchor),
108 page_set=page_set)
109 self.scrolling_page = scrolling_page
110 self.iframe_js = 'document'
112 def RunNavigateSteps(self, action_runner):
113 super(PolymerSampler, self).RunNavigateSteps(action_runner)
114 waitForLoadJS = """
115 window.Polymer.whenPolymerReady(function() {
116 %s.contentWindow.Polymer.whenPolymerReady(function() {
117 window.__polymer_ready = true;
120 """ % self.iframe_js
121 action_runner.ExecuteJavaScript(waitForLoadJS)
122 action_runner.WaitForJavaScriptCondition(
123 'window.__polymer_ready')
125 def RunSmoothness(self, action_runner):
126 #TODO(wiltzius) Add interactions for input elements and shadow pages
127 if self.scrolling_page:
128 # Only bother scrolling the page if its been marked as worthwhile
129 self.ScrollContentPane(action_runner)
130 self.TouchEverything(action_runner)
132 def ScrollContentPane(self, action_runner):
133 element_function = (self.iframe_js + '.querySelector('
134 '"core-scroll-header-panel").$.mainContainer')
135 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True)
136 action_runner.ScrollElement(use_touch=True,
137 direction='down',
138 distance='900',
139 element_function=element_function)
140 interaction.End()
141 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True)
142 action_runner.ScrollElement(use_touch=True,
143 direction='up',
144 distance='900',
145 element_function=element_function)
146 interaction.End()
148 def TouchEverything(self, action_runner):
149 tappable_types = [
150 'paper-button',
151 'paper-checkbox',
152 'paper-fab',
153 'paper-icon-button',
154 # crbug.com/394756
155 # 'paper-radio-button',
156 'paper-tab',
157 'paper-toggle-button',
158 'x-shadow',
160 for tappable_type in tappable_types:
161 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget)
162 swipeable_types = ['paper-slider']
163 for swipeable_type in swipeable_types:
164 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget)
166 def DoActionOnWidgetType(self, action_runner, widget_type, action_function):
167 # Find all widgets of this type, but skip any that are disabled or are
168 # currently active as they typically don't produce animation frames.
169 element_list_query = (self.iframe_js +
170 ('.querySelectorAll("body %s:not([disabled]):'
171 'not([active])")' % widget_type))
172 roles_count_query = element_list_query + '.length'
173 for i in range(action_runner.EvaluateJavaScript(roles_count_query)):
174 element_query = element_list_query + ("[%d]" % i)
175 if action_runner.EvaluateJavaScript(
176 element_query + '.offsetParent != null'):
177 # Only try to tap on visible elements (offsetParent != null)
178 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()')
179 action_runner.Wait(1) # wait for page to settle after scrolling
180 action_function(action_runner, element_query)
182 def TapWidget(self, action_runner, element_function):
183 interaction = action_runner.BeginInteraction(
184 'Tap_Widget', is_smooth=True)
185 action_runner.TapElement(element_function=element_function)
186 action_runner.Wait(1) # wait for e.g. animations on the widget
187 interaction.End()
189 def SwipeWidget(self, action_runner, element_function):
190 interaction = action_runner.BeginInteraction(
191 'Swipe_Widget', is_smooth=True)
192 action_runner.SwipeElement(element_function=element_function,
193 left_start_ratio=0.75,
194 speed_in_pixels_per_second=300)
195 interaction.End()
198 class PolymerPageSet(page_set_module.PageSet):
200 def __init__(self):
201 super(PolymerPageSet, self).__init__(
202 user_agent_type='mobile',
203 archive_data_file='data/polymer.json',
204 bucket=page_set_module.PUBLIC_BUCKET)
206 self.AddPage(PolymerCalculatorPage(self))
207 self.AddPage(PolymerShadowPage(self))
209 # Polymer Sampler subpages that are interesting to tap / swipe elements on
210 TAPPABLE_PAGES = [
211 'paper-button',
212 'paper-checkbox',
213 'paper-fab',
214 'paper-icon-button',
215 # crbug.com/394756
216 # 'paper-radio-button',
217 #FIXME(wiltzius) Disabling x-shadow until this issue is fixed:
218 # https://github.com/Polymer/paper-shadow/issues/12
219 #'paper-shadow',
220 'paper-tabs',
221 'paper-toggle-button',
223 for p in TAPPABLE_PAGES:
224 self.AddPage(PolymerSampler(self, p))
226 # Polymer Sampler subpages that are interesting to scroll
227 SCROLLABLE_PAGES = [
228 'core-scroll-header-panel',
230 for p in SCROLLABLE_PAGES:
231 self.AddPage(PolymerSampler(self, p, scrolling_page=True))