Index: tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py |
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py |
index 68ba33fa311af9bf05d99f082f3cadc31ed68379..a1b79700fff4a632c13031442d1ad1b0f39f62bc 100644 |
--- a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py |
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py |
@@ -78,15 +78,19 @@ class ChromeProxyResponse(network_metrics.HTTPResponse): |
return kvp[1].strip() |
return None |
- def HasChromeProxyLoFi(self): |
+ def HasChromeProxyLoFiRequest(self): |
if 'Chrome-Proxy' not in self.response.request_headers: |
return False |
chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] |
values = [v.strip() for v in chrome_proxy_request_header.split(',')] |
- for value in values: |
- if len(value) == 5 and value == 'q=low': |
- return True |
- return False |
+ return any(v == "q=low" for v in values) |
+ |
+ def HasChromeProxyLoFiResponse(self): |
+ chrome_proxy_response_header = self.response.GetHeader('Chrome-Proxy') |
+ if not chrome_proxy_response_header: |
+ return False |
+ values = [v.strip() for v in chrome_proxy_response_header.split(',')] |
+ return any(v == "q=low" for v in values) |
class ChromeProxyMetric(network_metrics.NetworkMetric): |
"""A Chrome proxy timeline metric.""" |
@@ -301,27 +305,40 @@ class ChromeProxyMetric(network_metrics.NetworkMetric): |
results.current_page, 'bypass', 'count', bypass_count)) |
def AddResultsForLoFi(self, tab, results): |
- lo_fi_count = 0 |
+ lo_fi_request_count = 0 |
+ lo_fi_response_count = 0 |
for resp in self.IterResponses(tab): |
- if resp.HasChromeProxyLoFi(): |
- lo_fi_count += 1 |
+ if resp.HasChromeProxyLoFiRequest(): |
+ lo_fi_request_count += 1 |
else: |
raise ChromeProxyMetricException, ( |
'%s: LoFi not in request header.' % (resp.response.url)) |
+ if resp.HasChromeProxyLoFiResponse(): |
+ lo_fi_response_count += 1 |
+ else: |
+ raise ChromeProxyMetricException, ( |
+ '%s: LoFi not in response header.' % (resp.response.url)) |
+ |
if resp.content_length > 100: |
raise ChromeProxyMetricException, ( |
'Image %s is %d bytes. Expecting less than 100 bytes.' % |
(resp.response.url, resp.content_length)) |
- if lo_fi_count == 0: |
+ if lo_fi_request_count == 0: |
+ raise ChromeProxyMetricException, ( |
+ 'Expected at least one LoFi request, but zero such requests were ' |
+ 'received.') |
sclittle
2015/05/14 22:03:25
nit: wording seems a bit strange, "requests were r
megjablon
2015/05/15 00:38:10
Ah ya forgot to fix that part. Done.
|
+ if lo_fi_response_count == 0: |
raise ChromeProxyMetricException, ( |
'Expected at least one LoFi response, but zero such responses were ' |
'received.') |
results.AddValue(scalar.ScalarValue( |
- results.current_page, 'lo_fi', 'count', lo_fi_count)) |
+ results.current_page, 'lo_fi_request', 'count', lo_fi_request_count)) |
+ results.AddValue(scalar.ScalarValue( |
+ results.current_page, 'lo_fi_response', 'count', lo_fi_response_count)) |
super(ChromeProxyMetric, self).AddResults(tab, results) |
def AddResultsForBypass(self, tab, results): |