summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbengr <bengr@chromium.org>2014-10-03 17:03:47 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-04 00:04:04 +0000
commit46b80798fc04651280742ec902ef3047936d2ef3 (patch)
treed7745321a93c24995492fb7650cb882b3ad6179a
parent67170fdcd3405a014144ae310f8ed5c0a83addb9 (diff)
downloadchromium_src-46b80798fc04651280742ec902ef3047936d2ef3.zip
chromium_src-46b80798fc04651280742ec902ef3047936d2ef3.tar.gz
chromium_src-46b80798fc04651280742ec902ef3047936d2ef3.tar.bz2
Integration test for CORS related data reduction proxy bypass
Added a test to verify that the bypass of a resource that requires CORS headers is reloaded without the data reduction proxy. BUG=418843 Review URL: https://codereview.chromium.org/621583002 Cr-Commit-Position: refs/heads/master@{#298127}
-rw-r--r--tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py6
-rw-r--r--tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py17
-rw-r--r--tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py45
-rw-r--r--tools/chrome_proxy/integration_tests/chrome_proxy_metrics_unittest.py32
-rw-r--r--tools/chrome_proxy/integration_tests/chrome_proxy_pagesets/corsbypass.py29
5 files changed, 129 insertions, 0 deletions
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py b/tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py
index a49f8bf..cd1a296 100644
--- a/tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py
@@ -83,6 +83,12 @@ class ChromeProxyBypass(benchmark.Benchmark):
page_set = pagesets.BypassPageSet
@benchmark.Enabled('android')
+class ChromeProxyCorsBypass(benchmark.Benchmark):
+ tag = 'bypass'
+ test = measurements.ChromeProxyCorsBypass
+ page_set = pagesets.CorsBypassPageSet
+
+@benchmark.Enabled('android')
class ChromeProxyBlockOnce(benchmark.Benchmark):
tag = 'block_once'
test = measurements.ChromeProxyBlockOnce
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py b/tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py
index 83e8060..00ba5b5 100644
--- a/tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py
@@ -112,6 +112,23 @@ class ChromeProxyBypass(ChromeProxyValidation):
self._metrics.AddResultsForBypass(tab, results)
+class ChromeProxyCorsBypass(ChromeProxyValidation):
+ """Correctness measurement for bypass responses."""
+
+ def __init__(self):
+ super(ChromeProxyCorsBypass, self).__init__(restart_after_each_page=True)
+
+ def ValidateAndMeasurePage(self, page, tab, results):
+ # The test page sets window.xhrRequestCompleted to true when the XHR fetch
+ # finishes.
+ tab.WaitForJavaScriptExpression('window.xhrRequestCompleted', 15000)
+ super(ChromeProxyCorsBypass,
+ self).ValidateAndMeasurePag1Ge(page, tab, results)
+
+ def AddResults(self, tab, results):
+ self._metrics.AddResultsForCorsBypass(tab, results)
+
+
class ChromeProxyBlockOnce(ChromeProxyValidation):
"""Correctness measurement for block-once responses."""
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
index 0302dd0..d211b17 100644
--- a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
@@ -248,6 +248,51 @@ class ChromeProxyMetric(network_metrics.NetworkMetric):
results.AddValue(scalar.ScalarValue(
results.current_page, 'bypass', 'count', bypass_count))
+ def AddResultsForCorsBypass(self, tab, results):
+ eligible_response_count = 0
+ bypass_count = 0
+ bypasses = {}
+ for resp in self.IterResponses(tab):
+ logging.warn('got a resource %s' % (resp.response.url))
+
+ for resp in self.IterResponses(tab):
+ if resp.ShouldHaveChromeProxyViaHeader():
+ eligible_response_count += 1
+ if not resp.HasChromeProxyViaHeader():
+ bypass_count += 1
+ elif resp.response.status == 502:
+ bypasses[resp.response.url] = 0
+
+ for resp in self.IterResponses(tab):
+ if resp.ShouldHaveChromeProxyViaHeader():
+ if not resp.HasChromeProxyViaHeader():
+ if resp.response.status == 200:
+ if (bypasses.has_key(resp.response.url)):
+ bypasses[resp.response.url] = bypasses[resp.response.url] + 1
+
+ for url in bypasses:
+ if bypasses[url] == 0:
+ raise ChromeProxyMetricException, (
+ '%s: Got a 502 without a subsequent 200' % (url))
+ elif bypasses[url] > 1:
+ raise ChromeProxyMetricException, (
+ '%s: Got a 502 and multiple 200s: %d' % (url, bypasses[url]))
+ if bypass_count == 0:
+ raise ChromeProxyMetricException, (
+ 'At least one response should be bypassed. '
+ '(eligible_response_count=%d, bypass_count=%d)\n' % (
+ eligible_response_count, bypass_count))
+ if tab:
+ info = GetProxyInfoFromNetworkInternals(tab)
+ if not info['enabled']:
+ raise ChromeProxyMetricException, (
+ 'Chrome proxy should be enabled. proxy info: %s' % info)
+ _, expected_bad_proxies = self.IsProxyBypassed(tab)
+ self.VerifyBadProxies(info['badProxies'], expected_bad_proxies)
+
+ results.AddValue(scalar.ScalarValue(
+ results.current_page, 'cors_bypass', 'count', bypass_count))
+
def AddResultsForBlockOnce(self, tab, results):
eligible_response_count = 0
bypass_count = 0
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics_unittest.py b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics_unittest.py
index 4fdb894..37fdb5f 100644
--- a/tools/chrome_proxy/integration_tests/chrome_proxy_metrics_unittest.py
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_metrics_unittest.py
@@ -69,6 +69,28 @@ EVENT_MALWARE_PROXY = (
},
status=307))
+# An HTML via proxy with the deprecated Via header.
+EVENT_IMAGE_BYPASS = (
+ network_unittest.NetworkMetricTest.MakeNetworkTimelineEvent(
+ url='http://test.image',
+ response_headers={
+ 'Chrome-Proxy': 'bypass=1',
+ 'Content-Type': 'text/html',
+ 'Via': '1.1 ' + metrics.CHROME_PROXY_VIA_HEADER,
+ },
+ status=502))
+
+# An image fetched directly.
+EVENT_IMAGE_DIRECT = (
+ 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))
+
class ChromeProxyMetricTest(unittest.TestCase):
@@ -175,6 +197,16 @@ class ChromeProxyMetricTest(unittest.TestCase):
metric.AddResultsForBypass(None, results)
results.AssertHasPageSpecificScalarValue('bypass', 'count', 1)
+ def testChromeProxyMetricForCorsBypass(self):
+ metric = metrics.ChromeProxyMetric()
+ metric.SetEvents([EVENT_HTML_PROXY_DEPRECATED_VIA,
+ EVENT_IMAGE_BYPASS,
+ EVENT_IMAGE_DIRECT])
+ results = test_page_test_results.TestPageTestResults(self)
+ metric.AddResultsForCorsBypass(None, results)
+ results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1)
+
+
def testChromeProxyMetricForHTTPFallback(self):
metric = metrics.ChromeProxyMetric()
metric.SetEvents([
diff --git a/tools/chrome_proxy/integration_tests/chrome_proxy_pagesets/corsbypass.py b/tools/chrome_proxy/integration_tests/chrome_proxy_pagesets/corsbypass.py
new file mode 100644
index 0000000..bb26412
--- /dev/null
+++ b/tools/chrome_proxy/integration_tests/chrome_proxy_pagesets/corsbypass.py
@@ -0,0 +1,29 @@
+# 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.
+
+from telemetry.page import page as page_module
+from telemetry.page import page_set as page_set_module
+
+
+class CorsBypassPage(page_module.Page):
+
+ def __init__(self, url, page_set):
+ super(CorsBypassPage, self).__init__(url=url, page_set=page_set)
+ self.archive_data_file = '../data/chrome_proxy_bypass.json'
+
+
+class CorsBypassPageSet(page_set_module.PageSet):
+
+ """ Chrome proxy test sites """
+
+ def __init__(self):
+ super(CorsBypassPageSet, self).__init__(
+ archive_data_file='../data/chrome_proxy_bypass.json')
+
+ urls_list = [
+ 'http://aws1.mdw.la/test/cors/',
+ ]
+
+ for url in urls_list:
+ self.AddPage(CorsBypassPage(url, self))