Skip to content

Commit

Permalink
Integration tests for WebLite to Lo-Fi fallback
Browse files Browse the repository at this point in the history
Test that the DataCompressionProxyLitePageFallback field trial requests
Lo-Fi images when a Lite Page is not returned. Also check that when the
user is not in the field trial, Lo-Fi images are not requested.

Seperate the Lo-Fi and WebLite test files.

BUG=660212

Review-Url: https://codereview.chromium.org/2726423003
Cr-Commit-Position: refs/heads/master@{#454724}
(cherry picked from commit a9a7fa9)

Review-Url: https://codereview.chromium.org/2729773007 .
Cr-Commit-Position: refs/branch-heads/3029@{#7}
Cr-Branched-From: 939b32e-refs/heads/master@{#454471}
  • Loading branch information
Megan Jablonski committed Mar 4, 2017
1 parent e1725ef commit 1767195
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 41 deletions.
34 changes: 29 additions & 5 deletions tools/chrome_proxy/webdriver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,12 @@ def assertNotHasChromeProxyViaHeader(self, http_response):
self.assertNotIn(expected_via_header,
http_response.response_headers['via'])

def assertLoFiResponse(self, http_response, expected_lo_fi):
"""Asserts that the response and request headers contain the given directive
and the content size is less than 100 if |expected_lo_fi|. Otherwise, checks
that the response and request headers don't contain the Lo-Fi directive and
the content size is greater than 100.
def checkLoFiResponse(self, http_response, expected_lo_fi):
"""Asserts that if expected the response headers contain the Lo-Fi directive
then the request headers do too. Also checks that the content size is less
than 100 if |expected_lo_fi|. Otherwise, checks that the response and
request headers don't contain the Lo-Fi directive and the content size is
greater than 100.
Args:
http_response: The HTTPResponse object to check.
Expand Down Expand Up @@ -613,6 +614,29 @@ def assertLoFiResponse(self, http_response, expected_lo_fi):
self.assertTrue(int(content_length) > 100)
return False;

def checkLitePageResponse(self, http_response):
"""Asserts that if the response headers contain the Lite Page directive then
the request headers do too.
Args:
http_response: The HTTPResponse object to check.
Returns:
Whether the response was a Lite Page.
"""

self.assertHasChromeProxyViaHeader(http_response)
if ('chrome-proxy-content-transform' not in http_response.response_headers):
return False;
cpct_response = http_response.response_headers[
'chrome-proxy-content-transform']
cpat_request = http_response.request_headers[
'chrome-proxy-accept-transform']
if ('lite-page' in cpct_response):
self.assertIn('lite-page', cpat_request)
return True;
return False;

@staticmethod
def RunAllTests(run_all_tests=False):
"""A simple helper method to run all tests using unittest.main().
Expand Down
115 changes: 115 additions & 0 deletions tools/chrome_proxy/webdriver/lite_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright 2017 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.

import common
from common import TestDriver
from common import IntegrationTest


class LitePage(IntegrationTest):

# Checks that a Lite Page is served and that the ignore_preview_blacklist
# experiment is being used.
def testLitePage(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')

test_driver.LoadURL('http://check.googlezip.net/test.html')

lite_page_responses = 0
for response in test_driver.GetHTTPResponses():
# Skip CSI requests when validating Lite Page headers. CSI requests
# aren't expected to have LoFi headers.
if '/csi?' in response.url:
continue
if response.url.startswith('data:'):
continue
self.assertIn('exp=ignore_preview_blacklist',
response.request_headers['chrome-proxy'])
if (self.checkLitePageResponse(response)):
lite_page_responses = lite_page_responses + 1

# Verify that a Lite Page response for the main frame was seen.
self.assertEqual(1, lite_page_responses)

# Checks that Lo-Fi images are used when the user is in the
# DataCompressionProxyLitePageFallback field trial and a Lite Page is not
# served.
def testLitePageFallback(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--force-fieldtrials='
'DataCompressionProxyLoFi/Enabled_Preview/'
'DataCompressionProxyLitePageFallback/Enabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'DataCompressionProxyLoFi.Enabled_Preview:'
'effective_connection_type/4G')
test_driver.AddChromeArg('--force-net-effective-connection-type=2g')

test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback')

lite_page_requests = 0
lo_fi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.request_headers:
continue

cpat_request = response.request_headers['chrome-proxy-accept-transform']
if ('lite-page' in cpat_request):
lite_page_requests = lite_page_requests + 1
self.assertFalse(self.checkLitePageResponse(response))

if not response.url.endswith('png'):
continue

if (self.checkLoFiResponse(response, True)):
lo_fi_responses = lo_fi_responses + 1

# Verify that a Lite Page was requested and that the page fell back to
# Lo-Fi images.
self.assertEqual(1, lite_page_requests)
self.assertEqual(1, lo_fi_responses)

# Checks that Lo-Fi images are not used when the user is not in the
# DataCompressionProxyLitePageFallback field trial and a Lite Page is not
# served.
def testLitePageNoFallback(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
# Lite Pages must be enabled via the field trial because the Lite Page
# flag always falls back to Lo-Fi.
test_driver.AddChromeArg('--force-fieldtrials='
'DataCompressionProxyLoFi/Enabled_Preview')
test_driver.AddChromeArg('--force-fieldtrial-params='
'DataCompressionProxyLoFi.Enabled_Preview:'
'effective_connection_type/4G')
test_driver.AddChromeArg('--force-net-effective-connection-type=2g')

test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback')

lite_page_requests = 0
for response in test_driver.GetHTTPResponses():
if not response.request_headers:
continue

if ('chrome-proxy-accept-transform' in response.request_headers):
cpat_request = response.request_headers[
'chrome-proxy-accept-transform']
if ('lite-page' in cpat_request):
lite_page_requests = lite_page_requests + 1
self.assertFalse(self.checkLitePageResponse(response))

if not response.url.endswith('png'):
continue

self.checkLoFiResponse(response, False)

# Verify that a Lite Page was requested and that the page fell back to
# Lo-Fi images.
self.assertEqual(1, lite_page_requests)

if __name__ == '__main__':
IntegrationTest.RunAllTests()
40 changes: 4 additions & 36 deletions tools/chrome_proxy/webdriver/lofi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,12 @@ def testLoFi(self):
continue
if not response.request_headers:
continue
if (self.assertLoFiResponse(response, True)):
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1

# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)

# Checks that a Lite Page is served and that the ignore_preview_blacklist
# experiment is being used.
def testLitePage(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')

test_driver.LoadURL('http://check.googlezip.net/test.html')

lite_page_responses = 0
for response in test_driver.GetHTTPResponses():
# Skip CSI requests when validating Lite Page headers. CSI requests
# aren't expected to have LoFi headers.
if '/csi?' in response.url:
continue
if response.url.startswith('data:'):
continue
chrome_proxy_request = response.request_headers['chrome-proxy']
cpat_request = response.request_headers['chrome-proxy-accept-transform']
cpct_response = response.response_headers[
'chrome-proxy-content-transform']
self.assertHasChromeProxyViaHeader(response)
self.assertIn('exp=ignore_preview_blacklist',
chrome_proxy_request)
if ('lite-page' in cpct_response):
lite_page_responses = lite_page_responses + 1
self.assertIn('lite-page', cpat_request)

# Verify that a Lite Page response for the main frame was seen.
self.assertEqual(1, lite_page_responses)

# Checks that Lo-Fi placeholder images are not loaded from cache on page
# reloads when Lo-Fi mode is disabled or data reduction proxy is disabled.
# First a test page is opened with Lo-Fi and chrome proxy enabled. This allows
Expand Down Expand Up @@ -96,7 +64,7 @@ def testLoFiCacheBypass(self):
continue
if not response.request_headers:
continue
if (self.assertLoFiResponse(response, True)):
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1

# Verify that Lo-Fi responses were seen.
Expand All @@ -115,7 +83,7 @@ def testLoFiCacheBypass(self):
continue
responses = responses + 1
self.assertNotHasChromeProxyViaHeader(response)
self.assertLoFiResponse(response, False)
self.checkLoFiResponse(response, False)

# Verify that responses were seen.
self.assertNotEqual(0, responses)
Expand All @@ -135,7 +103,7 @@ def testLoFiCacheBypass(self):
continue
responses = responses + 1
self.assertHasChromeProxyViaHeader(response)
self.assertLoFiResponse(response, False)
self.checkLoFiResponse(response, False)

# Verify that responses were seen.
self.assertNotEqual(0, responses)
Expand Down

0 comments on commit 1767195

Please sign in to comment.