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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
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 |
| 143 # will need to pass True. Telemetry needs to understand |
| 144 # whether the browser is in headless mode, and pass that |
| 145 # knowledge down to this method. |
| 146 'fromSurface': False |
142 } | 147 } |
143 # "Google API are missing..." infobar might cause a viewport resize | 148 # "Google API are missing..." infobar might cause a viewport resize |
144 # which invalidates screenshot request. See crbug.com/459820. | 149 # which invalidates screenshot request. See crbug.com/459820. |
145 for _ in range(2): | 150 for _ in range(2): |
146 res = self._inspector_websocket.SyncRequest(request, timeout) | 151 res = self._inspector_websocket.SyncRequest(request, timeout) |
147 if res and ('result' in res) and ('data' in res['result']): | 152 if res and ('result' in res) and ('data' in res['result']): |
148 return image_util.FromBase64Png(res['result']['data']) | 153 return image_util.FromBase64Png(res['result']['data']) |
149 return None | 154 return None |
150 | 155 |
151 def CollectGarbage(self, timeout=60): | 156 def CollectGarbage(self, timeout=60): |
152 request = { | 157 request = { |
153 'method': 'HeapProfiler.collectGarbage' | 158 'method': 'HeapProfiler.collectGarbage' |
154 } | 159 } |
155 res = self._inspector_websocket.SyncRequest(request, timeout) | 160 res = self._inspector_websocket.SyncRequest(request, timeout) |
156 assert 'result' in res | 161 assert 'result' in res |
OLD | NEW |