OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import time | 4 import time |
5 | 5 |
6 from telemetry.util import image_util | 6 from telemetry.util import image_util |
7 | 7 |
8 | 8 |
9 class InspectorPage(object): | 9 class InspectorPage(object): |
10 """Class that controls a page connected by an inspector_websocket. | 10 """Class that controls a page connected by an inspector_websocket. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 res = self._inspector_websocket.SyncRequest(request, timeout) | 132 res = self._inspector_websocket.SyncRequest(request, timeout) |
133 cookies = res['result']['cookies'] | 133 cookies = res['result']['cookies'] |
134 for cookie in cookies: | 134 for cookie in cookies: |
135 if cookie['name'] == name: | 135 if cookie['name'] == name: |
136 return cookie['value'] | 136 return cookie['value'] |
137 return None | 137 return None |
138 | 138 |
139 def CaptureScreenshot(self, timeout=60): | 139 def CaptureScreenshot(self, timeout=60): |
140 request = { | 140 request = { |
141 'method': 'Page.captureScreenshot', | 141 'method': 'Page.captureScreenshot', |
142 # TODO(rmistry): when Chrome is running in headless mode, this | 142 'params': { |
143 # will need to pass True. Telemetry needs to understand | 143 # TODO(rmistry): when Chrome is running in headless mode, this |
144 # whether the browser is in headless mode, and pass that | 144 # will need to pass True. Telemetry needs to understand |
145 # knowledge down to this method. | 145 # whether the browser is in headless mode, and pass that |
146 'fromSurface': False | 146 # knowledge down to this method. |
| 147 'fromSurface': False |
| 148 } |
147 } | 149 } |
148 # "Google API are missing..." infobar might cause a viewport resize | 150 # "Google API are missing..." infobar might cause a viewport resize |
149 # which invalidates screenshot request. See crbug.com/459820. | 151 # which invalidates screenshot request. See crbug.com/459820. |
150 for _ in range(2): | 152 for _ in range(2): |
151 res = self._inspector_websocket.SyncRequest(request, timeout) | 153 res = self._inspector_websocket.SyncRequest(request, timeout) |
152 if res and ('result' in res) and ('data' in res['result']): | 154 if res and ('result' in res) and ('data' in res['result']): |
153 return image_util.FromBase64Png(res['result']['data']) | 155 return image_util.FromBase64Png(res['result']['data']) |
154 return None | 156 return None |
155 | 157 |
156 def CollectGarbage(self, timeout=60): | 158 def CollectGarbage(self, timeout=60): |
157 request = { | 159 request = { |
158 'method': 'HeapProfiler.collectGarbage' | 160 'method': 'HeapProfiler.collectGarbage' |
159 } | 161 } |
160 res = self._inspector_websocket.SyncRequest(request, timeout) | 162 res = self._inspector_websocket.SyncRequest(request, timeout) |
161 assert 'result' in res | 163 assert 'result' in res |
OLD | NEW |