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 logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import socket | 10 import socket |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 Behavior is analogous to 'function(){ return <script> }();' | 320 Behavior is analogous to 'function(){ return <script> }();' |
| 321 | 321 |
| 322 Args: | 322 Args: |
| 323 script: A string of Javascript code. | 323 script: A string of Javascript code. |
| 324 timeout: Timeout for the Javascript code to return in seconds. | 324 timeout: Timeout for the Javascript code to return in seconds. |
| 325 Returns: | 325 Returns: |
| 326 A string of the verbatim output from the Javascript execution. | 326 A string of the verbatim output from the Javascript execution. |
| 327 """ | 327 """ |
| 328 return self.ExecuteJavascript("return " + script, timeout) | 328 return self.ExecuteJavascript("return " + script, timeout) |
| 329 | 329 |
| 330 def GetHistogram(self, histogram): | 330 def GetHistogram(self, histogram, timeout=30): |
|
tbansal1
2017/02/24 19:39:17
May be useful to add a comment that this is 30 sec
| |
| 331 js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram | 331 js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram |
| 332 string_response = self.ExecuteJavascriptStatement(js_query) | 332 string_response = self.ExecuteJavascriptStatement(js_query, timeout) |
| 333 self._logger.debug('Got %s histogram=%s', histogram, string_response) | 333 self._logger.debug('Got %s histogram=%s', histogram, string_response) |
| 334 return json.loads(string_response) | 334 return json.loads(string_response) |
| 335 | 335 |
| 336 def WaitForJavascriptExpression(self, expression, timeout, min_poll=0.1, | 336 def WaitForJavascriptExpression(self, expression, timeout, min_poll=0.1, |
| 337 max_poll=1): | 337 max_poll=1): |
| 338 """Waits for the given Javascript expression to evaluate to True within the | 338 """Waits for the given Javascript expression to evaluate to True within the |
| 339 given timeout. This method polls the Javascript expression within the range | 339 given timeout. This method polls the Javascript expression within the range |
| 340 of |min_poll| and |max_poll|. | 340 of |min_poll| and |max_poll|. |
| 341 | 341 |
| 342 Args: | 342 Args: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 for log in self._driver.execute('getLog', {'type': 'performance'})['value']: | 375 for log in self._driver.execute('getLog', {'type': 'performance'})['value']: |
| 376 message = json.loads(log['message'])['message'] | 376 message = json.loads(log['message'])['message'] |
| 377 self._logger.debug('Got Performance log: %s', log['message']) | 377 self._logger.debug('Got Performance log: %s', log['message']) |
| 378 if re.match(method_filter, message['method']): | 378 if re.match(method_filter, message['method']): |
| 379 all_messages.append(message) | 379 all_messages.append(message) |
| 380 self._logger.info('Got %d performance logs with filter method=%s', | 380 self._logger.info('Got %d performance logs with filter method=%s', |
| 381 len(all_messages), method_filter) | 381 len(all_messages), method_filter) |
| 382 self._has_logs = False | 382 self._has_logs = False |
| 383 return all_messages | 383 return all_messages |
| 384 | 384 |
| 385 def SleepUntilHistogramHasEntry(self, histogram_name, sleep_intervals=10): | |
| 386 """Polls if a histogram exists in 1-6 second intervals for 10 intervals. | |
| 387 Allows script to run with a timeout of 5 seconds, so the default behavior | |
| 388 allows up to 60 seconds until timeout. | |
| 389 | |
| 390 Args: | |
| 391 histogram_name: The name of the histogram to wait for | |
| 392 sleep_intervals: The number of polling intervals, each polling cycle takes | |
| 393 no more than 6 seconds. | |
| 394 Returns: | |
| 395 Whether the histogram exists | |
| 396 """ | |
| 397 histogram = {} | |
| 398 while(not histogram and sleep_intervals > 0): | |
| 399 histogram = self.GetHistogram(histogram_name, 5) | |
| 400 if (not histogram): | |
| 401 time.sleep(1) | |
| 402 sleep_intervals -= 1 | |
| 403 | |
| 404 return bool(histogram) | |
| 405 | |
| 385 def GetHTTPResponses(self, include_favicon=False, skip_domainless_pages=True): | 406 def GetHTTPResponses(self, include_favicon=False, skip_domainless_pages=True): |
| 386 """Parses the Performance Logs and returns a list of HTTPResponse objects. | 407 """Parses the Performance Logs and returns a list of HTTPResponse objects. |
| 387 | 408 |
| 388 Use caution when calling this function multiple times. Only responses | 409 Use caution when calling this function multiple times. Only responses |
| 389 since the last time this function was called are returned (or since Chrome | 410 since the last time this function was called are returned (or since Chrome |
| 390 started, whichever is later). An Exception will be raised if no page was | 411 started, whichever is later). An Exception will be raised if no page was |
| 391 loaded since the last time this function was called. | 412 loaded since the last time this function was called. |
| 392 | 413 |
| 393 Args: | 414 Args: |
| 394 include_favicon: A bool that if True will include responses for favicons. | 415 include_favicon: A bool that if True will include responses for favicons. |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 args[0].skipTest('This test runs on Mac OS only.') | 663 args[0].skipTest('This test runs on Mac OS only.') |
| 643 return wrapper | 664 return wrapper |
| 644 | 665 |
| 645 def NotMac(func): | 666 def NotMac(func): |
| 646 def wrapper(*args, **kwargs): | 667 def wrapper(*args, **kwargs): |
| 647 if sys.platform == 'darwin': | 668 if sys.platform == 'darwin': |
| 648 func(*args, **kwargs) | 669 func(*args, **kwargs) |
| 649 else: | 670 else: |
| 650 args[0].skipTest('This test does not run on Mac OS.') | 671 args[0].skipTest('This test does not run on Mac OS.') |
| 651 return wrapper | 672 return wrapper |
| OLD | NEW |