| 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): | 9 def __init__(self, url, page_set): |
| 10 super(PolymerPage, self).__init__( | 10 super(PolymerPage, self).__init__( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 def __init__(self, page_set): | 73 def __init__(self, page_set): |
| 74 super(PolymerShadowPage, self).__init__( | 74 super(PolymerShadowPage, self).__init__( |
| 75 url='http://www.polymer-project.org/components/paper-shadow/demo.html', | 75 url='http://www.polymer-project.org/components/paper-shadow/demo.html', |
| 76 page_set=page_set) | 76 page_set=page_set) |
| 77 | 77 |
| 78 def RunSmoothness(self, action_runner): | 78 def RunSmoothness(self, action_runner): |
| 79 action_runner.ExecuteJavaScript( | 79 action_runner.ExecuteJavaScript( |
| 80 "document.getElementById('fab').scrollIntoView()") | 80 "document.getElementById('fab').scrollIntoView()") |
| 81 action_runner.Wait(5) | 81 action_runner.Wait(5) |
| 82 self.AnimateShadow(action_runner, 'card') | 82 self.AnimateShadow(action_runner, 'card') |
| 83 self.AnimateShadow(action_runner, 'fab') | 83 #FIXME(wiltzius) disabling until this issue is fixed: |
| 84 # https://github.com/Polymer/paper-shadow/issues/12 |
| 85 #self.AnimateShadow(action_runner, 'fab') |
| 84 | 86 |
| 85 def AnimateShadow(self, action_runner, eid): | 87 def AnimateShadow(self, action_runner, eid): |
| 86 for i in range(1, 6): | 88 for i in range(1, 6): |
| 87 action_runner.ExecuteJavaScript( | 89 action_runner.ExecuteJavaScript( |
| 88 'document.getElementById("{0}").z = {1}'.format(eid, i)) | 90 'document.getElementById("{0}").z = {1}'.format(eid, i)) |
| 89 action_runner.Wait(1) | 91 action_runner.Wait(1) |
| 90 | 92 |
| 91 | 93 |
| 92 class PolymerSampler(PolymerPage): | 94 class PolymerSampler(PolymerPage): |
| 93 | 95 |
| 94 def __init__(self, page_set, anchor, scrolling_page=False): | 96 def __init__(self, page_set, anchor, scrolling_page=False): |
| 95 """Page exercising interactions with a single Paper Sampler subpage. | 97 """Page exercising interactions with a single Paper Sampler subpage. |
| 96 | 98 |
| 97 Args: | 99 Args: |
| 98 page_set: Page set to inforporate this page into. | 100 page_set: Page set to inforporate this page into. |
| 99 anchor: string indicating which subpage to load (matches the element | 101 anchor: string indicating which subpage to load (matches the element |
| 100 type that page is displaying) | 102 type that page is displaying) |
| 101 scrolling_page: Whether scrolling the content pane is relevant to this | 103 scrolling_page: Whether scrolling the content pane is relevant to this |
| 102 content page or not. | 104 content page or not. |
| 103 """ | 105 """ |
| 104 super(PolymerSampler, self).__init__( | 106 super(PolymerSampler, self).__init__( |
| 105 url=('http://www.polymer-project.org/components/paper-elements/demo.html#' | 107 url=('http://www.polymer-project.org/components/%s/demo.html' % anchor), |
| 106 + anchor), | |
| 107 page_set=page_set) | 108 page_set=page_set) |
| 108 self.scrolling_page = scrolling_page | 109 self.scrolling_page = scrolling_page |
| 109 self.iframe_js = 'document.querySelector("sampler-scaffold").$.frame' | 110 self.iframe_js = 'document' |
| 110 | 111 |
| 111 def RunNavigateSteps(self, action_runner): | 112 def RunNavigateSteps(self, action_runner): |
| 112 #FIXME(wiltzius) workaround for crbug.com/391672 | |
| 113 action_runner.ExecuteJavaScript('window.location.href="about:blank";') | |
| 114 super(PolymerSampler, self).RunNavigateSteps(action_runner) | 113 super(PolymerSampler, self).RunNavigateSteps(action_runner) |
| 115 waitForLoadJS = """ | 114 waitForLoadJS = """ |
| 116 window.Polymer.whenPolymerReady(function() { | 115 window.Polymer.whenPolymerReady(function() { |
| 117 %s.contentWindow.Polymer.whenPolymerReady(function() { | 116 %s.contentWindow.Polymer.whenPolymerReady(function() { |
| 118 window.__polymer_ready = true; | 117 window.__polymer_ready = true; |
| 119 }) | 118 }) |
| 120 }); | 119 }); |
| 121 """ % self.iframe_js | 120 """ % self.iframe_js |
| 122 action_runner.ExecuteJavaScript(waitForLoadJS) | 121 action_runner.ExecuteJavaScript(waitForLoadJS) |
| 123 action_runner.WaitForJavaScriptCondition( | 122 action_runner.WaitForJavaScriptCondition( |
| 124 'window.__polymer_ready') | 123 'window.__polymer_ready') |
| 125 | 124 |
| 126 def RunSmoothness(self, action_runner): | 125 def RunSmoothness(self, action_runner): |
| 127 #TODO(wiltzius) Add interactions for input elements and shadow pages | 126 #TODO(wiltzius) Add interactions for input elements and shadow pages |
| 128 if self.scrolling_page: | 127 if self.scrolling_page: |
| 129 # Only bother scrolling the page if its been marked as worthwhile | 128 # Only bother scrolling the page if its been marked as worthwhile |
| 130 self.ScrollContentPane(action_runner) | 129 self.ScrollContentPane(action_runner) |
| 131 self.TouchEverything(action_runner) | 130 self.TouchEverything(action_runner) |
| 132 | 131 |
| 133 def ScrollContentPane(self, action_runner): | 132 def ScrollContentPane(self, action_runner): |
| 134 element_function = (self.iframe_js + '.contentDocument.querySelector(' | 133 element_function = (self.iframe_js + '.querySelector(' |
| 135 '"core-scroll-header-panel").$.mainContainer') | 134 '"core-scroll-header-panel").$.mainContainer') |
| 136 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) | 135 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) |
| 137 action_runner.ScrollElement(use_touch=True, | 136 action_runner.ScrollElement(use_touch=True, |
| 138 direction='down', | 137 direction='down', |
| 139 distance='900', | 138 distance='900', |
| 140 element_function=element_function) | 139 element_function=element_function) |
| 141 interaction.End() | 140 interaction.End() |
| 142 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) | 141 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) |
| 143 action_runner.ScrollElement(use_touch=True, | 142 action_runner.ScrollElement(use_touch=True, |
| 144 direction='up', | 143 direction='up', |
| (...skipping 16 matching lines...) Expand all Loading... |
| 161 for tappable_type in tappable_types: | 160 for tappable_type in tappable_types: |
| 162 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget) | 161 self.DoActionOnWidgetType(action_runner, tappable_type, self.TapWidget) |
| 163 swipeable_types = ['paper-slider'] | 162 swipeable_types = ['paper-slider'] |
| 164 for swipeable_type in swipeable_types: | 163 for swipeable_type in swipeable_types: |
| 165 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget) | 164 self.DoActionOnWidgetType(action_runner, swipeable_type, self.SwipeWidget) |
| 166 | 165 |
| 167 def DoActionOnWidgetType(self, action_runner, widget_type, action_function): | 166 def DoActionOnWidgetType(self, action_runner, widget_type, action_function): |
| 168 # Find all widgets of this type, but skip any that are disabled or are | 167 # Find all widgets of this type, but skip any that are disabled or are |
| 169 # currently active as they typically don't produce animation frames. | 168 # currently active as they typically don't produce animation frames. |
| 170 element_list_query = (self.iframe_js + | 169 element_list_query = (self.iframe_js + |
| 171 ('.contentDocument.querySelectorAll("body %s:not([disabled]):' | 170 ('.querySelectorAll("body %s:not([disabled]):' |
| 172 'not([active])")' % widget_type)) | 171 'not([active])")' % widget_type)) |
| 173 roles_count_query = element_list_query + '.length' | 172 roles_count_query = element_list_query + '.length' |
| 174 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): | 173 for i in range(action_runner.EvaluateJavaScript(roles_count_query)): |
| 175 element_query = element_list_query + ("[%d]" % i) | 174 element_query = element_list_query + ("[%d]" % i) |
| 176 if action_runner.EvaluateJavaScript( | 175 if action_runner.EvaluateJavaScript( |
| 177 element_query + '.offsetParent != null'): | 176 element_query + '.offsetParent != null'): |
| 178 # Only try to tap on visible elements (offsetParent != null) | 177 # Only try to tap on visible elements (offsetParent != null) |
| 179 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') | 178 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') |
| 180 action_runner.Wait(1) # wait for page to settle after scrolling | 179 action_runner.Wait(1) # wait for page to settle after scrolling |
| 181 action_function(action_runner, element_query) | 180 action_function(action_runner, element_query) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 208 self.AddPage(PolymerShadowPage(self)) | 207 self.AddPage(PolymerShadowPage(self)) |
| 209 | 208 |
| 210 # Polymer Sampler subpages that are interesting to tap / swipe elements on | 209 # Polymer Sampler subpages that are interesting to tap / swipe elements on |
| 211 TAPPABLE_PAGES = [ | 210 TAPPABLE_PAGES = [ |
| 212 'paper-button', | 211 'paper-button', |
| 213 'paper-checkbox', | 212 'paper-checkbox', |
| 214 'paper-fab', | 213 'paper-fab', |
| 215 'paper-icon-button', | 214 'paper-icon-button', |
| 216 # crbug.com/394756 | 215 # crbug.com/394756 |
| 217 # 'paper-radio-button', | 216 # 'paper-radio-button', |
| 218 'paper-shadow', | 217 #FIXME(wiltzius) Disabling x-shadow until this issue is fixed: |
| 218 # https://github.com/Polymer/paper-shadow/issues/12 |
| 219 #'paper-shadow', |
| 219 'paper-tabs', | 220 'paper-tabs', |
| 220 'paper-toggle-button', | 221 'paper-toggle-button', |
| 221 ] | 222 ] |
| 222 for p in TAPPABLE_PAGES: | 223 for p in TAPPABLE_PAGES: |
| 223 self.AddPage(PolymerSampler(self, p)) | 224 self.AddPage(PolymerSampler(self, p)) |
| 224 | 225 |
| 225 # Polymer Sampler subpages that are interesting to scroll | 226 # Polymer Sampler subpages that are interesting to scroll |
| 226 SCROLLABLE_PAGES = [ | 227 SCROLLABLE_PAGES = [ |
| 227 # crbug.com/394756 | 228 'core-scroll-header-panel', |
| 228 # 'core-scroll-header-panel', | |
| 229 ] | 229 ] |
| 230 for p in SCROLLABLE_PAGES: | 230 for p in SCROLLABLE_PAGES: |
| 231 self.AddPage(PolymerSampler(self, p, scrolling_page=True)) | 231 self.AddPage(PolymerSampler(self, p, scrolling_page=True)) |
| OLD | NEW |