OLD | NEW |
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 from telemetry.util import js_template |
8 | 8 |
9 | 9 |
10 class PolymerPage(page_module.Page): | 10 class PolymerPage(page_module.Page): |
(...skipping 22 matching lines...) Expand all Loading... |
33 if self._run_no_page_interactions: | 33 if self._run_no_page_interactions: |
34 return | 34 return |
35 self.PerformPageInteractions(action_runner) | 35 self.PerformPageInteractions(action_runner) |
36 | 36 |
37 def PerformPageInteractions(self, action_runner): | 37 def PerformPageInteractions(self, action_runner): |
38 """ Override this to perform actions after the page has navigated. """ | 38 """ Override this to perform actions after the page has navigated. """ |
39 pass | 39 pass |
40 | 40 |
41 def RunNavigateSteps(self, action_runner): | 41 def RunNavigateSteps(self, action_runner): |
42 super(PolymerPage, self).RunNavigateSteps(action_runner) | 42 super(PolymerPage, self).RunNavigateSteps(action_runner) |
43 action_runner.WaitForJavaScriptCondition2( | 43 action_runner.WaitForJavaScriptCondition( |
44 'window.__polymer_ready') | 44 'window.__polymer_ready') |
45 | 45 |
46 | 46 |
47 class PolymerCalculatorPage(PolymerPage): | 47 class PolymerCalculatorPage(PolymerPage): |
48 | 48 |
49 def __init__(self, page_set, run_no_page_interactions): | 49 def __init__(self, page_set, run_no_page_interactions): |
50 super(PolymerCalculatorPage, self).__init__( | 50 super(PolymerCalculatorPage, self).__init__( |
51 url=('http://www.polymer-project.org/components/paper-calculator/' | 51 url=('http://www.polymer-project.org/components/paper-calculator/' |
52 'demo.html'), | 52 'demo.html'), |
53 page_set=page_set, run_no_page_interactions=run_no_page_interactions) | 53 page_set=page_set, run_no_page_interactions=run_no_page_interactions) |
54 | 54 |
55 def PerformPageInteractions(self, action_runner): | 55 def PerformPageInteractions(self, action_runner): |
56 self.TapButton(action_runner) | 56 self.TapButton(action_runner) |
57 self.SlidePanel(action_runner) | 57 self.SlidePanel(action_runner) |
58 | 58 |
59 def TapButton(self, action_runner): | 59 def TapButton(self, action_runner): |
60 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True): | 60 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True): |
61 action_runner.TapElement(element_function=''' | 61 action_runner.TapElement(element_function=''' |
62 document.querySelector( | 62 document.querySelector( |
63 'body /deep/ #outerPanels' | 63 'body /deep/ #outerPanels' |
64 ).querySelector( | 64 ).querySelector( |
65 '#standard' | 65 '#standard' |
66 ).shadowRoot.querySelector( | 66 ).shadowRoot.querySelector( |
67 'paper-calculator-key[label="5"]' | 67 'paper-calculator-key[label="5"]' |
68 )''') | 68 )''') |
69 action_runner.Wait(2) | 69 action_runner.Wait(2) |
70 | 70 |
71 def SlidePanel(self, action_runner): | 71 def SlidePanel(self, action_runner): |
72 # only bother with this interaction if the drawer is hidden | 72 # only bother with this interaction if the drawer is hidden |
73 opened = action_runner.EvaluateJavaScript2(''' | 73 opened = action_runner.EvaluateJavaScript(''' |
74 (function() { | 74 (function() { |
75 var outer = document.querySelector("body /deep/ #outerPanels"); | 75 var outer = document.querySelector("body /deep/ #outerPanels"); |
76 return outer.opened || outer.wideMode; | 76 return outer.opened || outer.wideMode; |
77 }());''') | 77 }());''') |
78 if not opened: | 78 if not opened: |
79 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True): | 79 with action_runner.CreateInteraction('PolymerAnimation', repeatable=True): |
80 action_runner.SwipeElement( | 80 action_runner.SwipeElement( |
81 left_start_ratio=0.1, top_start_ratio=0.2, | 81 left_start_ratio=0.1, top_start_ratio=0.2, |
82 direction='left', distance=300, speed_in_pixels_per_second=5000, | 82 direction='left', distance=300, speed_in_pixels_per_second=5000, |
83 element_function=''' | 83 element_function=''' |
84 document.querySelector( | 84 document.querySelector( |
85 'body /deep/ #outerPanels' | 85 'body /deep/ #outerPanels' |
86 ).querySelector( | 86 ).querySelector( |
87 '#advanced' | 87 '#advanced' |
88 ).shadowRoot.querySelector( | 88 ).shadowRoot.querySelector( |
89 '.handle-bar' | 89 '.handle-bar' |
90 )''') | 90 )''') |
91 action_runner.WaitForJavaScriptCondition2(''' | 91 action_runner.WaitForJavaScriptCondition(''' |
92 var outer = document.querySelector("body /deep/ #outerPanels"); | 92 var outer = document.querySelector("body /deep/ #outerPanels"); |
93 outer.opened || outer.wideMode;''') | 93 outer.opened || outer.wideMode;''') |
94 | 94 |
95 | 95 |
96 class PolymerShadowPage(PolymerPage): | 96 class PolymerShadowPage(PolymerPage): |
97 | 97 |
98 def __init__(self, page_set, run_no_page_interactions): | 98 def __init__(self, page_set, run_no_page_interactions): |
99 super(PolymerShadowPage, self).__init__( | 99 super(PolymerShadowPage, self).__init__( |
100 url='http://www.polymer-project.org/components/paper-shadow/demo.html', | 100 url='http://www.polymer-project.org/components/paper-shadow/demo.html', |
101 page_set=page_set, run_no_page_interactions=run_no_page_interactions) | 101 page_set=page_set, run_no_page_interactions=run_no_page_interactions) |
102 | 102 |
103 def PerformPageInteractions(self, action_runner): | 103 def PerformPageInteractions(self, action_runner): |
104 with action_runner.CreateInteraction('ScrollAndShadowAnimation'): | 104 with action_runner.CreateInteraction('ScrollAndShadowAnimation'): |
105 action_runner.ExecuteJavaScript2( | 105 action_runner.ExecuteJavaScript( |
106 "document.getElementById('fab').scrollIntoView()") | 106 "document.getElementById('fab').scrollIntoView()") |
107 action_runner.Wait(5) | 107 action_runner.Wait(5) |
108 self.AnimateShadow(action_runner, 'card') | 108 self.AnimateShadow(action_runner, 'card') |
109 #FIXME(wiltzius) disabling until this issue is fixed: | 109 #FIXME(wiltzius) disabling until this issue is fixed: |
110 # https://github.com/Polymer/paper-shadow/issues/12 | 110 # https://github.com/Polymer/paper-shadow/issues/12 |
111 #self.AnimateShadow(action_runner, 'fab') | 111 #self.AnimateShadow(action_runner, 'fab') |
112 | 112 |
113 def AnimateShadow(self, action_runner, eid): | 113 def AnimateShadow(self, action_runner, eid): |
114 for i in range(1, 6): | 114 for i in range(1, 6): |
115 action_runner.ExecuteJavaScript2( | 115 action_runner.ExecuteJavaScript( |
116 'document.getElementById({{ eid }}).z = {{ i }}', eid=eid, i=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 action_runner.ExecuteJavaScript2(""" | 141 action_runner.ExecuteJavaScript(""" |
142 window.Polymer.whenPolymerReady(function() { | 142 window.Polymer.whenPolymerReady(function() { |
143 {{ @iframe }}.contentWindow.Polymer.whenPolymerReady(function() { | 143 {{ @iframe }}.contentWindow.Polymer.whenPolymerReady(function() { |
144 window.__polymer_ready = true; | 144 window.__polymer_ready = true; |
145 }) | 145 }) |
146 }); | 146 }); |
147 """, iframe=self.iframe_js) | 147 """, iframe=self.iframe_js) |
148 action_runner.WaitForJavaScriptCondition2( | 148 action_runner.WaitForJavaScriptCondition( |
149 'window.__polymer_ready') | 149 'window.__polymer_ready') |
150 | 150 |
151 def PerformPageInteractions(self, action_runner): | 151 def PerformPageInteractions(self, action_runner): |
152 #TODO(wiltzius) Add interactions for input elements and shadow pages | 152 #TODO(wiltzius) Add interactions for input elements and shadow pages |
153 if self.scrolling_page: | 153 if self.scrolling_page: |
154 # Only bother scrolling the page if its been marked as worthwhile | 154 # Only bother scrolling the page if its been marked as worthwhile |
155 self.ScrollContentPane(action_runner) | 155 self.ScrollContentPane(action_runner) |
156 self.TouchEverything(action_runner) | 156 self.TouchEverything(action_runner) |
157 | 157 |
158 def ScrollContentPane(self, action_runner): | 158 def ScrollContentPane(self, action_runner): |
(...skipping 30 matching lines...) Expand all Loading... |
189 | 189 |
190 def DoActionOnWidgetType(self, action_runner, widget_type, action_function): | 190 def DoActionOnWidgetType(self, action_runner, widget_type, action_function): |
191 # 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 |
192 # currently active as they typically don't produce animation frames. | 192 # currently active as they typically don't produce animation frames. |
193 element_list_query = js_template.Render( | 193 element_list_query = js_template.Render( |
194 '{{ @iframe }}.querySelectorAll({{ selector }})', | 194 '{{ @iframe }}.querySelectorAll({{ selector }})', |
195 iframe=self.iframe_js, | 195 iframe=self.iframe_js, |
196 selector='body %s:not([disabled]):not([active])' % widget_type) | 196 selector='body %s:not([disabled]):not([active])' % widget_type) |
197 | 197 |
198 roles_count_query = element_list_query + '.length' | 198 roles_count_query = element_list_query + '.length' |
199 for i in range(action_runner.EvaluateJavaScript2(roles_count_query)): | 199 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): |
200 element_query = js_template.Render( | 200 element_query = js_template.Render( |
201 '{{ @query }}[{{ i }}]', query=element_list_query, i=i) | 201 '{{ @query }}[{{ i }}]', query=element_list_query, i=i) |
202 if action_runner.EvaluateJavaScript2( | 202 if action_runner.EvaluateJavaScript( |
203 element_query + '.offsetParent != null'): | 203 element_query + '.offsetParent != null'): |
204 # Only try to tap on visible elements (offsetParent != null) | 204 # Only try to tap on visible elements (offsetParent != null) |
205 action_runner.ExecuteJavaScript2(element_query + '.scrollIntoView()') | 205 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') |
206 action_runner.Wait(1) # wait for page to settle after scrolling | 206 action_runner.Wait(1) # wait for page to settle after scrolling |
207 action_function(action_runner, element_query) | 207 action_function(action_runner, element_query) |
208 | 208 |
209 def TapWidget(self, action_runner, element_function): | 209 def TapWidget(self, action_runner, element_function): |
210 with action_runner.CreateInteraction('Tap_Widget', repeatable=True): | 210 with action_runner.CreateInteraction('Tap_Widget', repeatable=True): |
211 action_runner.TapElement(element_function=element_function) | 211 action_runner.TapElement(element_function=element_function) |
212 action_runner.Wait(1) # wait for e.g. animations on the widget | 212 action_runner.Wait(1) # wait for e.g. animations on the widget |
213 | 213 |
214 def SwipeWidget(self, action_runner, element_function): | 214 def SwipeWidget(self, action_runner, element_function): |
215 with action_runner.CreateInteraction('Swipe_Widget'): | 215 with action_runner.CreateInteraction('Swipe_Widget'): |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 for p in SCROLLABLE_PAGES: | 253 for p in SCROLLABLE_PAGES: |
254 self.AddStory(PolymerSampler( | 254 self.AddStory(PolymerSampler( |
255 self, p, run_no_page_interactions=run_no_page_interactions, | 255 self, p, run_no_page_interactions=run_no_page_interactions, |
256 scrolling_page=True)) | 256 scrolling_page=True)) |
257 | 257 |
258 for page in self: | 258 for page in self: |
259 assert (page.__class__.RunPageInteractions == | 259 assert (page.__class__.RunPageInteractions == |
260 PolymerPage.RunPageInteractions), ( | 260 PolymerPage.RunPageInteractions), ( |
261 'Pages in this page set must not override PolymerPage\' ' | 261 'Pages in this page set must not override PolymerPage\' ' |
262 'RunPageInteractions method.') | 262 'RunPageInteractions method.') |
OLD | NEW |