Skip to content

Commit

Permalink
Add integration test to ensure correct usage of the Data Reduction Pr…
Browse files Browse the repository at this point in the history
…oxy config service.

BUG=475350

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

Cr-Commit-Position: refs/heads/master@{#334635}
  • Loading branch information
jeremyim authored and Commit bot committed Jun 16, 2015
1 parent 5cf8978 commit f997801
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
25 changes: 17 additions & 8 deletions tools/chrome_proxy/common/chrome_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ def IsValidByViaHeader(self):
return (not self.ShouldHaveChromeProxyViaHeader() or
self.HasChromeProxyViaHeader())

def GetChromeProxyClientType(self):
"""Get the client type directive from the Chrome-Proxy request header.
def GetChromeProxyRequestHeaderValue(self, key):
"""Get a specific Chrome-Proxy request header value.
Returns:
The client type directive from the Chrome-Proxy request header for the
request that lead to this response. For example, if the request header
"Chrome-Proxy: c=android" is present, then this method would return
"android". Returns None if no client type directive is present.
The value for a specific Chrome-Proxy request header value for a
given key. Returns None if no such key is present.
"""
if 'Chrome-Proxy' not in self.response.request_headers:
return None
Expand All @@ -84,15 +82,26 @@ def GetChromeProxyClientType(self):
values = [v.strip() for v in chrome_proxy_request_header.split(',')]
for value in values:
kvp = value.split('=', 1)
if len(kvp) == 2 and kvp[0].strip() == 'c':
if len(kvp) == 2 and kvp[0].strip() == key:
return kvp[1].strip()
return None

def GetChromeProxyClientType(self):
"""Get the client type directive from the Chrome-Proxy request header.
Returns:
The client type directive from the Chrome-Proxy request header for the
request that lead to this response. For example, if the request header
"Chrome-Proxy: c=android" is present, then this method would return
"android". Returns None if no client type directive is present.
"""
return self.GetChromeProxyRequestHeaderValue('c')

def HasChromeProxyLoFiRequest(self):
return self.HasRequestHeader('Chrome-Proxy', "q=low")

def HasChromeProxyLoFiResponse(self):
return self.HasResponseHeader('Chrome-Proxy', "q=low")

def HasChromeProxyPassThroughRequest(self):
return self.HasRequestHeader('Chrome-Proxy', "pass-through")
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 @@ -178,6 +178,16 @@ def Name(cls):
return 'chrome_proxy_benchmark.smoke.smoke'


class ChromeProxyClientConfig(ChromeProxyBenchmark):
tag = 'client_config'
test = measurements.ChromeProxyClientConfig
page_set = pagesets.SyntheticPageSet

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


@benchmark.Enabled(*DESKTOP_CHROME_BROWSERS)
class ChromeProxyVideoDirect(benchmark.Benchmark):
tag = 'video'
Expand Down
16 changes: 16 additions & 0 deletions tools/chrome_proxy/integration_tests/chrome_proxy_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ def AddResults(self, tab, results):
PROXIED = metrics.PROXIED
DIRECT = metrics.DIRECT

class ChromeProxyClientConfig(ChromeProxyValidation):
"""Chrome proxy client configuration service validation."""

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

def CustomizeBrowserOptions(self, options):
super(ChromeProxyClientConfig, self).CustomizeBrowserOptions(options)
options.AppendExtraBrowserArgs(
'--enable-data-reduction-proxy-config-client')

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

class ChromeProxyVideoValidation(page_test.PageTest):
"""Validation for video pages.
Expand Down
26 changes: 25 additions & 1 deletion tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,31 @@ def AddResultsForReenableAfterBypass(
results.AddValue(scalar.ScalarValue(
results.current_page, 'via', 'count', via_count))

def AddResultsForClientConfig(self, tab, results):
resources_with_old_auth = 0
resources_with_new_auth = 0

super(ChromeProxyMetric, self).AddResults(tab, results)
for resp in self.IterResponses(tab):
if resp.GetChromeProxyRequestHeaderValue('s') != None:
resources_with_new_auth += 1
if resp.GetChromeProxyRequestHeaderValue('ps') != None:
resources_with_old_auth += 1

if resources_with_old_auth != 0:
raise ChromeProxyMetricException, (
'Expected zero responses with the old authentication scheme but '
'received %d.' % resources_with_old_auth)

if resources_with_new_auth == 0:
raise ChromeProxyMetricException, (
'Expected at least one response with the new authentication scheme, '
'but zero such responses were received.')

results.AddValue(scalar.ScalarValue(
results.current_page, 'new_auth', 'count', resources_with_new_auth))
results.AddValue(scalar.ScalarValue(
results.current_page, 'old_auth', 'count', resources_with_old_auth))

PROXIED = 'proxied'
DIRECT = 'direct'
Expand Down Expand Up @@ -685,4 +710,3 @@ def err(s):
def IsTestUrlForBlockOnce(url):
return (url == 'http://check.googlezip.net/blocksingle/' or
url == 'http://chromeproxy-test.appspot.com/default?respBody=T0s=&respStatus=200&flywheelAction=block-once')

0 comments on commit f997801

Please sign in to comment.