blob: fb465044ff6823a897bf2b2228a6d9e79b2eded7 [file] [log] [blame]
[email protected]58ec0f42014-04-26 22:41:431# 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.
[email protected]58ec0f42014-04-26 22:41:434from telemetry.page import page as page_module
nednguyen7f9aa0c2015-06-11 20:48:215from telemetry.page import shared_page_state
nednguyenb82df292015-07-01 20:17:156from telemetry import story
perezju80aedca2017-01-12 10:03:007from telemetry.util import js_template
nednguyen7f9aa0c2015-06-11 20:48:218
[email protected]58ec0f42014-04-26 22:41:439
[email protected]0d8afa5b2014-05-02 16:58:5310class PolymerPage(page_module.Page):
[email protected]8cbe0702014-05-02 02:10:0711
nednguyen05140bce2015-02-16 17:07:5612 def __init__(self, url, page_set, run_no_page_interactions):
13 """ Base class for all polymer pages.
14
15 Args:
16 run_no_page_interactions: whether the page will run any interactions after
17 navigate steps.
18 """
[email protected]8cbe0702014-05-02 02:10:0719 super(PolymerPage, self).__init__(
20 url=url,
nednguyen7f9aa0c2015-06-11 20:48:2121 shared_page_state_class=shared_page_state.SharedMobilePageState,
ashleymarie500f75b22017-06-06 19:24:0822 page_set=page_set,
23 name=url)
[email protected]8cbe0702014-05-02 02:10:0724 self.script_to_evaluate_on_commit = '''
25 document.addEventListener("polymer-ready", function() {
26 window.__polymer_ready = true;
27 });
28 '''
nednguyen05140bce2015-02-16 17:07:5629 self._run_no_page_interactions = run_no_page_interactions
30
vmiura70e100f22015-02-18 02:45:2831 def RunPageInteractions(self, action_runner):
32 # If a polymer page wants to customize its actions, it should
33 # override the PerformPageInteractions method instead of this method.
nednguyen05140bce2015-02-16 17:07:5634 if self._run_no_page_interactions:
35 return
36 self.PerformPageInteractions(action_runner)
37
38 def PerformPageInteractions(self, action_runner):
39 """ Override this to perform actions after the page has navigated. """
40 pass
[email protected]8cbe0702014-05-02 02:10:0741
42 def RunNavigateSteps(self, action_runner):
ariblue735db9f2015-01-15 20:14:3543 super(PolymerPage, self).RunNavigateSteps(action_runner)
perezjud42421be2017-02-28 09:40:2044 action_runner.WaitForJavaScriptCondition(
[email protected]64bb94f2014-06-08 07:00:5745 'window.__polymer_ready')
[email protected]8cbe0702014-05-02 02:10:0746
47
48class PolymerCalculatorPage(PolymerPage):
[email protected]58ec0f42014-04-26 22:41:4349
nednguyen05140bce2015-02-16 17:07:5650 def __init__(self, page_set, run_no_page_interactions):
[email protected]58ec0f42014-04-26 22:41:4351 super(PolymerCalculatorPage, self).__init__(
[email protected]71c92782014-07-15 18:05:5352 url=('http://www.polymer-project.org/components/paper-calculator/'
53 'demo.html'),
nednguyen05140bce2015-02-16 17:07:5654 page_set=page_set, run_no_page_interactions=run_no_page_interactions)
[email protected]58ec0f42014-04-26 22:41:4355
nednguyen05140bce2015-02-16 17:07:5656 def PerformPageInteractions(self, action_runner):
[email protected]58ec0f42014-04-26 22:41:4357 self.TapButton(action_runner)
58 self.SlidePanel(action_runner)
59
60 def TapButton(self, action_runner):
nednguyeneb2eca942015-04-28 00:08:0961 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True):
nednguyen9e1bf62a42015-04-09 22:55:5162 action_runner.TapElement(element_function='''
63 document.querySelector(
64 'body /deep/ #outerPanels'
65 ).querySelector(
66 '#standard'
67 ).shadowRoot.querySelector(
68 'paper-calculator-key[label="5"]'
69 )''')
70 action_runner.Wait(2)
[email protected]58ec0f42014-04-26 22:41:4371
72 def SlidePanel(self, action_runner):
[email protected]d89ff642014-08-21 20:46:3373 # only bother with this interaction if the drawer is hidden
perezjud42421be2017-02-28 09:40:2074 opened = action_runner.EvaluateJavaScript('''
[email protected]d89ff642014-08-21 20:46:3375 (function() {
76 var outer = document.querySelector("body /deep/ #outerPanels");
77 return outer.opened || outer.wideMode;
78 }());''')
79 if not opened:
nednguyeneb2eca942015-04-28 00:08:0980 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True):
nednguyen9e1bf62a42015-04-09 22:55:5181 action_runner.SwipeElement(
82 left_start_ratio=0.1, top_start_ratio=0.2,
83 direction='left', distance=300, speed_in_pixels_per_second=5000,
84 element_function='''
85 document.querySelector(
86 'body /deep/ #outerPanels'
87 ).querySelector(
88 '#advanced'
89 ).shadowRoot.querySelector(
90 '.handle-bar'
91 )''')
perezjud42421be2017-02-28 09:40:2092 action_runner.WaitForJavaScriptCondition('''
nednguyen9e1bf62a42015-04-09 22:55:5193 var outer = document.querySelector("body /deep/ #outerPanels");
94 outer.opened || outer.wideMode;''')
[email protected]58ec0f42014-04-26 22:41:4395
96
[email protected]8cbe0702014-05-02 02:10:0797class PolymerShadowPage(PolymerPage):
98
nednguyen05140bce2015-02-16 17:07:5699 def __init__(self, page_set, run_no_page_interactions):
[email protected]8cbe0702014-05-02 02:10:07100 super(PolymerShadowPage, self).__init__(
[email protected]71c92782014-07-15 18:05:53101 url='http://www.polymer-project.org/components/paper-shadow/demo.html',
nednguyen05140bce2015-02-16 17:07:56102 page_set=page_set, run_no_page_interactions=run_no_page_interactions)
[email protected]8cbe0702014-05-02 02:10:07103
nednguyen05140bce2015-02-16 17:07:56104 def PerformPageInteractions(self, action_runner):
nednguyen0b55812e2015-04-22 00:35:52105 with action_runner.CreateInteraction('ScrollAndShadowAnimation'):
perezjud42421be2017-02-28 09:40:20106 action_runner.ExecuteJavaScript(
nednguyen0b55812e2015-04-22 00:35:52107 "document.getElementById('fab').scrollIntoView()")
108 action_runner.Wait(5)
109 self.AnimateShadow(action_runner, 'card')
110 #FIXME(wiltzius) disabling until this issue is fixed:
111 # https://github.com/Polymer/paper-shadow/issues/12
112 #self.AnimateShadow(action_runner, 'fab')
[email protected]8cbe0702014-05-02 02:10:07113
114 def AnimateShadow(self, action_runner, eid):
115 for i in range(1, 6):
perezjud42421be2017-02-28 09:40:20116 action_runner.ExecuteJavaScript(
perezju80aedca2017-01-12 10:03:00117 'document.getElementById({{ eid }}).z = {{ i }}', eid=eid, i=i)
[email protected]64bb94f2014-06-08 07:00:57118 action_runner.Wait(1)
[email protected]8cbe0702014-05-02 02:10:07119
120
[email protected]71c92782014-07-15 18:05:53121class PolymerSampler(PolymerPage):
122
nednguyen05140bce2015-02-16 17:07:56123 def __init__(self, page_set, anchor, run_no_page_interactions,
124 scrolling_page=False):
[email protected]71c92782014-07-15 18:05:53125 """Page exercising interactions with a single Paper Sampler subpage.
126
127 Args:
128 page_set: Page set to inforporate this page into.
129 anchor: string indicating which subpage to load (matches the element
130 type that page is displaying)
131 scrolling_page: Whether scrolling the content pane is relevant to this
132 content page or not.
133 """
134 super(PolymerSampler, self).__init__(
[email protected]04caf732014-08-19 23:42:49135 url=('http://www.polymer-project.org/components/%s/demo.html' % anchor),
nednguyen05140bce2015-02-16 17:07:56136 page_set=page_set, run_no_page_interactions=run_no_page_interactions)
[email protected]71c92782014-07-15 18:05:53137 self.scrolling_page = scrolling_page
[email protected]04caf732014-08-19 23:42:49138 self.iframe_js = 'document'
[email protected]71c92782014-07-15 18:05:53139
140 def RunNavigateSteps(self, action_runner):
[email protected]71c92782014-07-15 18:05:53141 super(PolymerSampler, self).RunNavigateSteps(action_runner)
perezjud42421be2017-02-28 09:40:20142 action_runner.ExecuteJavaScript("""
perezju80aedca2017-01-12 10:03:00143 window.Polymer.whenPolymerReady(function() {
144 {{ @iframe }}.contentWindow.Polymer.whenPolymerReady(function() {
145 window.__polymer_ready = true;
146 })
147 });
148 """, iframe=self.iframe_js)
perezjud42421be2017-02-28 09:40:20149 action_runner.WaitForJavaScriptCondition(
[email protected]9e9bef022014-08-06 21:31:38150 'window.__polymer_ready')
[email protected]71c92782014-07-15 18:05:53151
nednguyen05140bce2015-02-16 17:07:56152 def PerformPageInteractions(self, action_runner):
[email protected]71c92782014-07-15 18:05:53153 #TODO(wiltzius) Add interactions for input elements and shadow pages
154 if self.scrolling_page:
155 # Only bother scrolling the page if its been marked as worthwhile
156 self.ScrollContentPane(action_runner)
157 self.TouchEverything(action_runner)
158
159 def ScrollContentPane(self, action_runner):
[email protected]04caf732014-08-19 23:42:49160 element_function = (self.iframe_js + '.querySelector('
[email protected]71c92782014-07-15 18:05:53161 '"core-scroll-header-panel").$.mainContainer')
nednguyeneb2eca942015-04-28 00:08:09162 with action_runner.CreateInteraction('Scroll_Page', repeatable=True):
nednguyen9e1bf62a42015-04-09 22:55:51163 action_runner.ScrollElement(use_touch=True,
164 direction='down',
165 distance='900',
166 element_function=element_function)
nednguyeneb2eca942015-04-28 00:08:09167 with action_runner.CreateInteraction('Scroll_Page', repeatable=True):
nednguyen9e1bf62a42015-04-09 22:55:51168 action_runner.ScrollElement(use_touch=True,
169 direction='up',
170 distance='900',
171 element_function=element_function)
[email protected]71c92782014-07-15 18:05:53172
173 def TouchEverything(self, action_runner):
[email protected]26b7dfe2014-07-17 14:26:56174 tappable_types = [
175 'paper-button',
176 'paper-checkbox',
177 'paper-fab',
178 'paper-icon-button',
[email protected]ad6bcbc32014-08-06 02:59:53179 # crbug.com/394756
180 # 'paper-radio-button',
[email protected]26b7dfe2014-07-17 14:26:56181 'paper-tab',
182 'paper-toggle-button',
183 'x-shadow',
184 ]
[email protected]71c92782014-07-15 18:05:53185 for tappable_type in tappable_types:
186 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget)
187 swipeable_types = ['paper-slider']
188 for swipeable_type in swipeable_types:
189 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget)
190
191 def DoActionOnWidgetType(self, action_runner, widget_type, action_function):
192 # Find all widgets of this type, but skip any that are disabled or are
193 # currently active as they typically don't produce animation frames.
perezju80aedca2017-01-12 10:03:00194 element_list_query = js_template.Render(
195 '{{ @iframe }}.querySelectorAll({{ selector }})',
196 iframe=self.iframe_js,
197 selector='body %s:not([disabled]):not([active])' % widget_type)
198
[email protected]71c92782014-07-15 18:05:53199 roles_count_query = element_list_query + '.length'
perezjud42421be2017-02-28 09:40:20200 for i in range(action_runner.EvaluateJavaScript(roles_count_query)):
perezju80aedca2017-01-12 10:03:00201 element_query = js_template.Render(
202 '{{ @query }}[{{ i }}]', query=element_list_query, i=i)
perezjud42421be2017-02-28 09:40:20203 if action_runner.EvaluateJavaScript(
[email protected]71c92782014-07-15 18:05:53204 element_query + '.offsetParent != null'):
205 # Only try to tap on visible elements (offsetParent != null)
perezjud42421be2017-02-28 09:40:20206 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()')
[email protected]71c92782014-07-15 18:05:53207 action_runner.Wait(1) # wait for page to settle after scrolling
208 action_function(action_runner, element_query)
209
210 def TapWidget(self, action_runner, element_function):
nednguyeneb2eca942015-04-28 00:08:09211 with action_runner.CreateInteraction('Tap_Widget', repeatable=True):
nednguyen9e1bf62a42015-04-09 22:55:51212 action_runner.TapElement(element_function=element_function)
213 action_runner.Wait(1) # wait for e.g. animations on the widget
[email protected]71c92782014-07-15 18:05:53214
215 def SwipeWidget(self, action_runner, element_function):
nednguyen9e1bf62a42015-04-09 22:55:51216 with action_runner.CreateInteraction('Swipe_Widget'):
217 action_runner.SwipeElement(element_function=element_function,
218 left_start_ratio=0.75,
219 speed_in_pixels_per_second=300)
[email protected]71c92782014-07-15 18:05:53220
221
nednguyenb82df292015-07-01 20:17:15222class PolymerPageSet(story.StorySet):
[email protected]58ec0f42014-04-26 22:41:43223
nednguyen05140bce2015-02-16 17:07:56224 def __init__(self, run_no_page_interactions=False):
[email protected]58ec0f42014-04-26 22:41:43225 super(PolymerPageSet, self).__init__(
[email protected]41af08a2014-06-13 09:05:31226 archive_data_file='data/polymer.json',
ashleymariec3c82af2017-06-14 02:21:54227 cloud_storage_bucket=story.PUBLIC_BUCKET)
[email protected]58ec0f42014-04-26 22:41:43228
nednguyen98099b82015-07-06 23:07:24229 self.AddStory(PolymerCalculatorPage(self, run_no_page_interactions))
230 self.AddStory(PolymerShadowPage(self, run_no_page_interactions))
[email protected]71c92782014-07-15 18:05:53231
232 # Polymer Sampler subpages that are interesting to tap / swipe elements on
[email protected]26b7dfe2014-07-17 14:26:56233 TAPPABLE_PAGES = [
234 'paper-button',
235 'paper-checkbox',
236 'paper-fab',
237 'paper-icon-button',
[email protected]ad6bcbc32014-08-06 02:59:53238 # crbug.com/394756
239 # 'paper-radio-button',
[email protected]04caf732014-08-19 23:42:49240 #FIXME(wiltzius) Disabling x-shadow until this issue is fixed:
241 # https://github.com/Polymer/paper-shadow/issues/12
242 #'paper-shadow',
[email protected]26b7dfe2014-07-17 14:26:56243 'paper-tabs',
244 'paper-toggle-button',
245 ]
[email protected]71c92782014-07-15 18:05:53246 for p in TAPPABLE_PAGES:
nednguyen98099b82015-07-06 23:07:24247 self.AddStory(PolymerSampler(
nednguyen05140bce2015-02-16 17:07:56248 self, p, run_no_page_interactions=run_no_page_interactions))
[email protected]71c92782014-07-15 18:05:53249
250 # Polymer Sampler subpages that are interesting to scroll
[email protected]781849a02014-07-18 16:14:44251 SCROLLABLE_PAGES = [
[email protected]04caf732014-08-19 23:42:49252 'core-scroll-header-panel',
[email protected]781849a02014-07-18 16:14:44253 ]
[email protected]71c92782014-07-15 18:05:53254 for p in SCROLLABLE_PAGES:
nednguyen98099b82015-07-06 23:07:24255 self.AddStory(PolymerSampler(
nednguyen05140bce2015-02-16 17:07:56256 self, p, run_no_page_interactions=run_no_page_interactions,
257 scrolling_page=True))
258
259 for page in self:
260 assert (page.__class__.RunPageInteractions ==
261 PolymerPage.RunPageInteractions), (
262 'Pages in this page set must not override PolymerPage\' '
263 'RunPageInteractions method.')