Chromium Code Reviews| 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 base64 | 5 import base64 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from common import chrome_proxy_metrics as com_metrics | |
|
sclittle
2015/05/01 23:05:39
nit: change to common_metrics
bustamante
2015/05/01 23:54:11
Done.
| |
| 9 from common import network_metrics_unittest as network_unittest | |
| 8 from integration_tests import chrome_proxy_metrics as metrics | 10 from integration_tests import chrome_proxy_metrics as metrics |
| 9 from integration_tests import network_metrics_unittest as network_unittest | |
| 10 from telemetry.unittest_util import test_page_test_results | 11 from telemetry.unittest_util import test_page_test_results |
| 11 | 12 |
| 12 TEST_EXTRA_VIA_HEADER = '1.1 EXTRA_VIA_HEADER' | 13 TEST_EXTRA_VIA_HEADER = '1.1 EXTRA_VIA_HEADER' |
| 13 | 14 |
| 14 # Timeline events used in tests. | 15 # Timeline events used in tests. |
| 15 # An HTML not via proxy. | 16 # An HTML not via proxy. |
| 16 EVENT_HTML_DIRECT = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 17 EVENT_HTML_DIRECT = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 17 url='http://test.html1', | 18 url='http://test.html1', |
| 18 response_headers={ | 19 response_headers={ |
| 19 'Content-Type': 'text/html', | 20 'Content-Type': 'text/html', |
| 20 'Content-Length': str(len(network_unittest.HTML_BODY)), | 21 'Content-Length': str(len(network_unittest.HTML_BODY)), |
| 21 }, | 22 }, |
| 22 body=network_unittest.HTML_BODY) | 23 body=network_unittest.HTML_BODY) |
| 23 | 24 |
| 24 # An HTML via proxy. | 25 # An HTML via proxy. |
| 25 EVENT_HTML_PROXY_VIA = ( | 26 EVENT_HTML_PROXY_VIA = ( |
| 26 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 27 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 27 url='http://test.html2', | 28 url='http://test.html2', |
| 28 response_headers={ | 29 response_headers={ |
| 29 'Content-Type': 'text/html', | 30 'Content-Type': 'text/html', |
| 30 'Content-Encoding': 'gzip', | 31 'Content-Encoding': 'gzip', |
| 31 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), | 32 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), |
| 32 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 33 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 33 }, | 34 }, |
| 34 body=network_unittest.HTML_BODY, | 35 body=network_unittest.HTML_BODY, |
| 35 remote_port=443)) | 36 remote_port=443)) |
| 36 | 37 |
| 37 # An HTML via proxy with extra header. | 38 # An HTML via proxy with extra header. |
| 38 EVENT_HTML_PROXY_EXTRA_VIA = ( | 39 EVENT_HTML_PROXY_EXTRA_VIA = ( |
| 39 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 40 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 40 url='http://test.html2', | 41 url='http://test.html2', |
| 41 response_headers={ | 42 response_headers={ |
| 42 'Content-Type': 'text/html', | 43 'Content-Type': 'text/html', |
| 43 'Content-Encoding': 'gzip', | 44 'Content-Encoding': 'gzip', |
| 44 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), | 45 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), |
| 45 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER + ", " + | 46 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER + ", " + |
| 46 TEST_EXTRA_VIA_HEADER, | 47 TEST_EXTRA_VIA_HEADER, |
| 47 }, | 48 }, |
| 48 body=network_unittest.HTML_BODY, | 49 body=network_unittest.HTML_BODY, |
| 49 remote_port=443)) | 50 remote_port=443)) |
| 50 | 51 |
| 51 # An HTML via the HTTP fallback proxy. | 52 # An HTML via the HTTP fallback proxy. |
| 52 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK = ( | 53 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK = ( |
| 53 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 54 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 54 url='http://test.html2', | 55 url='http://test.html2', |
| 55 response_headers={ | 56 response_headers={ |
| 56 'Content-Type': 'text/html', | 57 'Content-Type': 'text/html', |
| 57 'Content-Encoding': 'gzip', | 58 'Content-Encoding': 'gzip', |
| 58 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), | 59 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), |
| 59 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 60 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 60 }, | 61 }, |
| 61 body=network_unittest.HTML_BODY, | 62 body=network_unittest.HTML_BODY, |
| 62 remote_port=80)) | 63 remote_port=80)) |
| 63 | 64 |
| 64 # An image via proxy with Via header. | 65 # An image via proxy with Via header. |
| 65 EVENT_IMAGE_PROXY_VIA = ( | 66 EVENT_IMAGE_PROXY_VIA = ( |
| 66 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 67 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 67 url='http://test.image', | 68 url='http://test.image', |
| 68 response_headers={ | 69 response_headers={ |
| 69 'Content-Type': 'image/jpeg', | 70 'Content-Type': 'image/jpeg', |
| 70 'Content-Encoding': 'gzip', | 71 'Content-Encoding': 'gzip', |
| 71 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), | 72 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), |
| 72 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 73 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 73 }, | 74 }, |
| 74 body=base64.b64encode(network_unittest.IMAGE_BODY), | 75 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 75 base64_encoded_body=True, | 76 base64_encoded_body=True, |
| 76 remote_port=443)) | 77 remote_port=443)) |
| 77 | 78 |
| 78 # An image via the HTTP fallback proxy. | 79 # An image via the HTTP fallback proxy. |
| 79 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK = ( | 80 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK = ( |
| 80 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 81 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 81 url='http://test.image', | 82 url='http://test.image', |
| 82 response_headers={ | 83 response_headers={ |
| 83 'Content-Type': 'image/jpeg', | 84 'Content-Type': 'image/jpeg', |
| 84 'Content-Encoding': 'gzip', | 85 'Content-Encoding': 'gzip', |
| 85 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), | 86 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), |
| 86 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 87 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 87 }, | 88 }, |
| 88 body=base64.b64encode(network_unittest.IMAGE_BODY), | 89 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 89 base64_encoded_body=True, | 90 base64_encoded_body=True, |
| 90 remote_port=80)) | 91 remote_port=80)) |
| 91 | 92 |
| 92 # An image via proxy with Via header and it is cached. | 93 # An image via proxy with Via header and it is cached. |
| 93 EVENT_IMAGE_PROXY_CACHED = ( | 94 EVENT_IMAGE_PROXY_CACHED = ( |
| 94 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 95 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 95 url='http://test.image', | 96 url='http://test.image', |
| 96 response_headers={ | 97 response_headers={ |
| 97 'Content-Type': 'image/jpeg', | 98 'Content-Type': 'image/jpeg', |
| 98 'Content-Encoding': 'gzip', | 99 'Content-Encoding': 'gzip', |
| 99 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), | 100 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), |
| 100 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 101 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 101 }, | 102 }, |
| 102 body=base64.b64encode(network_unittest.IMAGE_BODY), | 103 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 103 base64_encoded_body=True, | 104 base64_encoded_body=True, |
| 104 served_from_cache=True)) | 105 served_from_cache=True)) |
| 105 | 106 |
| 106 # An image fetched directly. | 107 # An image fetched directly. |
| 107 EVENT_IMAGE_DIRECT = ( | 108 EVENT_IMAGE_DIRECT = ( |
| 108 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 109 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 109 url='http://test.image', | 110 url='http://test.image', |
| 110 response_headers={ | 111 response_headers={ |
| 111 'Content-Type': 'image/jpeg', | 112 'Content-Type': 'image/jpeg', |
| 112 'Content-Encoding': 'gzip', | 113 'Content-Encoding': 'gzip', |
| 113 }, | 114 }, |
| 114 body=base64.b64encode(network_unittest.IMAGE_BODY), | 115 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 115 base64_encoded_body=True)) | 116 base64_encoded_body=True)) |
| 116 | 117 |
| 117 # A safe-browsing malware response. | 118 # A safe-browsing malware response. |
| 118 EVENT_MALWARE_PROXY = ( | 119 EVENT_MALWARE_PROXY = ( |
| 119 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 120 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 120 url='http://test.malware', | 121 url='http://test.malware', |
| 121 response_headers={ | 122 response_headers={ |
| 122 'X-Malware-Url': '1', | 123 'X-Malware-Url': '1', |
| 123 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 124 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 124 'Location': 'http://test.malware', | 125 'Location': 'http://test.malware', |
| 125 }, | 126 }, |
| 126 status=307)) | 127 status=307)) |
| 127 | 128 |
| 128 # An HTML via proxy with the Via header. | 129 # An HTML via proxy with the Via header. |
| 129 EVENT_IMAGE_BYPASS = ( | 130 EVENT_IMAGE_BYPASS = ( |
| 130 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 131 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 131 url='http://test.image', | 132 url='http://test.image', |
| 132 response_headers={ | 133 response_headers={ |
| 133 'Chrome-Proxy': 'bypass=1', | 134 'Chrome-Proxy': 'bypass=1', |
| 134 'Content-Type': 'text/html', | 135 'Content-Type': 'text/html', |
| 135 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 136 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 136 }, | 137 }, |
| 137 status=502)) | 138 status=502)) |
| 138 | 139 |
| 139 # An image fetched directly. | 140 # An image fetched directly. |
| 140 EVENT_IMAGE_DIRECT = ( | 141 EVENT_IMAGE_DIRECT = ( |
| 141 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 142 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 142 url='http://test.image', | 143 url='http://test.image', |
| 143 response_headers={ | 144 response_headers={ |
| 144 'Content-Type': 'image/jpeg', | 145 'Content-Type': 'image/jpeg', |
| 145 'Content-Encoding': 'gzip', | 146 'Content-Encoding': 'gzip', |
| 146 }, | 147 }, |
| 147 body=base64.b64encode(network_unittest.IMAGE_BODY), | 148 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 148 base64_encoded_body=True)) | 149 base64_encoded_body=True)) |
| 149 | 150 |
| 150 | 151 |
| 151 class ChromeProxyMetricTest(unittest.TestCase): | 152 class ChromeProxyMetricTest(unittest.TestCase): |
| 152 | 153 |
| 153 _test_proxy_info = {} | 154 _test_proxy_info = {} |
| 154 | 155 |
| 155 def _StubGetProxyInfo(self, info): | 156 def _StubGetProxyInfo(self, info): |
| 156 def stub(unused_tab, unused_url=''): # pylint: disable=W0613 | 157 def stub(unused_tab, unused_url=''): # pylint: disable=W0613 |
| 157 return ChromeProxyMetricTest._test_proxy_info | 158 return ChromeProxyMetricTest._test_proxy_info |
| 158 metrics.GetProxyInfoFromNetworkInternals = stub | 159 metrics.GetProxyInfoFromNetworkInternals = stub |
| 159 ChromeProxyMetricTest._test_proxy_info = info | 160 ChromeProxyMetricTest._test_proxy_info = info |
| 160 | 161 |
| 161 def testChromeProxyResponse(self): | 162 def testChromeProxyResponse(self): |
|
sclittle
2015/05/01 23:05:39
Move this testChromeProxyResponse into a unittest
bustamante
2015/05/01 23:54:11
Done.
| |
| 162 # An https non-proxy response. | 163 # An https non-proxy response. |
| 163 resp = metrics.ChromeProxyResponse( | 164 resp = com_metrics.ChromeProxyResponse( |
| 164 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 165 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 165 url='https://test.url', | 166 url='https://test.url', |
| 166 response_headers={ | 167 response_headers={ |
| 167 'Content-Type': 'text/html', | 168 'Content-Type': 'text/html', |
| 168 'Content-Length': str(len(network_unittest.HTML_BODY)), | 169 'Content-Length': str(len(network_unittest.HTML_BODY)), |
| 169 'Via': 'some other via', | 170 'Via': 'some other via', |
| 170 }, | 171 }, |
| 171 body=network_unittest.HTML_BODY)) | 172 body=network_unittest.HTML_BODY)) |
| 172 self.assertFalse(resp.ShouldHaveChromeProxyViaHeader()) | 173 self.assertFalse(resp.ShouldHaveChromeProxyViaHeader()) |
| 173 self.assertFalse(resp.HasChromeProxyViaHeader()) | 174 self.assertFalse(resp.HasChromeProxyViaHeader()) |
| 174 self.assertTrue(resp.IsValidByViaHeader()) | 175 self.assertTrue(resp.IsValidByViaHeader()) |
| 175 | 176 |
| 176 # A proxied JPEG image response | 177 # A proxied JPEG image response |
| 177 resp = metrics.ChromeProxyResponse( | 178 resp = com_metrics.ChromeProxyResponse( |
| 178 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 179 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 179 url='http://test.image', | 180 url='http://test.image', |
| 180 response_headers={ | 181 response_headers={ |
| 181 'Content-Type': 'image/jpeg', | 182 'Content-Type': 'image/jpeg', |
| 182 'Content-Encoding': 'gzip', | 183 'Content-Encoding': 'gzip', |
| 183 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | 184 'Via': '1.1 ' + com_metrics.CHROME_PROXY_VIA_HEADER, |
| 184 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), | 185 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), |
| 185 }, | 186 }, |
| 186 body=base64.b64encode(network_unittest.IMAGE_BODY), | 187 body=base64.b64encode(network_unittest.IMAGE_BODY), |
| 187 base64_encoded_body=True)) | 188 base64_encoded_body=True)) |
| 188 self.assertTrue(resp.ShouldHaveChromeProxyViaHeader()) | 189 self.assertTrue(resp.ShouldHaveChromeProxyViaHeader()) |
| 189 self.assertTrue(resp.HasChromeProxyViaHeader()) | 190 self.assertTrue(resp.HasChromeProxyViaHeader()) |
| 190 self.assertTrue(resp.IsValidByViaHeader()) | 191 self.assertTrue(resp.IsValidByViaHeader()) |
| 191 | 192 |
| 192 def testChromeProxyMetricForDataSaving(self): | |
| 193 metric = metrics.ChromeProxyMetric() | |
| 194 events = [ | |
| 195 EVENT_HTML_DIRECT, | |
| 196 EVENT_HTML_PROXY_VIA, | |
| 197 EVENT_IMAGE_PROXY_CACHED, | |
| 198 EVENT_IMAGE_DIRECT] | |
| 199 metric.SetEvents(events) | |
| 200 | |
| 201 self.assertTrue(len(events), len(list(metric.IterResponses(None)))) | |
| 202 results = test_page_test_results.TestPageTestResults(self) | |
| 203 | |
| 204 metric.AddResultsForDataSaving(None, results) | |
| 205 results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2) | |
| 206 results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1) | |
| 207 results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2) | |
| 208 | |
| 209 # Passing in zero responses should cause a failure. | |
| 210 metric.SetEvents([]) | |
| 211 no_responses_exception = False | |
| 212 try: | |
| 213 metric.AddResultsForDataSaving(None, results) | |
| 214 except metrics.ChromeProxyMetricException: | |
| 215 no_responses_exception = True | |
| 216 self.assertTrue(no_responses_exception) | |
| 217 | |
| 218 def testChromeProxyMetricForHeaderValidation(self): | 193 def testChromeProxyMetricForHeaderValidation(self): |
| 219 metric = metrics.ChromeProxyMetric() | 194 metric = metrics.ChromeProxyMetric() |
| 220 metric.SetEvents([ | 195 metric.SetEvents([ |
| 221 EVENT_HTML_DIRECT, | 196 EVENT_HTML_DIRECT, |
| 222 EVENT_HTML_PROXY_VIA, | 197 EVENT_HTML_PROXY_VIA, |
| 223 EVENT_IMAGE_PROXY_CACHED, | 198 EVENT_IMAGE_PROXY_CACHED, |
| 224 EVENT_IMAGE_DIRECT]) | 199 EVENT_IMAGE_DIRECT]) |
| 225 | 200 |
| 226 results = test_page_test_results.TestPageTestResults(self) | 201 results = test_page_test_results.TestPageTestResults(self) |
| 227 | 202 |
| 228 missing_via_exception = False | 203 missing_via_exception = False |
| 229 try: | 204 try: |
| 230 metric.AddResultsForHeaderValidation(None, results) | 205 metric.AddResultsForHeaderValidation(None, results) |
| 231 except metrics.ChromeProxyMetricException: | 206 except com_metrics.ChromeProxyMetricException: |
| 232 missing_via_exception = True | 207 missing_via_exception = True |
| 233 # Only the HTTP image response does not have a valid Via header. | 208 # Only the HTTP image response does not have a valid Via header. |
| 234 self.assertTrue(missing_via_exception) | 209 self.assertTrue(missing_via_exception) |
| 235 | 210 |
| 236 # Two events with valid Via headers. | 211 # Two events with valid Via headers. |
| 237 metric.SetEvents([ | 212 metric.SetEvents([ |
| 238 EVENT_HTML_PROXY_VIA, | 213 EVENT_HTML_PROXY_VIA, |
| 239 EVENT_IMAGE_PROXY_CACHED]) | 214 EVENT_IMAGE_PROXY_CACHED]) |
| 240 metric.AddResultsForHeaderValidation(None, results) | 215 metric.AddResultsForHeaderValidation(None, results) |
| 241 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) | 216 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) |
| 242 | 217 |
| 243 # Passing in zero responses should cause a failure. | 218 # Passing in zero responses should cause a failure. |
| 244 metric.SetEvents([]) | 219 metric.SetEvents([]) |
| 245 no_responses_exception = False | 220 no_responses_exception = False |
| 246 try: | 221 try: |
| 247 metric.AddResultsForHeaderValidation(None, results) | 222 metric.AddResultsForHeaderValidation(None, results) |
| 248 except metrics.ChromeProxyMetricException: | 223 except com_metrics.ChromeProxyMetricException: |
| 249 no_responses_exception = True | 224 no_responses_exception = True |
| 250 self.assertTrue(no_responses_exception) | 225 self.assertTrue(no_responses_exception) |
| 251 | 226 |
| 252 def testChromeProxyMetricForExtraViaHeader(self): | 227 def testChromeProxyMetricForExtraViaHeader(self): |
| 253 metric = metrics.ChromeProxyMetric() | 228 metric = metrics.ChromeProxyMetric() |
| 254 metric.SetEvents([EVENT_HTML_DIRECT, | 229 metric.SetEvents([EVENT_HTML_DIRECT, |
| 255 EVENT_HTML_PROXY_EXTRA_VIA]) | 230 EVENT_HTML_PROXY_EXTRA_VIA]) |
| 256 results = test_page_test_results.TestPageTestResults(self) | 231 results = test_page_test_results.TestPageTestResults(self) |
| 257 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) | 232 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) |
| 258 # The direct page should not count an extra via header, but should also not | 233 # The direct page should not count an extra via header, but should also not |
| 259 # throw an exception. | 234 # throw an exception. |
| 260 results.AssertHasPageSpecificScalarValue('extra_via_header', 'count', 1) | 235 results.AssertHasPageSpecificScalarValue('extra_via_header', 'count', 1) |
| 261 | 236 |
| 262 metric.SetEvents([EVENT_HTML_PROXY_VIA]) | 237 metric.SetEvents([EVENT_HTML_PROXY_VIA]) |
| 263 exception_occurred = False | 238 exception_occurred = False |
| 264 try: | 239 try: |
| 265 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) | 240 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) |
| 266 except metrics.ChromeProxyMetricException: | 241 except com_metrics.ChromeProxyMetricException: |
| 267 exception_occurred = True | 242 exception_occurred = True |
| 268 # The response had the chrome proxy via header, but not the extra expected | 243 # The response had the chrome proxy via header, but not the extra expected |
| 269 # via header. | 244 # via header. |
| 270 self.assertTrue(exception_occurred) | 245 self.assertTrue(exception_occurred) |
| 271 | 246 |
| 272 def testChromeProxyMetricForBypass(self): | 247 def testChromeProxyMetricForBypass(self): |
| 273 metric = metrics.ChromeProxyMetric() | 248 metric = metrics.ChromeProxyMetric() |
| 274 metric.SetEvents([ | 249 metric.SetEvents([ |
| 275 EVENT_HTML_DIRECT, | 250 EVENT_HTML_DIRECT, |
| 276 EVENT_HTML_PROXY_VIA, | 251 EVENT_HTML_PROXY_VIA, |
| 277 EVENT_IMAGE_PROXY_CACHED, | 252 EVENT_IMAGE_PROXY_CACHED, |
| 278 EVENT_IMAGE_DIRECT]) | 253 EVENT_IMAGE_DIRECT]) |
| 279 results = test_page_test_results.TestPageTestResults(self) | 254 results = test_page_test_results.TestPageTestResults(self) |
| 280 | 255 |
| 281 bypass_exception = False | 256 bypass_exception = False |
| 282 try: | 257 try: |
| 283 metric.AddResultsForBypass(None, results) | 258 metric.AddResultsForBypass(None, results) |
| 284 except metrics.ChromeProxyMetricException: | 259 except com_metrics.ChromeProxyMetricException: |
| 285 bypass_exception = True | 260 bypass_exception = True |
| 286 # Two of the first three events have Via headers. | 261 # Two of the first three events have Via headers. |
| 287 self.assertTrue(bypass_exception) | 262 self.assertTrue(bypass_exception) |
| 288 | 263 |
| 289 # Use directly fetched image only. It is treated as bypassed. | 264 # Use directly fetched image only. It is treated as bypassed. |
| 290 metric.SetEvents([EVENT_IMAGE_DIRECT]) | 265 metric.SetEvents([EVENT_IMAGE_DIRECT]) |
| 291 metric.AddResultsForBypass(None, results) | 266 metric.AddResultsForBypass(None, results) |
| 292 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 267 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
| 293 | 268 |
| 294 # Passing in zero responses should cause a failure. | 269 # Passing in zero responses should cause a failure. |
| 295 metric.SetEvents([]) | 270 metric.SetEvents([]) |
| 296 no_responses_exception = False | 271 no_responses_exception = False |
| 297 try: | 272 try: |
| 298 metric.AddResultsForBypass(None, results) | 273 metric.AddResultsForBypass(None, results) |
| 299 except metrics.ChromeProxyMetricException: | 274 except com_metrics.ChromeProxyMetricException: |
| 300 no_responses_exception = True | 275 no_responses_exception = True |
| 301 self.assertTrue(no_responses_exception) | 276 self.assertTrue(no_responses_exception) |
| 302 | 277 |
| 303 def testChromeProxyMetricForCorsBypass(self): | 278 def testChromeProxyMetricForCorsBypass(self): |
| 304 metric = metrics.ChromeProxyMetric() | 279 metric = metrics.ChromeProxyMetric() |
| 305 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 280 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
| 306 EVENT_IMAGE_BYPASS, | 281 EVENT_IMAGE_BYPASS, |
| 307 EVENT_IMAGE_DIRECT]) | 282 EVENT_IMAGE_DIRECT]) |
| 308 results = test_page_test_results.TestPageTestResults(self) | 283 results = test_page_test_results.TestPageTestResults(self) |
| 309 metric.AddResultsForCorsBypass(None, results) | 284 metric.AddResultsForCorsBypass(None, results) |
| 310 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) | 285 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) |
| 311 | 286 |
| 312 # Passing in zero responses should cause a failure. | 287 # Passing in zero responses should cause a failure. |
| 313 metric.SetEvents([]) | 288 metric.SetEvents([]) |
| 314 no_responses_exception = False | 289 no_responses_exception = False |
| 315 try: | 290 try: |
| 316 metric.AddResultsForCorsBypass(None, results) | 291 metric.AddResultsForCorsBypass(None, results) |
| 317 except metrics.ChromeProxyMetricException: | 292 except com_metrics.ChromeProxyMetricException: |
| 318 no_responses_exception = True | 293 no_responses_exception = True |
| 319 self.assertTrue(no_responses_exception) | 294 self.assertTrue(no_responses_exception) |
| 320 | 295 |
| 321 def testChromeProxyMetricForBlockOnce(self): | 296 def testChromeProxyMetricForBlockOnce(self): |
| 322 metric = metrics.ChromeProxyMetric() | 297 metric = metrics.ChromeProxyMetric() |
| 323 metric.SetEvents([EVENT_HTML_DIRECT, | 298 metric.SetEvents([EVENT_HTML_DIRECT, |
| 324 EVENT_IMAGE_PROXY_VIA]) | 299 EVENT_IMAGE_PROXY_VIA]) |
| 325 results = test_page_test_results.TestPageTestResults(self) | 300 results = test_page_test_results.TestPageTestResults(self) |
| 326 metric.AddResultsForBlockOnce(None, results) | 301 metric.AddResultsForBlockOnce(None, results) |
| 327 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) | 302 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) |
| 328 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 303 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
| 329 | 304 |
| 330 metric.SetEvents([EVENT_HTML_DIRECT, | 305 metric.SetEvents([EVENT_HTML_DIRECT, |
| 331 EVENT_IMAGE_DIRECT]) | 306 EVENT_IMAGE_DIRECT]) |
| 332 exception_occurred = False | 307 exception_occurred = False |
| 333 try: | 308 try: |
| 334 metric.AddResultsForBlockOnce(None, results) | 309 metric.AddResultsForBlockOnce(None, results) |
| 335 except metrics.ChromeProxyMetricException: | 310 except com_metrics.ChromeProxyMetricException: |
| 336 exception_occurred = True | 311 exception_occurred = True |
| 337 # The second response was over direct, but was expected via proxy. | 312 # The second response was over direct, but was expected via proxy. |
| 338 self.assertTrue(exception_occurred) | 313 self.assertTrue(exception_occurred) |
| 339 | 314 |
| 340 # Passing in zero responses should cause a failure. | 315 # Passing in zero responses should cause a failure. |
| 341 metric.SetEvents([]) | 316 metric.SetEvents([]) |
| 342 no_responses_exception = False | 317 no_responses_exception = False |
| 343 try: | 318 try: |
| 344 metric.AddResultsForBlockOnce(None, results) | 319 metric.AddResultsForBlockOnce(None, results) |
| 345 except metrics.ChromeProxyMetricException: | 320 except com_metrics.ChromeProxyMetricException: |
| 346 no_responses_exception = True | 321 no_responses_exception = True |
| 347 self.assertTrue(no_responses_exception) | 322 self.assertTrue(no_responses_exception) |
| 348 | 323 |
| 349 def testChromeProxyMetricForSafebrowsingOn(self): | 324 def testChromeProxyMetricForSafebrowsingOn(self): |
| 350 metric = metrics.ChromeProxyMetric() | 325 metric = metrics.ChromeProxyMetric() |
| 351 metric.SetEvents([EVENT_MALWARE_PROXY]) | 326 metric.SetEvents([EVENT_MALWARE_PROXY]) |
| 352 results = test_page_test_results.TestPageTestResults(self) | 327 results = test_page_test_results.TestPageTestResults(self) |
| 353 | 328 |
| 354 metric.AddResultsForSafebrowsingOn(None, results) | 329 metric.AddResultsForSafebrowsingOn(None, results) |
| 355 results.AssertHasPageSpecificScalarValue( | 330 results.AssertHasPageSpecificScalarValue( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 368 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) | 343 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) |
| 369 results = test_page_test_results.TestPageTestResults(self) | 344 results = test_page_test_results.TestPageTestResults(self) |
| 370 metric.AddResultsForHTTPFallback(None, results) | 345 metric.AddResultsForHTTPFallback(None, results) |
| 371 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 2) | 346 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 2) |
| 372 | 347 |
| 373 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 348 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
| 374 EVENT_IMAGE_PROXY_VIA]) | 349 EVENT_IMAGE_PROXY_VIA]) |
| 375 exception_occurred = False | 350 exception_occurred = False |
| 376 try: | 351 try: |
| 377 metric.AddResultsForHTTPFallback(None, results) | 352 metric.AddResultsForHTTPFallback(None, results) |
| 378 except metrics.ChromeProxyMetricException: | 353 except com_metrics.ChromeProxyMetricException: |
| 379 exception_occurred = True | 354 exception_occurred = True |
| 380 # The responses came through the SPDY proxy, but were expected through the | 355 # The responses came through the SPDY proxy, but were expected through the |
| 381 # HTTP fallback proxy. | 356 # HTTP fallback proxy. |
| 382 self.assertTrue(exception_occurred) | 357 self.assertTrue(exception_occurred) |
| 383 | 358 |
| 384 # Passing in zero responses should cause a failure. | 359 # Passing in zero responses should cause a failure. |
| 385 metric.SetEvents([]) | 360 metric.SetEvents([]) |
| 386 no_responses_exception = False | 361 no_responses_exception = False |
| 387 try: | 362 try: |
| 388 metric.AddResultsForHTTPFallback(None, results) | 363 metric.AddResultsForHTTPFallback(None, results) |
| 389 except metrics.ChromeProxyMetricException: | 364 except com_metrics.ChromeProxyMetricException: |
| 390 no_responses_exception = True | 365 no_responses_exception = True |
| 391 self.assertTrue(no_responses_exception) | 366 self.assertTrue(no_responses_exception) |
| 392 | 367 |
| 393 def testChromeProxyMetricForHTTPToDirectFallback(self): | 368 def testChromeProxyMetricForHTTPToDirectFallback(self): |
| 394 metric = metrics.ChromeProxyMetric() | 369 metric = metrics.ChromeProxyMetric() |
| 395 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 370 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
| 396 EVENT_HTML_DIRECT, | 371 EVENT_HTML_DIRECT, |
| 397 EVENT_IMAGE_DIRECT]) | 372 EVENT_IMAGE_DIRECT]) |
| 398 results = test_page_test_results.TestPageTestResults(self) | 373 results = test_page_test_results.TestPageTestResults(self) |
| 399 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 374 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
| 400 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 1) | 375 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 1) |
| 401 results.AssertHasPageSpecificScalarValue('bypass', 'count', 2) | 376 results.AssertHasPageSpecificScalarValue('bypass', 'count', 2) |
| 402 | 377 |
| 403 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 378 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
| 404 EVENT_HTML_DIRECT]) | 379 EVENT_HTML_DIRECT]) |
| 405 exception_occurred = False | 380 exception_occurred = False |
| 406 try: | 381 try: |
| 407 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 382 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
| 408 except metrics.ChromeProxyMetricException: | 383 except com_metrics.ChromeProxyMetricException: |
| 409 exception_occurred = True | 384 exception_occurred = True |
| 410 # The first response was expected through the HTTP fallback proxy. | 385 # The first response was expected through the HTTP fallback proxy. |
| 411 self.assertTrue(exception_occurred) | 386 self.assertTrue(exception_occurred) |
| 412 | 387 |
| 413 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 388 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
| 414 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 389 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
| 415 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) | 390 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) |
| 416 exception_occurred = False | 391 exception_occurred = False |
| 417 try: | 392 try: |
| 418 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 393 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
| 419 except metrics.ChromeProxyMetricException: | 394 except com_metrics.ChromeProxyMetricException: |
| 420 exception_occurred = True | 395 exception_occurred = True |
| 421 # All but the first response were expected to be over direct. | 396 # All but the first response were expected to be over direct. |
| 422 self.assertTrue(exception_occurred) | 397 self.assertTrue(exception_occurred) |
| 423 | 398 |
| 424 metric.SetEvents([EVENT_HTML_DIRECT, | 399 metric.SetEvents([EVENT_HTML_DIRECT, |
| 425 EVENT_HTML_DIRECT, | 400 EVENT_HTML_DIRECT, |
| 426 EVENT_IMAGE_DIRECT]) | 401 EVENT_IMAGE_DIRECT]) |
| 427 exception_occurred = False | 402 exception_occurred = False |
| 428 try: | 403 try: |
| 429 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 404 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
| 430 except metrics.ChromeProxyMetricException: | 405 except com_metrics.ChromeProxyMetricException: |
| 431 exception_occurred = True | 406 exception_occurred = True |
| 432 # The first response was expected through the HTTP fallback proxy. | 407 # The first response was expected through the HTTP fallback proxy. |
| 433 self.assertTrue(exception_occurred) | 408 self.assertTrue(exception_occurred) |
| 434 | 409 |
| 435 # Passing in zero responses should cause a failure. | 410 # Passing in zero responses should cause a failure. |
| 436 metric.SetEvents([]) | 411 metric.SetEvents([]) |
| 437 no_responses_exception = False | 412 no_responses_exception = False |
| 438 try: | 413 try: |
| 439 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 414 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
| 440 except metrics.ChromeProxyMetricException: | 415 except com_metrics.ChromeProxyMetricException: |
| 441 no_responses_exception = True | 416 no_responses_exception = True |
| 442 self.assertTrue(no_responses_exception) | 417 self.assertTrue(no_responses_exception) |
| OLD | NEW |