| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return None | 64 return None |
| 65 | 65 |
| 66 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] | 66 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] |
| 67 values = [v.strip() for v in chrome_proxy_request_header.split(',')] | 67 values = [v.strip() for v in chrome_proxy_request_header.split(',')] |
| 68 for value in values: | 68 for value in values: |
| 69 kvp = value.split('=', 1) | 69 kvp = value.split('=', 1) |
| 70 if len(kvp) == 2 and kvp[0].strip() == 'c': | 70 if len(kvp) == 2 and kvp[0].strip() == 'c': |
| 71 return kvp[1].strip() | 71 return kvp[1].strip() |
| 72 return None | 72 return None |
| 73 | 73 |
| 74 def HasChromeProxyLoFi(self): |
| 75 if 'Chrome-Proxy' not in self.response.request_headers: |
| 76 return False |
| 77 chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy'] |
| 78 values = [v.strip() for v in chrome_proxy_request_header.split(',')] |
| 79 for value in values: |
| 80 if len(value) == 5 and value == 'q=low': |
| 81 return True |
| 82 return False |
| 74 | 83 |
| 75 class ChromeProxyMetric(network_metrics.NetworkMetric): | 84 class ChromeProxyMetric(network_metrics.NetworkMetric): |
| 76 """A Chrome proxy timeline metric.""" | 85 """A Chrome proxy timeline metric.""" |
| 77 | 86 |
| 78 def __init__(self): | 87 def __init__(self): |
| 79 super(ChromeProxyMetric, self).__init__() | 88 super(ChromeProxyMetric, self).__init__() |
| 80 self.compute_data_saving = True | 89 self.compute_data_saving = True |
| 81 | 90 |
| 82 def SetEvents(self, events): | 91 def SetEvents(self, events): |
| 83 """Used for unittest.""" | 92 """Used for unittest.""" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 raise ChromeProxyMetricException, ( | 182 raise ChromeProxyMetricException, ( |
| 174 '%s: Response missing via header. Only "%s" clients should ' | 183 '%s: Response missing via header. Only "%s" clients should ' |
| 175 'bypass for this page, but this client is "%s".' % ( | 184 'bypass for this page, but this client is "%s".' % ( |
| 176 resp.response.url, bypass_for_client_type, client_type)) | 185 resp.response.url, bypass_for_client_type, client_type)) |
| 177 | 186 |
| 178 results.AddValue(scalar.ScalarValue( | 187 results.AddValue(scalar.ScalarValue( |
| 179 results.current_page, 'via', 'count', via_count)) | 188 results.current_page, 'via', 'count', via_count)) |
| 180 results.AddValue(scalar.ScalarValue( | 189 results.AddValue(scalar.ScalarValue( |
| 181 results.current_page, 'bypass', 'count', bypass_count)) | 190 results.current_page, 'bypass', 'count', bypass_count)) |
| 182 | 191 |
| 192 def AddResultsForLoFi(self, tab, results): |
| 193 lo_fi_count = 0 |
| 194 |
| 195 for resp in self.IterResponses(tab): |
| 196 if resp.HasChromeProxyViaHeader(): |
| 197 lo_fi_count += 1 |
| 198 else: |
| 199 r = resp.response |
| 200 raise ChromeProxyMetricException, ( |
| 201 '%s: LoFi not in request header.' % (r.url)) |
| 202 |
| 203 cl = resp.content_length |
| 204 resource = resp.response.url |
| 205 results.AddValue(scalar.ScalarValue( |
| 206 results.current_page, 'lo_fi', 'count', lo_fi_count)) |
| 207 |
| 208 for resp in self.IterResponses(tab): |
| 209 r = resp.response |
| 210 cl = resp.content_length |
| 211 ocl = resp.original_content_length |
| 212 saving = resp.data_saving_rate * 100 |
| 213 if cl > 100: |
| 214 raise ChromeProxyMetricException, ( |
| 215 'Image %s is %d bytes. Expecting less than 100 bytes.' % |
| 216 (resource, cl)) |
| 217 |
| 218 results.AddValue(scalar.ScalarValue( |
| 219 results.current_page, 'content_length', 'bytes', cl)) |
| 220 results.AddValue(scalar.ScalarValue( |
| 221 results.current_page, 'original_content_length', 'bytes', ocl)) |
| 222 results.AddValue(scalar.ScalarValue( |
| 223 results.current_page, 'data_saving', 'percent', saving)) |
| 224 |
| 183 def AddResultsForBypass(self, tab, results): | 225 def AddResultsForBypass(self, tab, results): |
| 184 bypass_count = 0 | 226 bypass_count = 0 |
| 185 | 227 |
| 186 for resp in self.IterResponses(tab): | 228 for resp in self.IterResponses(tab): |
| 187 if resp.HasChromeProxyViaHeader(): | 229 if resp.HasChromeProxyViaHeader(): |
| 188 r = resp.response | 230 r = resp.response |
| 189 raise ChromeProxyMetricException, ( | 231 raise ChromeProxyMetricException, ( |
| 190 '%s: Should not have Via header (%s) (refer=%s, status=%d)' % ( | 232 '%s: Should not have Via header (%s) (refer=%s, status=%d)' % ( |
| 191 r.url, r.GetHeader('Via'), r.GetHeader('Referer'), r.status)) | 233 r.url, r.GetHeader('Via'), r.GetHeader('Referer'), r.status)) |
| 192 bypass_count += 1 | 234 bypass_count += 1 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 'Response for %s should have via header; proxy should no longer ' | 455 'Response for %s should have via header; proxy should no longer ' |
| 414 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( | 456 'be bypassed.\nReponse: status=(%d, %s)\nHeaders:\n %s' % ( |
| 415 r.url, r.status, r.status_text, r.headers)) | 457 r.url, r.status, r.status_text, r.headers)) |
| 416 else: | 458 else: |
| 417 via_count += 1 | 459 via_count += 1 |
| 418 | 460 |
| 419 results.AddValue(scalar.ScalarValue( | 461 results.AddValue(scalar.ScalarValue( |
| 420 results.current_page, 'bypass', 'count', bypass_count)) | 462 results.current_page, 'bypass', 'count', bypass_count)) |
| 421 results.AddValue(scalar.ScalarValue( | 463 results.AddValue(scalar.ScalarValue( |
| 422 results.current_page, 'via', 'count', via_count)) | 464 results.current_page, 'via', 'count', via_count)) |
| OLD | NEW |