Skip to content

Commit

Permalink
Integration test for retrying POSTs with block-once.
Browse files Browse the repository at this point in the history
BUG=471877

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

Cr-Commit-Position: refs/heads/master@{#331619}
  • Loading branch information
kundaji authored and Commit bot committed May 27, 2015
1 parent c1bcfae commit 25e4d8e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
48 changes: 31 additions & 17 deletions tools/chrome_proxy/integration_tests/chrome_proxy_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,30 +375,37 @@ def AddResultsForCorsBypass(self, tab, results):

def AddResultsForBlockOnce(self, tab, results):
eligible_response_count = 0
bypass_count = 0
via_proxy = 0

for resp in self.IterResponses(tab):
if resp.ShouldHaveChromeProxyViaHeader():
# Block-once test URLs (Data Reduction Proxy always returns
# block-once) should not have the Chrome-Compression-Proxy Via header.
if (IsTestUrlForBlockOnce(resp.response.url)):
eligible_response_count += 1
if resp.HasChromeProxyViaHeader():
raise ChromeProxyMetricException, (
'Response has a Chrome-Compression-Proxy Via header: ' +
resp.response.url)
elif resp.ShouldHaveChromeProxyViaHeader():
via_proxy += 1
if not resp.HasChromeProxyViaHeader():
bypass_count += 1
# For all other URLs, confirm that via header is present if expected.
raise ChromeProxyMetricException, (
'Missing Chrome-Compression-Proxy Via header.' +
resp.response.url)

if eligible_response_count <= 1:
if via_proxy == 0:
raise ChromeProxyMetricException, (
'There should be more than one DRP eligible response '
'(eligible_response_count=%d, bypass_count=%d)\n' % (
eligible_response_count, bypass_count))
elif bypass_count != 1:
'None of the requests went via data reduction proxy')

if (eligible_response_count != 2):
raise ChromeProxyMetricException, (
'Exactly one response should be bypassed. '
'(eligible_response_count=%d, bypass_count=%d)\n' % (
eligible_response_count, bypass_count))
else:
results.AddValue(scalar.ScalarValue(
results.current_page, 'eligible_responses', 'count',
eligible_response_count))
results.AddValue(scalar.ScalarValue(
results.current_page, 'bypass', 'count', bypass_count))
'Did not make expected number of requests to whitelisted block-once'
' test URLs. Expected: 2, Actual: ' + str(eligible_response_count))

results.AddValue(scalar.ScalarValue(results.current_page,
'BlockOnce_success', 'num_eligible_response', 2))


def AddResultsForSafebrowsingOn(self, tab, results):
results.AddValue(scalar.ScalarValue(
Expand Down Expand Up @@ -672,3 +679,10 @@ def err(s):
for (k,v) in self.videoMetrics.iteritems():
k = "%s_%s" % (k, kind)
results.AddValue(scalar.ScalarValue(results.current_page, k, "", v))

# Returns whether |url| is a block-once test URL. Data Reduction Proxy has been
# configured to always return block-once for these URLs.
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')

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ class BlockOncePage(page_module.Page):
def __init__(self, url, page_set):
super(BlockOncePage, self).__init__(url=url, page_set=page_set)

def RunNavigateSteps(self, action_runner):
super(BlockOncePage, self).RunNavigateSteps(action_runner)
# Test block-once on a POST request.
# Ensure that a subsequent request uses the data reduction proxy.
action_runner.ExecuteJavaScript('''
(function() {
var request = new XMLHttpRequest();
request.open("POST",
"http://chromeproxy-test.appspot.com/default?respBody=T0s=&respStatus=200&flywheelAction=block-once");
request.onload = function() {
var viaProxyRequest = new XMLHttpRequest();
viaProxyRequest.open("GET",
"http://check.googlezip.net/image.png");
viaProxyRequest.send();
};
request.send();
})();
''')
action_runner.Wait(1)

class BlockOncePageSet(page_set_module.PageSet):

Expand All @@ -19,6 +38,7 @@ class BlockOncePageSet(page_set_module.PageSet):
def __init__(self):
super(BlockOncePageSet, self).__init__()

# Test block-once for a GET request.
urls_list = [
'http://check.googlezip.net/blocksingle',
]
Expand Down

0 comments on commit 25e4d8e

Please sign in to comment.