Chromium Code Reviews| Index: tools/chrome_proxy/webdriver/common.py |
| diff --git a/tools/chrome_proxy/webdriver/common.py b/tools/chrome_proxy/webdriver/common.py |
| index 2572a64a9253049576e6d5b6364a950ce18c46c3..63ec5b39dbf0c4964b6c66df8be50b301a001eaa 100644 |
| --- a/tools/chrome_proxy/webdriver/common.py |
| +++ b/tools/chrome_proxy/webdriver/common.py |
| @@ -327,9 +327,9 @@ class TestDriver: |
| """ |
| return self.ExecuteJavascript("return " + script, timeout) |
| - def GetHistogram(self, histogram): |
| + 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
|
| js_query = 'statsCollectionController.getBrowserHistogram("%s")' % histogram |
| - string_response = self.ExecuteJavascriptStatement(js_query) |
| + string_response = self.ExecuteJavascriptStatement(js_query, timeout) |
| self._logger.debug('Got %s histogram=%s', histogram, string_response) |
| return json.loads(string_response) |
| @@ -382,6 +382,27 @@ class TestDriver: |
| self._has_logs = False |
| return all_messages |
| + def SleepUntilHistogramHasEntry(self, histogram_name, sleep_intervals=10): |
| + """Polls if a histogram exists in 1-6 second intervals for 10 intervals. |
| + Allows script to run with a timeout of 5 seconds, so the default behavior |
| + allows up to 60 seconds until timeout. |
| + |
| + Args: |
| + histogram_name: The name of the histogram to wait for |
| + sleep_intervals: The number of polling intervals, each polling cycle takes |
| + no more than 6 seconds. |
| + Returns: |
| + Whether the histogram exists |
| + """ |
| + histogram = {} |
| + while(not histogram and sleep_intervals > 0): |
| + histogram = self.GetHistogram(histogram_name, 5) |
| + if (not histogram): |
| + time.sleep(1) |
| + sleep_intervals -= 1 |
| + |
| + return bool(histogram) |
| + |
| def GetHTTPResponses(self, include_favicon=False, skip_domainless_pages=True): |
| """Parses the Performance Logs and returns a list of HTTPResponse objects. |