Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import socket | 9 import socket |
| 10 import shlex | 10 import shlex |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 given URL. | 212 given URL. |
| 213 | 213 |
| 214 Args: | 214 Args: |
| 215 timeout: Page load timeout in seconds. | 215 timeout: Page load timeout in seconds. |
| 216 """ | 216 """ |
| 217 if not self._driver: | 217 if not self._driver: |
| 218 self._StartDriver() | 218 self._StartDriver() |
| 219 self._driver.set_page_load_timeout(timeout) | 219 self._driver.set_page_load_timeout(timeout) |
| 220 self._driver.get(self._url) | 220 self._driver.get(self._url) |
| 221 | 221 |
| 222 def GetURL(self, url, timeout=30): | |
|
RyanSturm
2016/12/12 20:02:46
I'd prefer LoadURL. This seems a little backwards
Robert Ogden
2016/12/13 16:36:31
Done.
| |
| 223 """Convenience function for SetURL() followed by LoadPage() | |
| 224 Args: | |
| 225 url: the URL to navigate to | |
| 226 timeout: the time in seconds to load the page before timing out | |
| 227 """ | |
| 228 self.SetURL(url) | |
|
RyanSturm
2016/12/12 20:02:46
For now, forcing us to use GetURL with a param eve
Robert Ogden
2016/12/13 16:36:31
Acknowledged.
| |
| 229 self.LoadPage(timeout) | |
| 230 | |
| 222 def ExecuteJavascript(self, script, timeout=30): | 231 def ExecuteJavascript(self, script, timeout=30): |
| 223 """Executes the given javascript in the browser's current page in an | 232 """Executes the given javascript in the browser's current page in an |
| 224 anonymous function. | 233 anonymous function. |
| 225 | 234 |
| 226 If you expect a result and don't get one, try adding a return statement or | 235 If you expect a result and don't get one, try adding a return statement or |
| 227 using ExecuteJavascriptStatement() below. | 236 using ExecuteJavascriptStatement() below. |
| 228 | 237 |
| 229 Args: | 238 Args: |
| 230 script: A string of Javascript code. | 239 script: A string of Javascript code. |
| 231 timeout: Timeout for the Javascript code to return in seconds. | 240 timeout: Timeout for the Javascript code to return in seconds. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 253 Returns: | 262 Returns: |
| 254 A string of the verbatim output from the Javascript execution. | 263 A string of the verbatim output from the Javascript execution. |
| 255 """ | 264 """ |
| 256 return self.ExecuteJavascript("return " + script, timeout) | 265 return self.ExecuteJavascript("return " + script, timeout) |
| 257 | 266 |
| 258 def GetHistogram(self, histogram): | 267 def GetHistogram(self, histogram): |
| 259 js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram | 268 js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram |
| 260 string_response = self.ExecuteJavascriptStatement(js_query) | 269 string_response = self.ExecuteJavascriptStatement(js_query) |
| 261 return json.loads(string_response) | 270 return json.loads(string_response) |
| 262 | 271 |
| 272 def WaitForJavascriptExpression(self, expression, timeout, min_poll=0.1, | |
| 273 max_poll=1): | |
| 274 """Waits for the given Javascript expression to evaluate to True within the | |
| 275 given timeout. This method polls the Javascript expression within the range | |
| 276 of min_poll and max_poll. | |
| 277 | |
| 278 Args: | |
| 279 expression: The Javascript expression to poll, as a string | |
| 280 min_poll: The most frequently to poll as a float | |
| 281 max_poll: The least frequently to poll as a float | |
| 282 Returns: the result of the expression | |
| 283 """ | |
| 284 poll_interval = max(min(max_poll, float(timeout) / 10.0), min_poll) | |
| 285 result = self.ExecuteJavascriptStatement(expression) | |
| 286 total_waited_time = 0 | |
| 287 while not result and total_waited_time < timeout: | |
| 288 time.sleep(poll_interval) | |
| 289 total_waited_time += poll_interval | |
| 290 result = self.ExecuteJavascriptStatement(expression) | |
| 291 if not result: | |
| 292 raise Exception('%s not true after %f seconds' % (expression, timeout)) | |
| 293 return result | |
| 294 | |
| 263 def GetPerformanceLogs(self, method_filter=r'Network\.responseReceived'): | 295 def GetPerformanceLogs(self, method_filter=r'Network\.responseReceived'): |
| 264 """Returns all logged Performance events from Chrome. | 296 """Returns all logged Performance events from Chrome. |
| 265 | 297 |
| 266 Args: | 298 Args: |
| 267 method_filter: A regex expression to match the method of logged events | 299 method_filter: A regex expression to match the method of logged events |
| 268 against. Only logs who's method matches the regex will be returned. | 300 against. Only logs who's method matches the regex will be returned. |
| 269 Returns: | 301 Returns: |
| 270 Performance logs as a list of dicts, since the last time this function was | 302 Performance logs as a list of dicts, since the last time this function was |
| 271 called. | 303 called. |
| 272 """ | 304 """ |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 @property | 393 @property |
| 362 def request_type(self): | 394 def request_type(self): |
| 363 return self._request_type | 395 return self._request_type |
| 364 | 396 |
| 365 def ResponseHasViaHeader(self): | 397 def ResponseHasViaHeader(self): |
| 366 return 'via' in self._response_headers and (self._response_headers['via'] == | 398 return 'via' in self._response_headers and (self._response_headers['via'] == |
| 367 self._flags.via_header_value) | 399 self._flags.via_header_value) |
| 368 | 400 |
| 369 def WasXHR(self): | 401 def WasXHR(self): |
| 370 return self.request_type == 'XHR' | 402 return self.request_type == 'XHR' |
| OLD | NEW |