Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tools/perf/page_sets/polymer.py

Issue 2618333006: [tools/perf] Fix JavaScript interpolation in action_runner calls (Closed)
Patch Set: fix a few more interpolations Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 from telemetry.page import page as page_module 4 from telemetry.page import page as page_module
5 from telemetry.page import shared_page_state 5 from telemetry.page import shared_page_state
6 from telemetry import story 6 from telemetry import story
7 from telemetry.util import js_template
7 8
8 9
9 class PolymerPage(page_module.Page): 10 class PolymerPage(page_module.Page):
10 11
11 def __init__(self, url, page_set, run_no_page_interactions): 12 def __init__(self, url, page_set, run_no_page_interactions):
12 """ Base class for all polymer pages. 13 """ Base class for all polymer pages.
13 14
14 Args: 15 Args:
15 run_no_page_interactions: whether the page will run any interactions after 16 run_no_page_interactions: whether the page will run any interactions after
16 navigate steps. 17 navigate steps.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 action_runner.ExecuteJavaScript( 105 action_runner.ExecuteJavaScript(
105 "document.getElementById('fab').scrollIntoView()") 106 "document.getElementById('fab').scrollIntoView()")
106 action_runner.Wait(5) 107 action_runner.Wait(5)
107 self.AnimateShadow(action_runner, 'card') 108 self.AnimateShadow(action_runner, 'card')
108 #FIXME(wiltzius) disabling until this issue is fixed: 109 #FIXME(wiltzius) disabling until this issue is fixed:
109 # https://github.com/Polymer/paper-shadow/issues/12 110 # https://github.com/Polymer/paper-shadow/issues/12
110 #self.AnimateShadow(action_runner, 'fab') 111 #self.AnimateShadow(action_runner, 'fab')
111 112
112 def AnimateShadow(self, action_runner, eid): 113 def AnimateShadow(self, action_runner, eid):
113 for i in range(1, 6): 114 for i in range(1, 6):
114 # TODO(catapult:#3028): Fix interpolation of JavaScript values.
115 action_runner.ExecuteJavaScript( 115 action_runner.ExecuteJavaScript(
116 'document.getElementById("{0}").z = {1}'.format(eid, i)) 116 'document.getElementById({{ eid }}).z = {{ i }}', eid=eid, i=i)
117 action_runner.Wait(1) 117 action_runner.Wait(1)
118 118
119 119
120 class PolymerSampler(PolymerPage): 120 class PolymerSampler(PolymerPage):
121 121
122 def __init__(self, page_set, anchor, run_no_page_interactions, 122 def __init__(self, page_set, anchor, run_no_page_interactions,
123 scrolling_page=False): 123 scrolling_page=False):
124 """Page exercising interactions with a single Paper Sampler subpage. 124 """Page exercising interactions with a single Paper Sampler subpage.
125 125
126 Args: 126 Args:
127 page_set: Page set to inforporate this page into. 127 page_set: Page set to inforporate this page into.
128 anchor: string indicating which subpage to load (matches the element 128 anchor: string indicating which subpage to load (matches the element
129 type that page is displaying) 129 type that page is displaying)
130 scrolling_page: Whether scrolling the content pane is relevant to this 130 scrolling_page: Whether scrolling the content pane is relevant to this
131 content page or not. 131 content page or not.
132 """ 132 """
133 super(PolymerSampler, self).__init__( 133 super(PolymerSampler, self).__init__(
134 url=('http://www.polymer-project.org/components/%s/demo.html' % anchor), 134 url=('http://www.polymer-project.org/components/%s/demo.html' % anchor),
135 page_set=page_set, run_no_page_interactions=run_no_page_interactions) 135 page_set=page_set, run_no_page_interactions=run_no_page_interactions)
136 self.scrolling_page = scrolling_page 136 self.scrolling_page = scrolling_page
137 self.iframe_js = 'document' 137 self.iframe_js = 'document'
138 138
139 def RunNavigateSteps(self, action_runner): 139 def RunNavigateSteps(self, action_runner):
140 super(PolymerSampler, self).RunNavigateSteps(action_runner) 140 super(PolymerSampler, self).RunNavigateSteps(action_runner)
141 # TODO(catapult:#3028): Fix interpolation of JavaScript values. 141 action_runner.ExecuteJavaScript("""
142 waitForLoadJS = """ 142 window.Polymer.whenPolymerReady(function() {
143 window.Polymer.whenPolymerReady(function() { 143 {{ @iframe }}.contentWindow.Polymer.whenPolymerReady(function() {
144 %s.contentWindow.Polymer.whenPolymerReady(function() { 144 window.__polymer_ready = true;
145 window.__polymer_ready = true; 145 })
146 }) 146 });
147 }); 147 """, iframe=self.iframe_js)
148 """ % self.iframe_js
149 action_runner.ExecuteJavaScript(waitForLoadJS)
150 action_runner.WaitForJavaScriptCondition( 148 action_runner.WaitForJavaScriptCondition(
151 'window.__polymer_ready') 149 'window.__polymer_ready')
152 150
153 def PerformPageInteractions(self, action_runner): 151 def PerformPageInteractions(self, action_runner):
154 #TODO(wiltzius) Add interactions for input elements and shadow pages 152 #TODO(wiltzius) Add interactions for input elements and shadow pages
155 if self.scrolling_page: 153 if self.scrolling_page:
156 # Only bother scrolling the page if its been marked as worthwhile 154 # Only bother scrolling the page if its been marked as worthwhile
157 self.ScrollContentPane(action_runner) 155 self.ScrollContentPane(action_runner)
158 self.TouchEverything(action_runner) 156 self.TouchEverything(action_runner)
159 157
(...skipping 25 matching lines...) Expand all
185 ] 183 ]
186 for tappable_type in tappable_types: 184 for tappable_type in tappable_types:
187 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget) 185 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget)
188 swipeable_types = ['paper-slider'] 186 swipeable_types = ['paper-slider']
189 for swipeable_type in swipeable_types: 187 for swipeable_type in swipeable_types:
190 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget) 188 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget)
191 189
192 def DoActionOnWidgetType(self, action_runner, widget_type, action_function): 190 def DoActionOnWidgetType(self, action_runner, widget_type, action_function):
193 # Find all widgets of this type, but skip any that are disabled or are 191 # Find all widgets of this type, but skip any that are disabled or are
194 # currently active as they typically don't produce animation frames. 192 # currently active as they typically don't produce animation frames.
195 # TODO(catapult:#3028): Fix interpolation of JavaScript values. 193 element_list_query = js_template.Render(
196 element_list_query = (self.iframe_js + 194 '{{ @iframe }}.querySelectorAll({{ selector }})',
197 ('.querySelectorAll("body %s:not([disabled]):' 195 iframe=self.iframe_js,
198 'not([active])")' % widget_type)) 196 selector='body %s:not([disabled]):not([active])' % widget_type)
197
199 roles_count_query = element_list_query + '.length' 198 roles_count_query = element_list_query + '.length'
200 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): 199 for i in range(action_runner.EvaluateJavaScript(roles_count_query)):
201 # TODO(catapult:#3028): Fix interpolation of JavaScript values. 200 element_query = js_template.Render(
202 element_query = element_list_query + ("[%d]" % i) 201 '{{ @query }}[{{ i }}]', query=element_list_query, i=i)
203 if action_runner.EvaluateJavaScript( 202 if action_runner.EvaluateJavaScript(
204 element_query + '.offsetParent != null'): 203 element_query + '.offsetParent != null'):
205 # Only try to tap on visible elements (offsetParent != null) 204 # Only try to tap on visible elements (offsetParent != null)
206 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') 205 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()')
207 action_runner.Wait(1) # wait for page to settle after scrolling 206 action_runner.Wait(1) # wait for page to settle after scrolling
208 action_function(action_runner, element_query) 207 action_function(action_runner, element_query)
209 208
210 def TapWidget(self, action_runner, element_function): 209 def TapWidget(self, action_runner, element_function):
211 with action_runner.CreateInteraction('Tap_Widget', repeatable=True): 210 with action_runner.CreateInteraction('Tap_Widget', repeatable=True):
212 action_runner.TapElement(element_function=element_function) 211 action_runner.TapElement(element_function=element_function)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 for p in SCROLLABLE_PAGES: 253 for p in SCROLLABLE_PAGES:
255 self.AddStory(PolymerSampler( 254 self.AddStory(PolymerSampler(
256 self, p, run_no_page_interactions=run_no_page_interactions, 255 self, p, run_no_page_interactions=run_no_page_interactions,
257 scrolling_page=True)) 256 scrolling_page=True))
258 257
259 for page in self: 258 for page in self:
260 assert (page.__class__.RunPageInteractions == 259 assert (page.__class__.RunPageInteractions ==
261 PolymerPage.RunPageInteractions), ( 260 PolymerPage.RunPageInteractions), (
262 'Pages in this page set must not override PolymerPage\' ' 261 'Pages in this page set must not override PolymerPage\' '
263 'RunPageInteractions method.') 262 'RunPageInteractions method.')
OLDNEW
« no previous file with comments | « tools/perf/page_sets/login_helpers/login_utils.py ('k') | tools/perf/page_sets/repaint_helpers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698