Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: tools/perf/metrics/chrome_proxy_unittest.py

Issue 191383003: First cut of chrome-proxy (data reduction proxy) measurements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved out test_page_measurement_results.py to network.py CL. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/perf/metrics/chrome_proxy.py ('K') | « tools/perf/metrics/chrome_proxy.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/metrics/chrome_proxy_unittest.py
diff --git a/tools/perf/metrics/chrome_proxy_unittest.py b/tools/perf/metrics/chrome_proxy_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..096b5e7c1b0dfe65170e71dfbd1b88179e3e01a6
--- /dev/null
+++ b/tools/perf/metrics/chrome_proxy_unittest.py
@@ -0,0 +1,161 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import base64
+import unittest
+
+from metrics import chrome_proxy
+from metrics import network_unittest
+from metrics import test_page_measurement_results
+
+
+_EVENTS = [
+ # An HTML not via proxy.
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.html1',
+ response_headers={
+ 'Content-Type': 'text/html',
+ 'Content-Length': str(len(network_unittest.HTML_BODY)),
+ },
+ body=network_unittest.HTML_BODY),
+
+ # An HTML via proxy with old Via header.
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.html2',
+ response_headers={
+ 'Content-Type': 'text/html',
+ 'Content-Encoding': 'gzip',
+ 'X-Original-Content-Length': str(len(network_unittest.HTML_BODY)),
+ 'Via': chrome_proxy.CHROME_PROXY_VIA_HEADER_OLD + ',other-via',
+ },
+ body=network_unittest.HTML_BODY),
+
+ # An image via proxy with Via header and it is cached.
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.image',
+ response_headers={
+ 'Content-Type': 'image/jpeg',
+ 'Content-Encoding': 'gzip',
+ 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL),
+ 'Via': '1.1 ' + chrome_proxy.CHROME_PROXY_VIA_HEADER,
+ },
+ body=base64.b64encode(network_unittest.IMAGE_BODY),
+ base64_encoded_body=True,
+ served_from_cache=True),
+
+ # An image fetched directly.
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.image',
+ response_headers={
+ 'Content-Type': 'image/jpeg',
+ 'Content-Encoding': 'gzip',
+ },
+ body=base64.b64encode(network_unittest.IMAGE_BODY),
+ base64_encoded_body=True),
+
+ # A safe-browsing malware response.
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.malware',
+ response_headers={
+ 'X-Malware-Url': '1',
+ 'Via': '1.1 ' + chrome_proxy.CHROME_PROXY_VIA_HEADER,
+ 'Location': 'http://test.malware',
+ },
+ status=307),
+ ]
+
+
+class ChromeProxyMetricTest(unittest.TestCase):
+ def testChromeProxyResponse(self):
+ # An https non-proxy response.
+ resp = chrome_proxy.ChromeProxyResponse(
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='https://test.url',
+ response_headers={
+ 'Content-Type': 'text/html',
+ 'Content-Length': str(len(network_unittest.HTML_BODY)),
+ 'Via': 'some other via',
+ },
+ body=network_unittest.HTML_BODY))
+ self.assertFalse(resp.ShouldHaveChromeProxyViaHeader())
+ self.assertFalse(resp.HasChromeProxyViaHeader())
+ self.assertTrue(resp.IsValidByViaHeader())
+
+ # A proxied JPEG image response
+ resp = chrome_proxy.ChromeProxyResponse(
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.image',
+ response_headers={
+ 'Content-Type': 'image/jpeg',
+ 'Content-Encoding': 'gzip',
+ 'Via': '1.1 ' + chrome_proxy.CHROME_PROXY_VIA_HEADER,
+ 'X-Original-Content-Length': str(network_unittest.IMAGE_OCL),
+ },
+ body=base64.b64encode(network_unittest.IMAGE_BODY),
+ base64_encoded_body=True))
+ self.assertTrue(resp.ShouldHaveChromeProxyViaHeader())
+ self.assertTrue(resp.HasChromeProxyViaHeader())
+ self.assertTrue(resp.IsValidByViaHeader())
+
+ def testChromePrxoyMetricForDataSaving(self):
bengr 2014/03/26 22:45:55 Proxy
bolian 2014/03/27 00:43:32 Done.
+ metric = chrome_proxy.ChromeProxyMetric()
+ metric._events = _EVENTS[:4]
+
+ self.assertTrue(len(_EVENTS[:4]), len(list(metric.IterResponses(None))))
+ results = test_page_measurement_results.TestPageMeasurementResults(self)
+
+ metric.AddResultsForDataSaving(None, results)
+ results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2)
+ results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1)
+ results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2)
+
+ def testChromePrxoyMetricForHeaderValidation(self):
bengr 2014/03/26 22:45:55 Proxy
bolian 2014/03/27 00:43:32 Done.
+ metric = chrome_proxy.ChromeProxyMetric()
+ metric._events = _EVENTS[:4]
+ results = test_page_measurement_results.TestPageMeasurementResults(self)
+
+ missing_via_exception = False
+ try:
+ metric.AddResultsForHeaderValidation(None, results)
+ except chrome_proxy.ChromeProxyMetricException:
+ missing_via_exception = True
+ # Only the HTTP image response does not have a valid Via header.
+ self.assertTrue(missing_via_exception)
+
+ # Two events with valid Via headers.
+ metric._events = _EVENTS[1:3]
+ metric.AddResultsForHeaderValidation(None, results)
+ results.AssertHasPageSpecificScalarValue('checked_via_header', 'count', 2)
+
+ def testChromePrxoyMetricForBypass(self):
bengr 2014/03/26 22:45:55 Proxy
bolian 2014/03/27 00:43:32 Done.
+ metric = chrome_proxy.ChromeProxyMetric()
+ metric._events = _EVENTS[:4]
+ results = test_page_measurement_results.TestPageMeasurementResults(self)
+
+ bypass_exception = False
+ try:
+ metric.AddResultsForBypass(None, results)
+ except chrome_proxy.ChromeProxyMetricException:
+ bypass_exception = True
+ # Two of the first three events have Via headers.
+ self.assertTrue(bypass_exception)
+
+ # Use directly fetched image only. It is treated as bypassed.
+ metric._events = _EVENTS[3:4]
+ metric.AddResultsForBypass(None, results)
+ results.AssertHasPageSpecificScalarValue('bypass', 'count', 1)
+
+ def testChromePrxoyMetricForSafebrowsing(self):
bengr 2014/03/26 22:45:55 Proxy
bolian 2014/03/27 00:43:32 Done.
+ metric = chrome_proxy.ChromeProxyMetric()
+ metric._events = _EVENTS[4:]
+ results = test_page_measurement_results.TestPageMeasurementResults(self)
+
+ metric.AddResultsForSafebrowsing(None, results)
+ results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True)
+
+ # Clear results and metrics to test no response for safebrowsing
+ results = test_page_measurement_results.TestPageMeasurementResults(self)
+ metric._events = []
+ metric.AddResultsForSafebrowsing(None, results)
+ results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True)
« tools/perf/metrics/chrome_proxy.py ('K') | « tools/perf/metrics/chrome_proxy.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698