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 | 8 from common import chrome_proxy_metrics as common_metrics |
9 from common import network_metrics_unittest as network_unittest | 9 from common import network_metrics_unittest as network_unittest |
10 from integration_tests import chrome_proxy_metrics as metrics | 10 from integration_tests import chrome_proxy_metrics as metrics |
11 from telemetry.testing import test_page_test_results | 11 from telemetry.testing import test_page_test_results |
12 | 12 |
13 TEST_EXTRA_VIA_HEADER = '1.1 EXTRA_VIA_HEADER' | 13 TEST_EXTRA_VIA_HEADER = '1.1 EXTRA_VIA_HEADER' |
14 | 14 |
15 # Timeline events used in tests. | 15 # Timeline events used in tests. |
16 # An HTML not via proxy. | 16 # An HTML not via proxy. |
17 EVENT_HTML_DIRECT = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 17 EVENT_HTML_DIRECT = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
18 url='http://test.html1', | 18 url='http://test.html1', |
19 response_headers={ | 19 response_headers={ |
20 'Content-Type': 'text/html', | 20 'Content-Type': 'text/html', |
21 'Content-Length': str(len(network_unittest.HTML_BODY)), | 21 'Content-Length': str(len(network_unittest.HTML_BODY)), |
22 }, | 22 }, |
23 body=network_unittest.HTML_BODY) | 23 body=network_unittest.HTML_BODY) |
24 | 24 |
| 25 # A BlockOnce response not via proxy. |
| 26 EVENT_HTML_BLOCKONCE = ( |
| 27 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
| 28 url='http://check.googlezip.net/blocksingle/', |
| 29 response_headers={ |
| 30 'Content-Type': 'text/html', |
| 31 'Content-Length': str(len(network_unittest.HTML_BODY)), |
| 32 }, |
| 33 body=network_unittest.HTML_BODY)) |
| 34 |
25 # An HTML via proxy. | 35 # An HTML via proxy. |
26 EVENT_HTML_PROXY_VIA = ( | 36 EVENT_HTML_PROXY_VIA = ( |
27 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 37 network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
28 url='http://test.html2', | 38 url='http://test.html2', |
29 response_headers={ | 39 response_headers={ |
30 'Content-Type': 'text/html', | 40 'Content-Type': 'text/html', |
31 'Content-Encoding': 'gzip', | 41 'Content-Encoding': 'gzip', |
32 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), | 42 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)), |
33 'Via': '1.1 ' + common_metrics.CHROME_PROXY_VIA_HEADER, | 43 'Via': '1.1 ' + common_metrics.CHROME_PROXY_VIA_HEADER, |
34 }, | 44 }, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 metric.SetEvents([]) | 267 metric.SetEvents([]) |
258 no_responses_exception = False | 268 no_responses_exception = False |
259 try: | 269 try: |
260 metric.AddResultsForCorsBypass(None, results) | 270 metric.AddResultsForCorsBypass(None, results) |
261 except common_metrics.ChromeProxyMetricException: | 271 except common_metrics.ChromeProxyMetricException: |
262 no_responses_exception = True | 272 no_responses_exception = True |
263 self.assertTrue(no_responses_exception) | 273 self.assertTrue(no_responses_exception) |
264 | 274 |
265 def testChromeProxyMetricForBlockOnce(self): | 275 def testChromeProxyMetricForBlockOnce(self): |
266 metric = metrics.ChromeProxyMetric() | 276 metric = metrics.ChromeProxyMetric() |
267 metric.SetEvents([EVENT_HTML_DIRECT, | 277 metric.SetEvents([EVENT_HTML_BLOCKONCE, |
| 278 EVENT_HTML_BLOCKONCE, |
268 EVENT_IMAGE_PROXY_VIA]) | 279 EVENT_IMAGE_PROXY_VIA]) |
269 results = test_page_test_results.TestPageTestResults(self) | 280 results = test_page_test_results.TestPageTestResults(self) |
270 metric.AddResultsForBlockOnce(None, results) | 281 metric.AddResultsForBlockOnce(None, results) |
271 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) | 282 results.AssertHasPageSpecificScalarValue('eligible_responses', 'count', 2) |
272 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | |
273 | 283 |
274 metric.SetEvents([EVENT_HTML_DIRECT, | 284 metric.SetEvents([EVENT_HTML_BLOCKONCE, |
| 285 EVENT_HTML_BLOCKONCE, |
275 EVENT_IMAGE_DIRECT]) | 286 EVENT_IMAGE_DIRECT]) |
276 exception_occurred = False | 287 exception_occurred = False |
277 try: | 288 try: |
278 metric.AddResultsForBlockOnce(None, results) | 289 metric.AddResultsForBlockOnce(None, results) |
279 except common_metrics.ChromeProxyMetricException: | 290 except common_metrics.ChromeProxyMetricException: |
280 exception_occurred = True | 291 exception_occurred = True |
281 # The second response was over direct, but was expected via proxy. | 292 # The second response was over direct, but was expected via proxy. |
282 self.assertTrue(exception_occurred) | 293 self.assertTrue(exception_occurred) |
283 | 294 |
284 # Passing in zero responses should cause a failure. | 295 # Passing in zero responses should cause a failure. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 389 |
379 # Passing in zero responses should cause a failure. | 390 # Passing in zero responses should cause a failure. |
380 metric.SetEvents([]) | 391 metric.SetEvents([]) |
381 no_responses_exception = False | 392 no_responses_exception = False |
382 try: | 393 try: |
383 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') | 394 metric.AddResultsForHTTPToDirectFallback(None, results, 'test.html2') |
384 except common_metrics.ChromeProxyMetricException: | 395 except common_metrics.ChromeProxyMetricException: |
385 no_responses_exception = True | 396 no_responses_exception = True |
386 self.assertTrue(no_responses_exception) | 397 self.assertTrue(no_responses_exception) |
387 | 398 |
OLD | NEW |