OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 logging | 5 import logging |
6 import time | 6 import time |
7 | 7 |
8 from integration_tests import network_metrics | 8 from integration_tests import network_metrics |
9 from telemetry.page import page_test | 9 from telemetry.page import page_test |
10 from telemetry.value import scalar | 10 from telemetry.value import scalar |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 return None | 71 return None |
72 | 72 |
73 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] | 73 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] |
74 values = [v.strip() for v in chrome_proxy_request_header.split(',')] | 74 values = [v.strip() for v in chrome_proxy_request_header.split(',')] |
75 for value in values: | 75 for value in values: |
76 kvp = value.split('=', 1) | 76 kvp = value.split('=', 1) |
77 if len(kvp) == 2 and kvp[0].strip() == 'c': | 77 if len(kvp) == 2 and kvp[0].strip() == 'c': |
78 return kvp[1].strip() | 78 return kvp[1].strip() |
79 return None | 79 return None |
80 | 80 |
81 def HasChromeProxyLoFi(self): | 81 def HasChromeProxyLoFiRequest(self): |
82 if 'Chrome-Proxy' not in self.response.request_headers: | 82 if 'Chrome-Proxy' not in self.response.request_headers: |
83 return False | 83 return False |
84 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] | 84 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] |
85 values = [v.strip() for v in chrome_proxy_request_header.split(',')] | 85 values = [v.strip() for v in chrome_proxy_request_header.split(',')] |
86 for value in values: | 86 return any(v == "q=low" for v in values) |
87 if len(value) == 5 and value == 'q=low': | 87 |
88 return True | 88 def HasChromeProxyLoFiResponse(self): |
89 return False | 89 chrome_proxy_response_header = self.response.GetHeader('Chrome-Proxy') |
90 if not chrome_proxy_response_header: | |
91 return False | |
92 values = [v.strip() for v in chrome_proxy_response_header.split(',')] | |
93 return any(v == "q=low" for v in values) | |
90 | 94 |
91 class ChromeProxyMetric(network_metrics.NetworkMetric): | 95 class ChromeProxyMetric(network_metrics.NetworkMetric): |
92 """A Chrome proxy timeline metric.""" | 96 """A Chrome proxy timeline metric.""" |
93 | 97 |
94 def __init__(self): | 98 def __init__(self): |
95 super(ChromeProxyMetric, self).__init__() | 99 super(ChromeProxyMetric, self).__init__() |
96 self.compute_data_saving = True | 100 self.compute_data_saving = True |
97 | 101 |
98 def SetEvents(self, events): | 102 def SetEvents(self, events): |
99 """Used for unittest.""" | 103 """Used for unittest.""" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 raise ChromeProxyMetricException, ( | 298 raise ChromeProxyMetricException, ( |
295 'Expected at least one response that was eligible to be proxied, but ' | 299 'Expected at least one response that was eligible to be proxied, but ' |
296 'zero such responses were received.') | 300 'zero such responses were received.') |
297 | 301 |
298 results.AddValue(scalar.ScalarValue( | 302 results.AddValue(scalar.ScalarValue( |
299 results.current_page, 'via', 'count', via_count)) | 303 results.current_page, 'via', 'count', via_count)) |
300 results.AddValue(scalar.ScalarValue( | 304 results.AddValue(scalar.ScalarValue( |
301 results.current_page, 'bypass', 'count', bypass_count)) | 305 results.current_page, 'bypass', 'count', bypass_count)) |
302 | 306 |
303 def AddResultsForLoFi(self, tab, results): | 307 def AddResultsForLoFi(self, tab, results): |
304 lo_fi_count = 0 | 308 lo_fi_request_count = 0 |
309 lo_fi_response_count = 0 | |
305 | 310 |
306 for resp in self.IterResponses(tab): | 311 for resp in self.IterResponses(tab): |
307 if resp.HasChromeProxyLoFi(): | 312 if resp.HasChromeProxyLoFiRequest(): |
308 lo_fi_count += 1 | 313 lo_fi_request_count += 1 |
309 else: | 314 else: |
310 raise ChromeProxyMetricException, ( | 315 raise ChromeProxyMetricException, ( |
311 '%s: LoFi not in request header.' % (resp.response.url)) | 316 '%s: LoFi not in request header.' % (resp.response.url)) |
312 | 317 |
318 if resp.HasChromeProxyLoFiResponse(): | |
319 lo_fi_response_count += 1 | |
320 else: | |
321 raise ChromeProxyMetricException, ( | |
322 '%s: LoFi not in response header.' % (resp.response.url)) | |
323 | |
313 if resp.content_length > 100: | 324 if resp.content_length > 100: |
314 raise ChromeProxyMetricException, ( | 325 raise ChromeProxyMetricException, ( |
315 'Image %s is %d bytes. Expecting less than 100 bytes.' % | 326 'Image %s is %d bytes. Expecting less than 100 bytes.' % |
316 (resp.response.url, resp.content_length)) | 327 (resp.response.url, resp.content_length)) |
317 | 328 |
318 if lo_fi_count == 0: | 329 if lo_fi_request_count == 0: |
330 raise ChromeProxyMetricException, ( | |
331 'Expected at least one LoFi request, but zero such requests were ' | |
332 '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.
| |
333 if lo_fi_response_count == 0: | |
319 raise ChromeProxyMetricException, ( | 334 raise ChromeProxyMetricException, ( |
320 'Expected at least one LoFi response, but zero such responses were ' | 335 'Expected at least one LoFi response, but zero such responses were ' |
321 'received.') | 336 'received.') |
322 | 337 |
323 results.AddValue(scalar.ScalarValue( | 338 results.AddValue(scalar.ScalarValue( |
324 results.current_page, 'lo_fi', 'count', lo_fi_count)) | 339 results.current_page, 'lo_fi_request', 'count', lo_fi_request_count)) |
340 results.AddValue(scalar.ScalarValue( | |
341 results.current_page, 'lo_fi_response', 'count', lo_fi_response_count)) | |
325 super(ChromeProxyMetric, self).AddResults(tab, results) | 342 super(ChromeProxyMetric, self).AddResults(tab, results) |
326 | 343 |
327 def AddResultsForBypass(self, tab, results): | 344 def AddResultsForBypass(self, tab, results): |
328 bypass_count = 0 | 345 bypass_count = 0 |
329 | 346 |
330 for resp in self.IterResponses(tab): | 347 for resp in self.IterResponses(tab): |
331 if resp.HasChromeProxyViaHeader(): | 348 if resp.HasChromeProxyViaHeader(): |
332 r = resp.response | 349 r = resp.response |
333 raise ChromeProxyMetricException, ( | 350 raise ChromeProxyMetricException, ( |
334 '%s: Should not have Via header (%s) (refer=%s, status=%d)' % ( | 351 '%s: Should not have Via header (%s) (refer=%s, status=%d)' % ( |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 via_count += 1 | 590 via_count += 1 |
574 if via_count == 0: | 591 if via_count == 0: |
575 raise ChromeProxyMetricException, ( | 592 raise ChromeProxyMetricException, ( |
576 'Expected at least one response through the proxy after the bypass ' | 593 'Expected at least one response through the proxy after the bypass ' |
577 'expired, but zero such responses were received.') | 594 'expired, but zero such responses were received.') |
578 | 595 |
579 results.AddValue(scalar.ScalarValue( | 596 results.AddValue(scalar.ScalarValue( |
580 results.current_page, 'bypass', 'count', bypass_count)) | 597 results.current_page, 'bypass', 'count', bypass_count)) |
581 results.AddValue(scalar.ScalarValue( | 598 results.AddValue(scalar.ScalarValue( |
582 results.current_page, 'via', 'count', via_count)) | 599 results.current_page, 'via', 'count', via_count)) |
OLD | NEW |