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 integration_tests import chrome_proxy_metrics as metrics | 8 from integration_tests import chrome_proxy_metrics as metrics |
9 from integration_tests import network_metrics_unittest as network_unittest | 9 from integration_tests import network_metrics_unittest as network_unittest |
10 from metrics import test_page_measurement_results | 10 from metrics import test_page_test_results |
11 | 11 |
12 | 12 |
13 # Timeline events used in tests. | 13 # Timeline events used in tests. |
14 # An HTML not via proxy. | 14 # An HTML not via proxy. |
15 EVENT_HTML_PROXY = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( | 15 EVENT_HTML_PROXY = network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent( |
16 url='http://test.html1', | 16 url='http://test.html1', |
17 response_headers={ | 17 response_headers={ |
18 'Content-Type': 'text/html', | 18 'Content-Type': 'text/html', |
19 'Content-Length': str(len(network_unittest.HTML_BODY)), | 19 'Content-Length': str(len(network_unittest.HTML_BODY)), |
20 }, | 20 }, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 def testChromeProxyMetricForDataSaving(self): | 114 def testChromeProxyMetricForDataSaving(self): |
115 metric = metrics.ChromeProxyMetric() | 115 metric = metrics.ChromeProxyMetric() |
116 events = [ | 116 events = [ |
117 EVENT_HTML_PROXY, | 117 EVENT_HTML_PROXY, |
118 EVENT_HTML_PROXY_DEPRECATED_VIA, | 118 EVENT_HTML_PROXY_DEPRECATED_VIA, |
119 EVENT_IMAGE_PROXY_CACHED, | 119 EVENT_IMAGE_PROXY_CACHED, |
120 EVENT_IMAGE_DIRECT] | 120 EVENT_IMAGE_DIRECT] |
121 metric.SetEvents(events) | 121 metric.SetEvents(events) |
122 | 122 |
123 self.assertTrue(len(events), len(list(metric.IterResponses(None)))) | 123 self.assertTrue(len(events), len(list(metric.IterResponses(None)))) |
124 results = test_page_measurement_results.TestPageMeasurementResults(self) | 124 results = test_page_test_results.TestPageTestResults(self) |
125 | 125 |
126 metric.AddResultsForDataSaving(None, results) | 126 metric.AddResultsForDataSaving(None, results) |
127 results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2) | 127 results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2) |
128 results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1) | 128 results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1) |
129 results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2) | 129 results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2) |
130 | 130 |
131 def testChromeProxyMetricForHeaderValidation(self): | 131 def testChromeProxyMetricForHeaderValidation(self): |
132 metric = metrics.ChromeProxyMetric() | 132 metric = metrics.ChromeProxyMetric() |
133 metric.SetEvents([ | 133 metric.SetEvents([ |
134 EVENT_HTML_PROXY, | 134 EVENT_HTML_PROXY, |
135 EVENT_HTML_PROXY_DEPRECATED_VIA, | 135 EVENT_HTML_PROXY_DEPRECATED_VIA, |
136 EVENT_IMAGE_PROXY_CACHED, | 136 EVENT_IMAGE_PROXY_CACHED, |
137 EVENT_IMAGE_DIRECT]) | 137 EVENT_IMAGE_DIRECT]) |
138 | 138 |
139 results = test_page_measurement_results.TestPageMeasurementResults(self) | 139 results = test_page_test_results.TestPageTestResults(self) |
140 | 140 |
141 missing_via_exception = False | 141 missing_via_exception = False |
142 try: | 142 try: |
143 metric.AddResultsForHeaderValidation(None, results) | 143 metric.AddResultsForHeaderValidation(None, results) |
144 except metrics.ChromeProxyMetricException: | 144 except metrics.ChromeProxyMetricException: |
145 missing_via_exception = True | 145 missing_via_exception = True |
146 # Only the HTTP image response does not have a valid Via header. | 146 # Only the HTTP image response does not have a valid Via header. |
147 self.assertTrue(missing_via_exception) | 147 self.assertTrue(missing_via_exception) |
148 | 148 |
149 # Two events with valid Via headers. | 149 # Two events with valid Via headers. |
150 metric.SetEvents([ | 150 metric.SetEvents([ |
151 EVENT_HTML_PROXY_DEPRECATED_VIA, | 151 EVENT_HTML_PROXY_DEPRECATED_VIA, |
152 EVENT_IMAGE_PROXY_CACHED]) | 152 EVENT_IMAGE_PROXY_CACHED]) |
153 metric.AddResultsForHeaderValidation(None, results) | 153 metric.AddResultsForHeaderValidation(None, results) |
154 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) | 154 results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2) |
155 | 155 |
156 def testChromeProxyMetricForBypass(self): | 156 def testChromeProxyMetricForBypass(self): |
157 metric = metrics.ChromeProxyMetric() | 157 metric = metrics.ChromeProxyMetric() |
158 metric.SetEvents([ | 158 metric.SetEvents([ |
159 EVENT_HTML_PROXY, | 159 EVENT_HTML_PROXY, |
160 EVENT_HTML_PROXY_DEPRECATED_VIA, | 160 EVENT_HTML_PROXY_DEPRECATED_VIA, |
161 EVENT_IMAGE_PROXY_CACHED, | 161 EVENT_IMAGE_PROXY_CACHED, |
162 EVENT_IMAGE_DIRECT]) | 162 EVENT_IMAGE_DIRECT]) |
163 results = test_page_measurement_results.TestPageMeasurementResults(self) | 163 results = test_page_test_results.TestPageTestResults(self) |
164 | 164 |
165 bypass_exception = False | 165 bypass_exception = False |
166 try: | 166 try: |
167 metric.AddResultsForBypass(None, results) | 167 metric.AddResultsForBypass(None, results) |
168 except metrics.ChromeProxyMetricException: | 168 except metrics.ChromeProxyMetricException: |
169 bypass_exception = True | 169 bypass_exception = True |
170 # Two of the first three events have Via headers. | 170 # Two of the first three events have Via headers. |
171 self.assertTrue(bypass_exception) | 171 self.assertTrue(bypass_exception) |
172 | 172 |
173 # Use directly fetched image only. It is treated as bypassed. | 173 # Use directly fetched image only. It is treated as bypassed. |
174 metric.SetEvents([EVENT_IMAGE_DIRECT]) | 174 metric.SetEvents([EVENT_IMAGE_DIRECT]) |
175 metric.AddResultsForBypass(None, results) | 175 metric.AddResultsForBypass(None, results) |
176 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 176 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
177 | 177 |
178 def testChromeProxyMetricForHTTPFallback(self): | 178 def testChromeProxyMetricForHTTPFallback(self): |
179 metric = metrics.ChromeProxyMetric() | 179 metric = metrics.ChromeProxyMetric() |
180 metric.SetEvents([ | 180 metric.SetEvents([ |
181 EVENT_HTML_PROXY, | 181 EVENT_HTML_PROXY, |
182 EVENT_HTML_PROXY_DEPRECATED_VIA]) | 182 EVENT_HTML_PROXY_DEPRECATED_VIA]) |
183 results = test_page_measurement_results.TestPageMeasurementResults(self) | 183 results = test_page_test_results.TestPageTestResults(self) |
184 | 184 |
185 fallback_exception = False | 185 fallback_exception = False |
186 info = {} | 186 info = {} |
187 info['enabled'] = False | 187 info['enabled'] = False |
188 self._StubGetProxyInfo(info) | 188 self._StubGetProxyInfo(info) |
189 try: | 189 try: |
190 metric.AddResultsForBypass(None, results) | 190 metric.AddResultsForBypass(None, results) |
191 except metrics.ChromeProxyMetricException: | 191 except metrics.ChromeProxyMetricException: |
192 fallback_exception = True | 192 fallback_exception = True |
193 self.assertTrue(fallback_exception) | 193 self.assertTrue(fallback_exception) |
(...skipping 15 matching lines...) Expand all Loading... |
209 info['proxies'] = [ | 209 info['proxies'] = [ |
210 metrics.PROXY_SETTING_HTTP, | 210 metrics.PROXY_SETTING_HTTP, |
211 metrics.PROXY_SETTING_DIRECT | 211 metrics.PROXY_SETTING_DIRECT |
212 ] | 212 ] |
213 self._StubGetProxyInfo(info) | 213 self._StubGetProxyInfo(info) |
214 metric.AddResultsForHTTPFallback(None, results) | 214 metric.AddResultsForHTTPFallback(None, results) |
215 | 215 |
216 def testChromeProxyMetricForSafebrowsing(self): | 216 def testChromeProxyMetricForSafebrowsing(self): |
217 metric = metrics.ChromeProxyMetric() | 217 metric = metrics.ChromeProxyMetric() |
218 metric.SetEvents([EVENT_MALWARE_PROXY]) | 218 metric.SetEvents([EVENT_MALWARE_PROXY]) |
219 results = test_page_measurement_results.TestPageMeasurementResults(self) | 219 results = test_page_test_results.TestPageTestResults(self) |
220 | 220 |
221 metric.AddResultsForSafebrowsing(None, results) | 221 metric.AddResultsForSafebrowsing(None, results) |
222 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) | 222 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) |
223 | 223 |
224 # Clear results and metrics to test no response for safebrowsing | 224 # Clear results and metrics to test no response for safebrowsing |
225 results = test_page_measurement_results.TestPageMeasurementResults(self) | 225 results = test_page_test_results.TestPageTestResults(self) |
226 metric.SetEvents([]) | 226 metric.SetEvents([]) |
227 metric.AddResultsForSafebrowsing(None, results) | 227 metric.AddResultsForSafebrowsing(None, results) |
228 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) | 228 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) |
OLD | NEW |