| OLD | NEW |
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 | 4 |
| 5 from telemetry.internal.actions import action_runner | 5 from telemetry.internal.actions import action_runner |
| 6 from telemetry.internal.browser import web_contents | 6 from telemetry.internal.browser import web_contents |
| 7 from telemetry.internal.image_processing import video | 7 from telemetry.internal.image_processing import video |
| 8 | 8 |
| 9 DEFAULT_TAB_TIMEOUT = 60 | 9 DEFAULT_TAB_TIMEOUT = 60 |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 TODO(tonyg): It is possible that the z-index hack here might not work for | 127 TODO(tonyg): It is possible that the z-index hack here might not work for |
| 128 all pages. If this happens, DevTools also provides a method for this. | 128 all pages. If this happens, DevTools also provides a method for this. |
| 129 | 129 |
| 130 Raises: | 130 Raises: |
| 131 exceptions.EvaluateException | 131 exceptions.EvaluateException |
| 132 exceptions.WebSocketDisconnected | 132 exceptions.WebSocketDisconnected |
| 133 exceptions.TimeoutException | 133 exceptions.TimeoutException |
| 134 exceptions.DevtoolsTargetCrashException | 134 exceptions.DevtoolsTargetCrashException |
| 135 """ | 135 """ |
| 136 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 136 screen_save = 'window.__telemetry_screen_%d' % int(color) |
| 137 self.ExecuteJavaScript(""" | 137 self.ExecuteJavaScript2(""" |
| 138 (function() { | 138 (function() { |
| 139 var screen = document.createElement('div'); | 139 var screen = document.createElement('div'); |
| 140 screen.style.background = 'rgba(%d, %d, %d, %d)'; | 140 screen.style.background = {{ color }}; |
| 141 screen.style.position = 'fixed'; | 141 screen.style.position = 'fixed'; |
| 142 screen.style.top = '0'; | 142 screen.style.top = '0'; |
| 143 screen.style.left = '0'; | 143 screen.style.left = '0'; |
| 144 screen.style.width = '100%%'; | 144 screen.style.width = '100%'; |
| 145 screen.style.height = '100%%'; | 145 screen.style.height = '100%'; |
| 146 screen.style.zIndex = '2147483638'; | 146 screen.style.zIndex = '2147483638'; |
| 147 document.body.appendChild(screen); | 147 document.body.appendChild(screen); |
| 148 requestAnimationFrame(function() { | |
| 149 requestAnimationFrame(function() { | 148 requestAnimationFrame(function() { |
| 150 window.__telemetry_screen_%d = screen; | 149 requestAnimationFrame(function() { |
| 150 {{ @screen_save }} = screen; |
| 151 }); |
| 151 }); | 152 }); |
| 152 }); | 153 })(); |
| 153 })(); | 154 """, |
| 154 """ % (color.r, color.g, color.b, color.a, int(color))) | 155 color='rgba(%d, %d, %d, %d)' % (color.r, color.g, color.b, color.a), |
| 155 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 156 screen_save=screen_save) |
| 156 self.WaitForJavaScriptExpression( | 157 self.WaitForJavaScriptCondition2( |
| 157 '!!window.__telemetry_screen_%d' % int(color), 5) | 158 '!!{{ @screen_save }}', screen_save=screen_save, timeout=5) |
| 158 | 159 |
| 159 def ClearHighlight(self, color): | 160 def ClearHighlight(self, color): |
| 160 """Clears a highlight of the given bitmap.RgbaColor. | 161 """Clears a highlight of the given bitmap.RgbaColor. |
| 161 | 162 |
| 162 Raises: | 163 Raises: |
| 163 exceptions.EvaluateException | 164 exceptions.EvaluateException |
| 164 exceptions.WebSocketDisconnected | 165 exceptions.WebSocketDisconnected |
| 165 exceptions.TimeoutException | 166 exceptions.TimeoutException |
| 166 exceptions.DevtoolsTargetCrashException | 167 exceptions.DevtoolsTargetCrashException |
| 167 """ | 168 """ |
| 168 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 169 screen_save = 'window.__telemetry_screen_%d' % int(color) |
| 169 self.ExecuteJavaScript(""" | 170 self.ExecuteJavaScript2(""" |
| 170 (function() { | 171 (function() { |
| 171 document.body.removeChild(window.__telemetry_screen_%d); | 172 document.body.removeChild({{ @screen_save }}); |
| 172 requestAnimationFrame(function() { | |
| 173 requestAnimationFrame(function() { | 173 requestAnimationFrame(function() { |
| 174 window.__telemetry_screen_%d = null; | 174 requestAnimationFrame(function() { |
| 175 console.time('__ClearHighlight.video_capture_start'); | 175 {{ @screen_save }} = null; |
| 176 console.timeEnd('__ClearHighlight.video_capture_start'); | 176 console.time('__ClearHighlight.video_capture_start'); |
| 177 console.timeEnd('__ClearHighlight.video_capture_start'); |
| 178 }); |
| 177 }); | 179 }); |
| 178 }); | 180 })(); |
| 179 })(); | 181 """, screen_save=screen_save) |
| 180 """ % (int(color), int(color))) | 182 self.WaitForJavaScriptCondition2( |
| 181 # TODO(catapult:#3028): Fix interpolation of JavaScript values. | 183 '!{{ @screen_save }}', screen_save=screen_save, timeout=5) |
| 182 self.WaitForJavaScriptExpression( | |
| 183 '!window.__telemetry_screen_%d' % int(color), 5) | |
| 184 | 184 |
| 185 def StartVideoCapture(self, min_bitrate_mbps, | 185 def StartVideoCapture(self, min_bitrate_mbps, |
| 186 highlight_bitmap=video.HIGHLIGHT_ORANGE_FRAME): | 186 highlight_bitmap=video.HIGHLIGHT_ORANGE_FRAME): |
| 187 """Starts capturing video of the tab's contents. | 187 """Starts capturing video of the tab's contents. |
| 188 | 188 |
| 189 This works by flashing the entire tab contents to a arbitrary color and then | 189 This works by flashing the entire tab contents to a arbitrary color and then |
| 190 starting video recording. When the frames are processed, we can look for | 190 starting video recording. When the frames are processed, we can look for |
| 191 that flash as the content bounds. | 191 that flash as the content bounds. |
| 192 | 192 |
| 193 Args: | 193 Args: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 cleared. | 250 cleared. |
| 251 | 251 |
| 252 Raises: | 252 Raises: |
| 253 exceptions.EvaluateException | 253 exceptions.EvaluateException |
| 254 exceptions.WebSocketDisconnected | 254 exceptions.WebSocketDisconnected |
| 255 exceptions.TimeoutException | 255 exceptions.TimeoutException |
| 256 exceptions.DevtoolsTargetCrashException | 256 exceptions.DevtoolsTargetCrashException |
| 257 errors.DeviceUnresponsiveError | 257 errors.DeviceUnresponsiveError |
| 258 """ | 258 """ |
| 259 self.browser.platform.FlushDnsCache() | 259 self.browser.platform.FlushDnsCache() |
| 260 self.ExecuteJavaScript(""" | 260 self.ExecuteJavaScript2(""" |
| 261 if (window.chrome && chrome.benchmarking && | 261 if (window.chrome && chrome.benchmarking && |
| 262 chrome.benchmarking.clearCache) { | 262 chrome.benchmarking.clearCache) { |
| 263 chrome.benchmarking.clearCache(); | 263 chrome.benchmarking.clearCache(); |
| 264 chrome.benchmarking.clearPredictorCache(); | 264 chrome.benchmarking.clearPredictorCache(); |
| 265 chrome.benchmarking.clearHostResolverCache(); | 265 chrome.benchmarking.clearHostResolverCache(); |
| 266 } | 266 } |
| 267 """) | 267 """) |
| 268 if force: | 268 if force: |
| 269 self.Navigate('about:blank') | 269 self.Navigate('about:blank') |
| OLD | NEW |