Commit d2e45539 authored by megjablon's avatar megjablon Committed by Commit bot

Integration test for “lo-fi” mode in Chrome-Proxy request header

A telemetry test that checks for "q=low" in the Chrome-Proxy
request header and verifies that the image received was less than 100 bytes.

BUG=449665

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

Cr-Commit-Position: refs/heads/master@{#318926}
parent 0cca591a
...@@ -16,9 +16,6 @@ class ChromeProxyLatency(benchmark.Benchmark): ...@@ -16,9 +16,6 @@ class ChromeProxyLatency(benchmark.Benchmark):
def Name(cls): def Name(cls):
return 'chrome_proxy_benchmark.latency.top_20' return 'chrome_proxy_benchmark.latency.top_20'
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
class ChromeProxyLatencyDirect(benchmark.Benchmark): class ChromeProxyLatencyDirect(benchmark.Benchmark):
tag = 'latency_direct' tag = 'latency_direct'
...@@ -55,9 +52,6 @@ class ChromeProxyDataSaving(benchmark.Benchmark): ...@@ -55,9 +52,6 @@ class ChromeProxyDataSaving(benchmark.Benchmark):
def Name(cls): def Name(cls):
return 'chrome_proxy_benchmark.data_saving.top_20' return 'chrome_proxy_benchmark.data_saving.top_20'
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
class ChromeProxyDataSavingDirect(benchmark.Benchmark): class ChromeProxyDataSavingDirect(benchmark.Benchmark):
tag = 'data_saving_direct' tag = 'data_saving_direct'
...@@ -115,6 +109,16 @@ class ChromeProxyClientType(benchmark.Benchmark): ...@@ -115,6 +109,16 @@ class ChromeProxyClientType(benchmark.Benchmark):
return 'chrome_proxy_benchmark.client_type.client_type' return 'chrome_proxy_benchmark.client_type.client_type'
class ChromeProxyLoFi(benchmark.Benchmark):
tag = 'lo_fi'
test = measurements.ChromeProxyLoFi
page_set = pagesets.LoFiPageSet
@classmethod
def Name(cls):
return 'chrome_proxy_benchmark.lo_fi.lo_fi'
class ChromeProxyBypass(benchmark.Benchmark): class ChromeProxyBypass(benchmark.Benchmark):
tag = 'bypass' tag = 'bypass'
test = measurements.ChromeProxyBypass test = measurements.ChromeProxyBypass
......
...@@ -18,6 +18,9 @@ class ChromeProxyLatency(page_test.PageTest): ...@@ -18,6 +18,9 @@ class ChromeProxyLatency(page_test.PageTest):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ChromeProxyLatency, self).__init__(*args, **kwargs) super(ChromeProxyLatency, self).__init__(*args, **kwargs)
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
def WillNavigateToPage(self, page, tab): def WillNavigateToPage(self, page, tab):
tab.ClearCache(force=True) tab.ClearCache(force=True)
...@@ -28,11 +31,14 @@ class ChromeProxyLatency(page_test.PageTest): ...@@ -28,11 +31,14 @@ class ChromeProxyLatency(page_test.PageTest):
class ChromeProxyDataSaving(page_test.PageTest): class ChromeProxyDataSaving(page_test.PageTest):
"""Chrome proxy data daving measurement.""" """Chrome proxy data saving measurement."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ChromeProxyDataSaving, self).__init__(*args, **kwargs) super(ChromeProxyDataSaving, self).__init__(*args, **kwargs)
self._metrics = metrics.ChromeProxyMetric() self._metrics = metrics.ChromeProxyMetric()
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs('--enable-spdy-proxy-auth')
def WillNavigateToPage(self, page, tab): def WillNavigateToPage(self, page, tab):
tab.ClearCache(force=True) tab.ClearCache(force=True)
self._metrics.Start(page, tab) self._metrics.Start(page, tab)
...@@ -287,6 +293,20 @@ class ChromeProxyClientType(ChromeProxyValidation): ...@@ -287,6 +293,20 @@ class ChromeProxyClientType(ChromeProxyValidation):
self._page.bypass_for_client_type) self._page.bypass_for_client_type)
class ChromeProxyLoFi(ChromeProxyValidation):
"""Correctness measurement for Lo-Fi in Chrome-Proxy header."""
def __init__(self):
super(ChromeProxyLoFi, self).__init__(restart_after_each_page=True)
def CustomizeBrowserOptions(self, options):
super(ChromeProxyLoFi, self).CustomizeBrowserOptions(options)
options.AppendExtraBrowserArgs('--enable-data-reduction-proxy-lo-fi')
def AddResults(self, tab, results):
self._metrics.AddResultsForLoFi(tab, results)
class ChromeProxyHTTPToDirectFallback(ChromeProxyValidation): class ChromeProxyHTTPToDirectFallback(ChromeProxyValidation):
"""Correctness measurement for HTTP proxy fallback to direct.""" """Correctness measurement for HTTP proxy fallback to direct."""
......
...@@ -71,6 +71,15 @@ class ChromeProxyResponse(network_metrics.HTTPResponse): ...@@ -71,6 +71,15 @@ class ChromeProxyResponse(network_metrics.HTTPResponse):
return kvp[1].strip() return kvp[1].strip()
return None return None
def HasChromeProxyLoFi(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(',')]
for value in values:
if len(value) == 5 and value == 'q=low':
return True
return False
class ChromeProxyMetric(network_metrics.NetworkMetric): class ChromeProxyMetric(network_metrics.NetworkMetric):
"""A Chrome proxy timeline metric.""" """A Chrome proxy timeline metric."""
...@@ -180,6 +189,39 @@ class ChromeProxyMetric(network_metrics.NetworkMetric): ...@@ -180,6 +189,39 @@ class ChromeProxyMetric(network_metrics.NetworkMetric):
results.AddValue(scalar.ScalarValue( results.AddValue(scalar.ScalarValue(
results.current_page, 'bypass', 'count', bypass_count)) results.current_page, 'bypass', 'count', bypass_count))
def AddResultsForLoFi(self, tab, results):
lo_fi_count = 0
for resp in self.IterResponses(tab):
if resp.HasChromeProxyViaHeader():
lo_fi_count += 1
else:
r = resp.response
raise ChromeProxyMetricException, (
'%s: LoFi not in request header.' % (r.url))
cl = resp.content_length
resource = resp.response.url
results.AddValue(scalar.ScalarValue(
results.current_page, 'lo_fi', 'count', lo_fi_count))
for resp in self.IterResponses(tab):
r = resp.response
cl = resp.content_length
ocl = resp.original_content_length
saving = resp.data_saving_rate * 100
if cl > 100:
raise ChromeProxyMetricException, (
'Image %s is %d bytes. Expecting less than 100 bytes.' %
(resource, cl))
results.AddValue(scalar.ScalarValue(
results.current_page, 'content_length', 'bytes', cl))
results.AddValue(scalar.ScalarValue(
results.current_page, 'original_content_length', 'bytes', ocl))
results.AddValue(scalar.ScalarValue(
results.current_page, 'data_saving', 'percent', saving))
def AddResultsForBypass(self, tab, results): def AddResultsForBypass(self, tab, results):
bypass_count = 0 bypass_count = 0
......
# 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 LoFiPage(page_module.Page):
"""
A test page for the chrome proxy Lo-Fi tests.
Checks that the compressed image is below a certain threshold.
"""
def __init__(self, url, page_set):
super(LoFiPage, self).__init__(url=url, page_set=page_set)
class LoFiPageSet(page_set_module.PageSet):
""" Chrome proxy test sites """
def __init__(self):
super(LoFiPageSet, self).__init__()
urls_list = [
'http://aws1.mdw.la/fw/buddy.jpg',
]
for url in urls_list:
self.AddUserStory(LoFiPage(url, self))
...@@ -98,9 +98,10 @@ class HTTPResponse(object): ...@@ -98,9 +98,10 @@ class HTTPResponse(object):
try: try:
cl = self.GetContentLengthFromBody() cl = self.GetContentLengthFromBody()
except Exception, e: except Exception, e:
resp = self.response
logging.warning('Fail to get content length for %s from body: %s', logging.warning('Fail to get content length for %s from body: %s',
resp.url[:100], e) self.response.url[:100], e)
if cl == 0:
resp = self.response
cl_header = resp.GetHeader('Content-Length') cl_header = resp.GetHeader('Content-Length')
if cl_header: if cl_header:
cl = int(cl_header) cl = int(cl_header)
...@@ -170,7 +171,7 @@ class NetworkMetric(Metric): ...@@ -170,7 +171,7 @@ class NetworkMetric(Metric):
ocl = resp.original_content_length ocl = resp.original_content_length
if ocl < cl: if ocl < cl:
logging.warning('original content length (%d) is less than content ' logging.warning('original content length (%d) is less than content '
'lenght(%d) for resource %s', ocl, cl, resource) 'length (%d) for resource %s', ocl, cl, resource)
if self.add_result_for_resource: if self.add_result_for_resource:
results.AddValue(scalar.ScalarValue( results.AddValue(scalar.ScalarValue(
results.current_page, results.current_page,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment