| 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 page_set as page_set_module | 5 from telemetry.page import page_set as page_set_module |
| 6 | 6 |
| 7 class PolymerPage(page_module.Page): | 7 class PolymerPage(page_module.Page): |
| 8 | 8 |
| 9 def __init__(self, url, page_set, run_no_page_interactions): | 9 def __init__(self, url, page_set, run_no_page_interactions): |
| 10 """ Base class for all polymer pages. | 10 """ Base class for all polymer pages. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 super(PolymerCalculatorPage, self).__init__( | 46 super(PolymerCalculatorPage, self).__init__( |
| 47 url=('http://www.polymer-project.org/components/paper-calculator/' | 47 url=('http://www.polymer-project.org/components/paper-calculator/' |
| 48 'demo.html'), | 48 'demo.html'), |
| 49 page_set=page_set, run_no_page_interactions=run_no_page_interactions) | 49 page_set=page_set, run_no_page_interactions=run_no_page_interactions) |
| 50 | 50 |
| 51 def PerformPageInteractions(self, action_runner): | 51 def PerformPageInteractions(self, action_runner): |
| 52 self.TapButton(action_runner) | 52 self.TapButton(action_runner) |
| 53 self.SlidePanel(action_runner) | 53 self.SlidePanel(action_runner) |
| 54 | 54 |
| 55 def TapButton(self, action_runner): | 55 def TapButton(self, action_runner): |
| 56 interaction = action_runner.BeginInteraction( | 56 with action_runner.CreateInteraction('Action_TapAction'): |
| 57 'Action_TapAction') | 57 action_runner.TapElement(element_function=''' |
| 58 action_runner.TapElement(element_function=''' | 58 document.querySelector( |
| 59 document.querySelector( | 59 'body /deep/ #outerPanels' |
| 60 'body /deep/ #outerPanels' | 60 ).querySelector( |
| 61 ).querySelector( | 61 '#standard' |
| 62 '#standard' | 62 ).shadowRoot.querySelector( |
| 63 ).shadowRoot.querySelector( | 63 'paper-calculator-key[label="5"]' |
| 64 'paper-calculator-key[label="5"]' | 64 )''') |
| 65 )''') | 65 action_runner.Wait(2) |
| 66 action_runner.Wait(2) | |
| 67 interaction.End() | |
| 68 | 66 |
| 69 def SlidePanel(self, action_runner): | 67 def SlidePanel(self, action_runner): |
| 70 # only bother with this interaction if the drawer is hidden | 68 # only bother with this interaction if the drawer is hidden |
| 71 opened = action_runner.EvaluateJavaScript(''' | 69 opened = action_runner.EvaluateJavaScript(''' |
| 72 (function() { | 70 (function() { |
| 73 var outer = document.querySelector("body /deep/ #outerPanels"); | 71 var outer = document.querySelector("body /deep/ #outerPanels"); |
| 74 return outer.opened || outer.wideMode; | 72 return outer.opened || outer.wideMode; |
| 75 }());''') | 73 }());''') |
| 76 if not opened: | 74 if not opened: |
| 77 interaction = action_runner.BeginInteraction( | 75 with action_runner.CreateInteraction('Action_SwipeAction'): |
| 78 'Action_SwipeAction') | 76 action_runner.SwipeElement( |
| 79 action_runner.SwipeElement( | 77 left_start_ratio=0.1, top_start_ratio=0.2, |
| 80 left_start_ratio=0.1, top_start_ratio=0.2, | 78 direction='left', distance=300, speed_in_pixels_per_second=5000, |
| 81 direction='left', distance=300, speed_in_pixels_per_second=5000, | 79 element_function=''' |
| 82 element_function=''' | 80 document.querySelector( |
| 83 document.querySelector( | 81 'body /deep/ #outerPanels' |
| 84 'body /deep/ #outerPanels' | 82 ).querySelector( |
| 85 ).querySelector( | 83 '#advanced' |
| 86 '#advanced' | 84 ).shadowRoot.querySelector( |
| 87 ).shadowRoot.querySelector( | 85 '.handle-bar' |
| 88 '.handle-bar' | 86 )''') |
| 89 )''') | 87 action_runner.WaitForJavaScriptCondition(''' |
| 90 action_runner.WaitForJavaScriptCondition(''' | 88 var outer = document.querySelector("body /deep/ #outerPanels"); |
| 91 var outer = document.querySelector("body /deep/ #outerPanels"); | 89 outer.opened || outer.wideMode;''') |
| 92 outer.opened || outer.wideMode;''') | |
| 93 interaction.End() | |
| 94 | 90 |
| 95 | 91 |
| 96 class PolymerShadowPage(PolymerPage): | 92 class PolymerShadowPage(PolymerPage): |
| 97 | 93 |
| 98 def __init__(self, page_set, run_no_page_interactions): | 94 def __init__(self, page_set, run_no_page_interactions): |
| 99 super(PolymerShadowPage, self).__init__( | 95 super(PolymerShadowPage, self).__init__( |
| 100 url='http://www.polymer-project.org/components/paper-shadow/demo.html', | 96 url='http://www.polymer-project.org/components/paper-shadow/demo.html', |
| 101 page_set=page_set, run_no_page_interactions=run_no_page_interactions) | 97 page_set=page_set, run_no_page_interactions=run_no_page_interactions) |
| 102 | 98 |
| 103 def PerformPageInteractions(self, action_runner): | 99 def PerformPageInteractions(self, action_runner): |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 def PerformPageInteractions(self, action_runner): | 147 def PerformPageInteractions(self, action_runner): |
| 152 #TODO(wiltzius) Add interactions for input elements and shadow pages | 148 #TODO(wiltzius) Add interactions for input elements and shadow pages |
| 153 if self.scrolling_page: | 149 if self.scrolling_page: |
| 154 # Only bother scrolling the page if its been marked as worthwhile | 150 # Only bother scrolling the page if its been marked as worthwhile |
| 155 self.ScrollContentPane(action_runner) | 151 self.ScrollContentPane(action_runner) |
| 156 self.TouchEverything(action_runner) | 152 self.TouchEverything(action_runner) |
| 157 | 153 |
| 158 def ScrollContentPane(self, action_runner): | 154 def ScrollContentPane(self, action_runner): |
| 159 element_function = (self.iframe_js + '.querySelector(' | 155 element_function = (self.iframe_js + '.querySelector(' |
| 160 '"core-scroll-header-panel").$.mainContainer') | 156 '"core-scroll-header-panel").$.mainContainer') |
| 161 interaction = action_runner.BeginInteraction('Scroll_Page') | 157 with action_runner.CreateInteraction('Scroll_Page'): |
| 162 action_runner.ScrollElement(use_touch=True, | 158 action_runner.ScrollElement(use_touch=True, |
| 163 direction='down', | 159 direction='down', |
| 164 distance='900', | 160 distance='900', |
| 165 element_function=element_function) | 161 element_function=element_function) |
| 166 interaction.End() | 162 with action_runner.CreateInteraction('Scroll_Page'): |
| 167 interaction = action_runner.BeginInteraction('Scroll_Page') | 163 action_runner.ScrollElement(use_touch=True, |
| 168 action_runner.ScrollElement(use_touch=True, | 164 direction='up', |
| 169 direction='up', | 165 distance='900', |
| 170 distance='900', | 166 element_function=element_function) |
| 171 element_function=element_function) | |
| 172 interaction.End() | |
| 173 | 167 |
| 174 def TouchEverything(self, action_runner): | 168 def TouchEverything(self, action_runner): |
| 175 tappable_types = [ | 169 tappable_types = [ |
| 176 'paper-button', | 170 'paper-button', |
| 177 'paper-checkbox', | 171 'paper-checkbox', |
| 178 'paper-fab', | 172 'paper-fab', |
| 179 'paper-icon-button', | 173 'paper-icon-button', |
| 180 # crbug.com/394756 | 174 # crbug.com/394756 |
| 181 # 'paper-radio-button', | 175 # 'paper-radio-button', |
| 182 'paper-tab', | 176 'paper-tab', |
| (...skipping 16 matching lines...) Expand all Loading... |
| 199 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): | 193 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): |
| 200 element_query = element_list_query + ("[%d]" % i) | 194 element_query = element_list_query + ("[%d]" % i) |
| 201 if action_runner.EvaluateJavaScript( | 195 if action_runner.EvaluateJavaScript( |
| 202 element_query + '.offsetParent != null'): | 196 element_query + '.offsetParent != null'): |
| 203 # Only try to tap on visible elements (offsetParent != null) | 197 # Only try to tap on visible elements (offsetParent != null) |
| 204 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') | 198 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') |
| 205 action_runner.Wait(1) # wait for page to settle after scrolling | 199 action_runner.Wait(1) # wait for page to settle after scrolling |
| 206 action_function(action_runner, element_query) | 200 action_function(action_runner, element_query) |
| 207 | 201 |
| 208 def TapWidget(self, action_runner, element_function): | 202 def TapWidget(self, action_runner, element_function): |
| 209 interaction = action_runner.BeginInteraction( | 203 with action_runner.CreateInteraction('Tap_Widget'): |
| 210 'Tap_Widget') | 204 action_runner.TapElement(element_function=element_function) |
| 211 action_runner.TapElement(element_function=element_function) | 205 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 interaction.End() | |
| 214 | 206 |
| 215 def SwipeWidget(self, action_runner, element_function): | 207 def SwipeWidget(self, action_runner, element_function): |
| 216 interaction = action_runner.BeginInteraction( | 208 with action_runner.CreateInteraction('Swipe_Widget'): |
| 217 'Swipe_Widget') | 209 action_runner.SwipeElement(element_function=element_function, |
| 218 action_runner.SwipeElement(element_function=element_function, | 210 left_start_ratio=0.75, |
| 219 left_start_ratio=0.75, | 211 speed_in_pixels_per_second=300) |
| 220 speed_in_pixels_per_second=300) | |
| 221 interaction.End() | |
| 222 | 212 |
| 223 | 213 |
| 224 class PolymerPageSet(page_set_module.PageSet): | 214 class PolymerPageSet(page_set_module.PageSet): |
| 225 | 215 |
| 226 def __init__(self, run_no_page_interactions=False): | 216 def __init__(self, run_no_page_interactions=False): |
| 227 super(PolymerPageSet, self).__init__( | 217 super(PolymerPageSet, self).__init__( |
| 228 user_agent_type='mobile', | 218 user_agent_type='mobile', |
| 229 archive_data_file='data/polymer.json', | 219 archive_data_file='data/polymer.json', |
| 230 bucket=page_set_module.PUBLIC_BUCKET) | 220 bucket=page_set_module.PUBLIC_BUCKET) |
| 231 | 221 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 257 for p in SCROLLABLE_PAGES: | 247 for p in SCROLLABLE_PAGES: |
| 258 self.AddUserStory(PolymerSampler( | 248 self.AddUserStory(PolymerSampler( |
| 259 self, p, run_no_page_interactions=run_no_page_interactions, | 249 self, p, run_no_page_interactions=run_no_page_interactions, |
| 260 scrolling_page=True)) | 250 scrolling_page=True)) |
| 261 | 251 |
| 262 for page in self: | 252 for page in self: |
| 263 assert (page.__class__.RunPageInteractions == | 253 assert (page.__class__.RunPageInteractions == |
| 264 PolymerPage.RunPageInteractions), ( | 254 PolymerPage.RunPageInteractions), ( |
| 265 'Pages in this page set must not override PolymerPage\' ' | 255 'Pages in this page set must not override PolymerPage\' ' |
| 266 'RunPageInteractions method.') | 256 'RunPageInteractions method.') |
| OLD | NEW |