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 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_test_results | 10 from metrics import test_page_test_results |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) | 198 results.AssertHasPageSpecificScalarValue('bypass', 'count', 1) |
| 199 | 199 |
| 200 def testChromeProxyMetricForCorsBypass(self): | 200 def testChromeProxyMetricForCorsBypass(self): |
| 201 metric = metrics.ChromeProxyMetric() | 201 metric = metrics.ChromeProxyMetric() |
| 202 metric.SetEvents([EVENT_HTML_PROXY_DEPRECATED_VIA, | 202 metric.SetEvents([EVENT_HTML_PROXY_DEPRECATED_VIA, |
| 203 EVENT_IMAGE_BYPASS, | 203 EVENT_IMAGE_BYPASS, |
| 204 EVENT_IMAGE_DIRECT]) | 204 EVENT_IMAGE_DIRECT]) |
| 205 results = test_page_test_results.TestPageTestResults(self) | 205 results = test_page_test_results.TestPageTestResults(self) |
| 206 metric.AddResultsForCorsBypass(None, results) | 206 metric.AddResultsForCorsBypass(None, results) |
| 207 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) | 207 results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1) |
| 208 | 208 |
|
bolian
2015/01/14 07:01:04
Also add test for the new funcs? At least add a T
sclittle
2015/01/14 19:20:51
Sure, I've added new unit tests, except for Reenab
| |
| 209 | |
| 210 def testChromeProxyMetricForHTTPFallback(self): | |
| 211 metric = metrics.ChromeProxyMetric() | |
| 212 metric.SetEvents([ | |
| 213 EVENT_HTML_PROXY, | |
| 214 EVENT_HTML_PROXY_DEPRECATED_VIA]) | |
| 215 results = test_page_test_results.TestPageTestResults(self) | |
| 216 | |
| 217 fallback_exception = False | |
| 218 info = {} | |
| 219 info['enabled'] = False | |
| 220 self._StubGetProxyInfo(info) | |
| 221 try: | |
| 222 metric.AddResultsForBypass(None, results) | |
| 223 except metrics.ChromeProxyMetricException: | |
| 224 fallback_exception = True | |
| 225 self.assertTrue(fallback_exception) | |
| 226 | |
| 227 fallback_exception = False | |
| 228 info['enabled'] = True | |
| 229 info['proxies'] = [ | |
| 230 'something.else.com:80', | |
| 231 metrics.PROXY_SETTING_DIRECT | |
| 232 ] | |
| 233 self._StubGetProxyInfo(info) | |
| 234 try: | |
| 235 metric.AddResultsForBypass(None, results) | |
| 236 except metrics.ChromeProxyMetricException: | |
| 237 fallback_exception = True | |
| 238 self.assertTrue(fallback_exception) | |
| 239 | |
| 240 info['enabled'] = True | |
| 241 info['proxies'] = [ | |
| 242 metrics.PROXY_SETTING_HTTP, | |
| 243 metrics.PROXY_SETTING_DIRECT | |
| 244 ] | |
| 245 self._StubGetProxyInfo(info) | |
| 246 metric.AddResultsForHTTPFallback(None, results) | |
| 247 | |
| 248 def testChromeProxyMetricForSafebrowsing(self): | 209 def testChromeProxyMetricForSafebrowsing(self): |
| 249 metric = metrics.ChromeProxyMetric() | 210 metric = metrics.ChromeProxyMetric() |
| 250 metric.SetEvents([EVENT_MALWARE_PROXY]) | 211 metric.SetEvents([EVENT_MALWARE_PROXY]) |
| 251 results = test_page_test_results.TestPageTestResults(self) | 212 results = test_page_test_results.TestPageTestResults(self) |
| 252 | 213 |
| 253 metric.AddResultsForSafebrowsing(None, results) | 214 metric.AddResultsForSafebrowsing(None, results) |
| 254 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) | 215 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) |
| 255 | 216 |
| 256 # Clear results and metrics to test no response for safebrowsing | 217 # Clear results and metrics to test no response for safebrowsing |
| 257 results = test_page_test_results.TestPageTestResults(self) | 218 results = test_page_test_results.TestPageTestResults(self) |
| 258 metric.SetEvents([]) | 219 metric.SetEvents([]) |
| 259 metric.AddResultsForSafebrowsing(None, results) | 220 metric.AddResultsForSafebrowsing(None, results) |
| 260 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) | 221 results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True) |
| OLD | NEW |