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 common_metrics |
| 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 ' + common_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 ' + common_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 ' + common_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 ' + common_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 ' + common_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 ' + common_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 ' + common_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 ' + common_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 # An https non-proxy response. | |
163 resp = metrics.ChromeProxyResponse( | |
164 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | |
165 url='https://test.url', | |
166 response_headers={ | |
167 'Content-Type': 'text/html', | |
168 'Content-Length': str(len(network_unittest.HTML_BODY)), | |
169 'Via': 'some other via', | |
170 }, | |
171 body=network_unittest.HTML_BODY)) | |
172 self.assertFalse(resp.ShouldHaveChromeProxyViaHeader()) | |
173 self.assertFalse(resp.HasChromeProxyViaHeader()) | |
174 self.assertTrue(resp.IsValidByViaHeader()) | |
175 | |
176 # A proxied JPEG image response | |
177 resp = metrics.ChromeProxyResponse( | |
178 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | |
179 url='http://test.image', | |
180 response_headers={ | |
181 'Content-Type': 'image/jpeg', | |
182 'Content-Encoding': 'gzip', | |
183 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER, | |
184 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL), | |
185 }, | |
186 body=base64.b64encode(network_unittest.IMAGE_BODY), | |
187 base64_encoded_body=True)) | |
188 self.assertTrue(resp.ShouldHaveChromeProxyViaHeader()) | |
189 self.assertTrue(resp.HasChromeProxyViaHeader()) | |
190 self.assertTrue(resp.IsValidByViaHeader()) | |
191 | |
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): | 162 def testChromeProxyMetricForHeaderValidation(self): |
219 metric = metrics.ChromeProxyMetric() | 163 metric = metrics.ChromeProxyMetric() |
220 metric.SetEvents([ | 164 metric.SetEvents([ |
221 EVENT_HTML_DIRECT, | 165 EVENT_HTML_DIRECT, |
222 EVENT_HTML_PROXY_VIA, | 166 EVENT_HTML_PROXY_VIA, |
223 EVENT_IMAGE_PROXY_CACHED, | 167 EVENT_IMAGE_PROXY_CACHED, |
224 EVENT_IMAGE_DIRECT]) | 168 EVENT_IMAGE_DIRECT]) |
225 | 169 |
226 results = test_page_test_results.TestPageTestResults(self) | 170 results = test_page_test_results.TestPageTestResults(self) |
227 | 171 |
228 missing_via_exception = False | 172 missing_via_exception = False |
229 try: | 173 try: |
230 metric.AddResultsForHeaderValidation(None, results) | 174 metric.AddResultsForHeaderValidation(None, results) |
231 except metrics.ChromeProxyMetricException: | 175 except common_metrics.ChromeProxyMetricException: |
232 missing_via_exception = True | 176 missing_via_exception = True |
233 # Only the HTTP image response does not have a valid Via header. | 177 # Only the HTTP image response does not have a valid Via header. |
234 self.assertTrue(missing_via_exception) | 178 self.assertTrue(missing_via_exception) |
235 | 179 |
236 # Two events with valid Via headers. | 180 # Two events with valid Via headers. |
237 metric.SetEvents([ | 181 metric.SetEvents([ |
238 EVENT_HTML_PROXY_VIA, | 182 EVENT_HTML_PROXY_VIA, |
239 EVENT_IMAGE_PROXY_CACHED]) | 183 EVENT_IMAGE_PROXY_CACHED]) |
240 metric.AddResultsForHeaderValidation(None, results) | 184 metric.AddResultsForHeaderValidation(None, results) |
241 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) | 185 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) |
242 | 186 |
243 # Passing in zero responses should cause a failure. | 187 # Passing in zero responses should cause a failure. |
244 metric.SetEvents([]) | 188 metric.SetEvents([]) |
245 no_responses_exception = False | 189 no_responses_exception = False |
246 try: | 190 try: |
247 metric.AddResultsForHeaderValidation(None, results) | 191 metric.AddResultsForHeaderValidation(None, results) |
248 except metrics.ChromeProxyMetricException: | 192 except common_metrics.ChromeProxyMetricException: |
249 no_responses_exception = True | 193 no_responses_exception = True |
250 self.assertTrue(no_responses_exception) | 194 self.assertTrue(no_responses_exception) |
251 | 195 |
252 def testChromeProxyMetricForExtraViaHeader(self): | 196 def testChromeProxyMetricForExtraViaHeader(self): |
253 metric = metrics.ChromeProxyMetric() | 197 metric = metrics.ChromeProxyMetric() |
254 metric.SetEvents([EVENT_HTML_DIRECT, | 198 metric.SetEvents([EVENT_HTML_DIRECT, |
255 EVENT_HTML_PROXY_EXTRA_VIA]) | 199 EVENT_HTML_PROXY_EXTRA_VIA]) |
256 results = test_page_test_results.TestPageTestResults(self) | 200 results = test_page_test_results.TestPageTestResults(self) |
257 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) | 201 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) |
258 # The direct page should not count an extra via header, but should also not | 202 # The direct page should not count an extra via header, but should also not |
259 # throw an exception. | 203 # throw an exception. |
260 results.AssertHasPageSpecificScalarValue('extra_via_header', 'count', 1) | 204 results.AssertHasPageSpecificScalarValue('extra_via_header', 'count', 1) |
261 | 205 |
262 metric.SetEvents([EVENT_HTML_PROXY_VIA]) | 206 metric.SetEvents([EVENT_HTML_PROXY_VIA]) |
263 exception_occurred = False | 207 exception_occurred = False |
264 try: | 208 try: |
265 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) | 209 metric.AddResultsForExtraViaHeader(None, results, TEST_EXTRA_VIA_HEADER) |
266 except metrics.ChromeProxyMetricException: | 210 except common_metrics.ChromeProxyMetricException: |
267 exception_occurred = True | 211 exception_occurred = True |
268 # The response had the chrome proxy via header, but not the extra expected | 212 # The response had the chrome proxy via header, but not the extra expected |
269 # via header. | 213 # via header. |
270 self.assertTrue(exception_occurred) | 214 self.assertTrue(exception_occurred) |
271 | 215 |
272 def testChromeProxyMetricForBypass(self): | 216 def testChromeProxyMetricForBypass(self): |
273 metric = metrics.ChromeProxyMetric() | 217 metric = metrics.ChromeProxyMetric() |
274 metric.SetEvents([ | 218 metric.SetEvents([ |
275 EVENT_HTML_DIRECT, | 219 EVENT_HTML_DIRECT, |
276 EVENT_HTML_PROXY_VIA, | 220 EVENT_HTML_PROXY_VIA, |
277 EVENT_IMAGE_PROXY_CACHED, | 221 EVENT_IMAGE_PROXY_CACHED, |
278 EVENT_IMAGE_DIRECT]) | 222 EVENT_IMAGE_DIRECT]) |
279 results = test_page_test_results.TestPageTestResults(self) | 223 results = test_page_test_results.TestPageTestResults(self) |
280 | 224 |
281 bypass_exception = False | 225 bypass_exception = False |
282 try: | 226 try: |
283 metric.AddResultsForBypass(None, results) | 227 metric.AddResultsForBypass(None, results) |
284 except metrics.ChromeProxyMetricException: | 228 except common_metrics.ChromeProxyMetricException: |
285 bypass_exception = True | 229 bypass_exception = True |
286 # Two of the first three events have Via headers. | 230 # Two of the first three events have Via headers. |
287 self.assertTrue(bypass_exception) | 231 self.assertTrue(bypass_exception) |
288 | 232 |
289 # Use directly fetched image only. It is treated as bypassed. | 233 # Use directly fetched image only. It is treated as bypassed. |
290 metric.SetEvents([EVENT_IMAGE_DIRECT]) | 234 metric.SetEvents([EVENT_IMAGE_DIRECT]) |
291 metric.AddResultsForBypass(None, results) | 235 metric.AddResultsForBypass(None, results) |
292 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 236 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
293 | 237 |
294 # Passing in zero responses should cause a failure. | 238 # Passing in zero responses should cause a failure. |
295 metric.SetEvents([]) | 239 metric.SetEvents([]) |
296 no_responses_exception = False | 240 no_responses_exception = False |
297 try: | 241 try: |
298 metric.AddResultsForBypass(None, results) | 242 metric.AddResultsForBypass(None, results) |
299 except metrics.ChromeProxyMetricException: | 243 except common_metrics.ChromeProxyMetricException: |
300 no_responses_exception = True | 244 no_responses_exception = True |
301 self.assertTrue(no_responses_exception) | 245 self.assertTrue(no_responses_exception) |
302 | 246 |
303 def testChromeProxyMetricForCorsBypass(self): | 247 def testChromeProxyMetricForCorsBypass(self): |
304 metric = metrics.ChromeProxyMetric() | 248 metric = metrics.ChromeProxyMetric() |
305 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 249 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
306 EVENT_IMAGE_BYPASS, | 250 EVENT_IMAGE_BYPASS, |
307 EVENT_IMAGE_DIRECT]) | 251 EVENT_IMAGE_DIRECT]) |
308 results = test_page_test_results.TestPageTestResults(self) | 252 results = test_page_test_results.TestPageTestResults(self) |
309 metric.AddResultsForCorsBypass(None, results) | 253 metric.AddResultsForCorsBypass(None, results) |
310 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) | 254 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) |
311 | 255 |
312 # Passing in zero responses should cause a failure. | 256 # Passing in zero responses should cause a failure. |
313 metric.SetEvents([]) | 257 metric.SetEvents([]) |
314 no_responses_exception = False | 258 no_responses_exception = False |
315 try: | 259 try: |
316 metric.AddResultsForCorsBypass(None, results) | 260 metric.AddResultsForCorsBypass(None, results) |
317 except metrics.ChromeProxyMetricException: | 261 except common_metrics.ChromeProxyMetricException: |
318 no_responses_exception = True | 262 no_responses_exception = True |
319 self.assertTrue(no_responses_exception) | 263 self.assertTrue(no_responses_exception) |
320 | 264 |
321 def testChromeProxyMetricForBlockOnce(self): | 265 def testChromeProxyMetricForBlockOnce(self): |
322 metric = metrics.ChromeProxyMetric() | 266 metric = metrics.ChromeProxyMetric() |
323 metric.SetEvents([EVENT_HTML_DIRECT, | 267 metric.SetEvents([EVENT_HTML_DIRECT, |
324 EVENT_IMAGE_PROXY_VIA]) | 268 EVENT_IMAGE_PROXY_VIA]) |
325 results = test_page_test_results.TestPageTestResults(self) | 269 results = test_page_test_results.TestPageTestResults(self) |
326 metric.AddResultsForBlockOnce(None, results) | 270 metric.AddResultsForBlockOnce(None, results) |
327 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) | 271 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) |
328 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 272 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
329 | 273 |
330 metric.SetEvents([EVENT_HTML_DIRECT, | 274 metric.SetEvents([EVENT_HTML_DIRECT, |
331 EVENT_IMAGE_DIRECT]) | 275 EVENT_IMAGE_DIRECT]) |
332 exception_occurred = False | 276 exception_occurred = False |
333 try: | 277 try: |
334 metric.AddResultsForBlockOnce(None, results) | 278 metric.AddResultsForBlockOnce(None, results) |
335 except metrics.ChromeProxyMetricException: | 279 except common_metrics.ChromeProxyMetricException: |
336 exception_occurred = True | 280 exception_occurred = True |
337 # The second response was over direct, but was expected via proxy. | 281 # The second response was over direct, but was expected via proxy. |
338 self.assertTrue(exception_occurred) | 282 self.assertTrue(exception_occurred) |
339 | 283 |
340 # Passing in zero responses should cause a failure. | 284 # Passing in zero responses should cause a failure. |
341 metric.SetEvents([]) | 285 metric.SetEvents([]) |
342 no_responses_exception = False | 286 no_responses_exception = False |
343 try: | 287 try: |
344 metric.AddResultsForBlockOnce(None, results) | 288 metric.AddResultsForBlockOnce(None, results) |
345 except metrics.ChromeProxyMetricException: | 289 except common_metrics.ChromeProxyMetricException: |
346 no_responses_exception = True | 290 no_responses_exception = True |
347 self.assertTrue(no_responses_exception) | 291 self.assertTrue(no_responses_exception) |
348 | 292 |
349 def testChromeProxyMetricForSafebrowsingOn(self): | 293 def testChromeProxyMetricForSafebrowsingOn(self): |
350 metric = metrics.ChromeProxyMetric() | 294 metric = metrics.ChromeProxyMetric() |
351 metric.SetEvents([EVENT_MALWARE_PROXY]) | 295 metric.SetEvents([EVENT_MALWARE_PROXY]) |
352 results = test_page_test_results.TestPageTestResults(self) | 296 results = test_page_test_results.TestPageTestResults(self) |
353 | 297 |
354 metric.AddResultsForSafebrowsingOn(None, results) | 298 metric.AddResultsForSafebrowsingOn(None, results) |
355 results.AssertHasPageSpecificScalarValue( | 299 results.AssertHasPageSpecificScalarValue( |
(...skipping 12 matching lines...) Expand all Loading... |
368 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) | 312 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) |
369 results = test_page_test_results.TestPageTestResults(self) | 313 results = test_page_test_results.TestPageTestResults(self) |
370 metric.AddResultsForHTTPFallback(None, results) | 314 metric.AddResultsForHTTPFallback(None, results) |
371 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 2) | 315 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 2) |
372 | 316 |
373 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 317 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
374 EVENT_IMAGE_PROXY_VIA]) | 318 EVENT_IMAGE_PROXY_VIA]) |
375 exception_occurred = False | 319 exception_occurred = False |
376 try: | 320 try: |
377 metric.AddResultsForHTTPFallback(None, results) | 321 metric.AddResultsForHTTPFallback(None, results) |
378 except metrics.ChromeProxyMetricException: | 322 except common_metrics.ChromeProxyMetricException: |
379 exception_occurred = True | 323 exception_occurred = True |
380 # The responses came through the SPDY proxy, but were expected through the | 324 # The responses came through the SPDY proxy, but were expected through the |
381 # HTTP fallback proxy. | 325 # HTTP fallback proxy. |
382 self.assertTrue(exception_occurred) | 326 self.assertTrue(exception_occurred) |
383 | 327 |
384 # Passing in zero responses should cause a failure. | 328 # Passing in zero responses should cause a failure. |
385 metric.SetEvents([]) | 329 metric.SetEvents([]) |
386 no_responses_exception = False | 330 no_responses_exception = False |
387 try: | 331 try: |
388 metric.AddResultsForHTTPFallback(None, results) | 332 metric.AddResultsForHTTPFallback(None, results) |
389 except metrics.ChromeProxyMetricException: | 333 except common_metrics.ChromeProxyMetricException: |
390 no_responses_exception = True | 334 no_responses_exception = True |
391 self.assertTrue(no_responses_exception) | 335 self.assertTrue(no_responses_exception) |
392 | 336 |
393 def testChromeProxyMetricForHTTPToDirectFallback(self): | 337 def testChromeProxyMetricForHTTPToDirectFallback(self): |
394 metric = metrics.ChromeProxyMetric() | 338 metric = metrics.ChromeProxyMetric() |
395 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 339 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
396 EVENT_HTML_DIRECT, | 340 EVENT_HTML_DIRECT, |
397 EVENT_IMAGE_DIRECT]) | 341 EVENT_IMAGE_DIRECT]) |
398 results = test_page_test_results.TestPageTestResults(self) | 342 results = test_page_test_results.TestPageTestResults(self) |
399 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 343 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
400 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 1) | 344 results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 1) |
401 results.AssertHasPageSpecificScalarValue('bypass', 'count', 2) | 345 results.AssertHasPageSpecificScalarValue('bypass', 'count', 2) |
402 | 346 |
403 metric.SetEvents([EVENT_HTML_PROXY_VIA, | 347 metric.SetEvents([EVENT_HTML_PROXY_VIA, |
404 EVENT_HTML_DIRECT]) | 348 EVENT_HTML_DIRECT]) |
405 exception_occurred = False | 349 exception_occurred = False |
406 try: | 350 try: |
407 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 351 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
408 except metrics.ChromeProxyMetricException: | 352 except common_metrics.ChromeProxyMetricException: |
409 exception_occurred = True | 353 exception_occurred = True |
410 # The first response was expected through the HTTP fallback proxy. | 354 # The first response was expected through the HTTP fallback proxy. |
411 self.assertTrue(exception_occurred) | 355 self.assertTrue(exception_occurred) |
412 | 356 |
413 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 357 metric.SetEvents([EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
414 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, | 358 EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, |
415 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) | 359 EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK]) |
416 exception_occurred = False | 360 exception_occurred = False |
417 try: | 361 try: |
418 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 362 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
419 except metrics.ChromeProxyMetricException: | 363 except common_metrics.ChromeProxyMetricException: |
420 exception_occurred = True | 364 exception_occurred = True |
421 # All but the first response were expected to be over direct. | 365 # All but the first response were expected to be over direct. |
422 self.assertTrue(exception_occurred) | 366 self.assertTrue(exception_occurred) |
423 | 367 |
424 metric.SetEvents([EVENT_HTML_DIRECT, | 368 metric.SetEvents([EVENT_HTML_DIRECT, |
425 EVENT_HTML_DIRECT, | 369 EVENT_HTML_DIRECT, |
426 EVENT_IMAGE_DIRECT]) | 370 EVENT_IMAGE_DIRECT]) |
427 exception_occurred = False | 371 exception_occurred = False |
428 try: | 372 try: |
429 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 373 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
430 except metrics.ChromeProxyMetricException: | 374 except common_metrics.ChromeProxyMetricException: |
431 exception_occurred = True | 375 exception_occurred = True |
432 # The first response was expected through the HTTP fallback proxy. | 376 # The first response was expected through the HTTP fallback proxy. |
433 self.assertTrue(exception_occurred) | 377 self.assertTrue(exception_occurred) |
434 | 378 |
435 # Passing in zero responses should cause a failure. | 379 # Passing in zero responses should cause a failure. |
436 metric.SetEvents([]) | 380 metric.SetEvents([]) |
437 no_responses_exception = False | 381 no_responses_exception = False |
438 try: | 382 try: |
439 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 383 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
440 except metrics.ChromeProxyMetricException: | 384 except common_metrics.ChromeProxyMetricException: |
441 no_responses_exception = True | 385 no_responses_exception = True |
442 self.assertTrue(no_responses_exception) | 386 self.assertTrue(no_responses_exception) |
| 387 |
OLD | NEW |