Skip to content

Commit

Permalink
Integration test for Chrome-Proxy: pass-through directive
Browse files Browse the repository at this point in the history
Checks that an image loaded with the Chrome-Proxy: pass-through directive
is larger than the compressed image from the Data Reduction Proxy.

BUG=490397

Review URL: https://codereview.chromium.org/1151753003

Cr-Commit-Position: refs/heads/master@{#331028}
  • Loading branch information
megjablon authored and Commit bot committed May 21, 2015
1 parent 480e30a commit 91e5715
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 15 deletions.
35 changes: 20 additions & 15 deletions tools/chrome_proxy/common/chrome_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def ShouldHaveChromeProxyViaHeader(self):
return False
return True

def HasResponseHeader(self, key, value):
response_header = self.response.GetHeader(key)
if not response_header:
return False
values = [v.strip() for v in response_header.split(',')]
return any(v == value for v in values)

def HasRequestHeader(self, key, value):
if key not in self.response.request_headers:
return False
request_header = self.response.request_headers[key]
values = [v.strip() for v in request_header.split(',')]
return any(v == value for v in values)

def HasChromeProxyViaHeader(self):
via_header = self.response.GetHeader('Via')
if not via_header:
Expand All @@ -48,11 +62,7 @@ def HasChromeProxyViaHeader(self):
return any(v[4:] == CHROME_PROXY_VIA_HEADER for v in vias)

def HasExtraViaHeader(self, extra_header):
via_header = self.response.GetHeader('Via')
if not via_header:
return False
vias = [v.strip(' ') for v in via_header.split(',')]
return any(v == extra_header for v in vias)
return self.HasResponseHeader('Via', extra_header)

def IsValidByViaHeader(self):
return (not self.ShouldHaveChromeProxyViaHeader() or
Expand All @@ -79,15 +89,10 @@ def GetChromeProxyClientType(self):
return None

def HasChromeProxyLoFiRequest(self):
if 'Chrome-Proxy' not in self.response.request_headers:
return False
chrome_proxy_request_header = self.response.request_headers['Chrome-Proxy']
values = [v.strip() for v in chrome_proxy_request_header.split(',')]
return any(v == "q=low" for v in values)
return self.HasRequestHeader('Chrome-Proxy', "q=low")

def HasChromeProxyLoFiResponse(self):
chrome_proxy_response_header = self.response.GetHeader('Chrome-Proxy')
if not chrome_proxy_response_header:
return False
values = [v.strip() for v in chrome_proxy_response_header.split(',')]
return any(v == "q=low" for v in values)
return self.HasResponseHeader('Chrome-Proxy', "q=low")

def HasChromeProxyPassThroughRequest(self):
return self.HasRequestHeader('Chrome-Proxy', "pass-through")
10 changes: 10 additions & 0 deletions tools/chrome_proxy/integration_tests/chrome_proxy_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def Name(cls):
return 'chrome_proxy_benchmark.exp_directive.exp_directive'


class ChromeProxyPassThrough(ChromeProxyBenchmark):
tag = 'pass_through'
test = measurements.ChromeProxyPassThrough
page_set = pagesets.PassThroughPageSet

@classmethod
def Name(cls):
return 'chrome_proxy_benchmark.pass_through.pass_through'


class ChromeProxyBypass(ChromeProxyBenchmark):
tag = 'bypass'
test = measurements.ChromeProxyBypass
Expand Down
17 changes: 17 additions & 0 deletions tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ def CustomizeBrowserOptions(self, options):
def AddResults(self, tab, results):
self._metrics.AddResultsForBypass(tab, results, url_pattern='/exptest/')

class ChromeProxyPassThrough(ChromeProxyValidation):
"""Correctness measurement for Chrome-Proxy pass-through directives.
This test verifies that "pass-through" in the Chrome-Proxy request header
causes a resource to be loaded without Data Reduction Proxy transformations.
"""

def __init__(self):
super(ChromeProxyPassThrough, self).__init__(
restart_after_each_page=True,
metrics=metrics.ChromeProxyMetric())

def CustomizeBrowserOptions(self, options):
super(ChromeProxyPassThrough, self).CustomizeBrowserOptions(options)

def AddResults(self, tab, results):
self._metrics.AddResultsForPassThrough(tab, results)

class ChromeProxyHTTPToDirectFallback(ChromeProxyValidation):
"""Correctness measurement for HTTP proxy fallback to direct."""
Expand Down
46 changes: 46 additions & 0 deletions tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,52 @@ def AddResultsForLoFi(self, tab, results):
results.current_page, 'lo_fi_response', 'count', lo_fi_response_count))
super(ChromeProxyMetric, self).AddResults(tab, results)

def AddResultsForPassThrough(self, tab, results):
compressed_count = 0
compressed_size = 0
pass_through_count = 0
pass_through_size = 0

for resp in self.IterResponses(tab):
if 'favicon.ico' in resp.response.url:
continue
if not resp.HasChromeProxyViaHeader():
r = resp.response
raise ChromeProxyMetricException, (
'%s: Should have Via header (%s) (refer=%s, status=%d)' % (
r.url, r.GetHeader('Via'), r.GetHeader('Referer'), r.status))
if resp.HasChromeProxyPassThroughRequest():
pass_through_count += 1
pass_through_size = resp.content_length
else:
compressed_count += 1
compressed_size = resp.content_length

if pass_through_count != 1:
raise ChromeProxyMetricException, (
'Expected exactly one Chrome-Proxy pass-through request, but %d '
'such requests were sent.' % (pass_through_count))

if compressed_count != 1:
raise ChromeProxyMetricException, (
'Expected exactly one compressed request, but %d such requests were '
'received.' % (compressed_count))

if compressed_size >= pass_through_size:
raise ChromeProxyMetricException, (
'Compressed image is %d bytes and pass-through image is %d. '
'Expecting compressed image size to be less than pass-through '
'image.' % (compressed_size, pass_through_size))

results.AddValue(scalar.ScalarValue(
results.current_page, 'compressed', 'count', compressed_count))
results.AddValue(scalar.ScalarValue(
results.current_page, 'compressed_size', 'bytes', compressed_size))
results.AddValue(scalar.ScalarValue(
results.current_page, 'pass_through', 'count', pass_through_count))
results.AddValue(scalar.ScalarValue(
results.current_page, 'pass_through_size', 'bytes', pass_through_size))

def AddResultsForBypass(self, tab, results, url_pattern=""):
bypass_count = 0
skipped_count = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2015 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 PassThroughPage(page_module.Page):
"""
A test page for the chrome proxy pass-through tests.
"""

def __init__(self, url, page_set):
super(PassThroughPage, self).__init__(url=url, page_set=page_set)

def RunNavigateSteps(self, action_runner):
super(PassThroughPage, self).RunNavigateSteps(action_runner)
action_runner.ExecuteJavaScript('''
(function() {
var request = new XMLHttpRequest();
request.open("GET", "%s");
request.setRequestHeader("Chrome-Proxy", "pass-through");
request.send(null);
})();''' % (self.url))
action_runner.Wait(1)


class PassThroughPageSet(page_set_module.PageSet):
""" Chrome proxy test sites """

def __init__(self):
super(PassThroughPageSet, self).__init__()

urls_list = [
'http://check.googlezip.net/image.png',
]

for url in urls_list:
self.AddUserStory(PassThroughPage(url, self))

0 comments on commit 91e5715

Please sign in to comment.