| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import common | 5 import common |
| 6 from common import TestDriver | 6 from common import TestDriver |
| 7 from common import IntegrationTest | 7 from common import IntegrationTest |
| 8 | 8 |
| 9 | 9 |
| 10 class LoFi(IntegrationTest): | 10 class LoFi(IntegrationTest): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 'disabled') | 21 'disabled') |
| 22 | 22 |
| 23 test_driver.LoadURL('http://check.googlezip.net/static/index.html') | 23 test_driver.LoadURL('http://check.googlezip.net/static/index.html') |
| 24 | 24 |
| 25 lofi_responses = 0 | 25 lofi_responses = 0 |
| 26 for response in test_driver.GetHTTPResponses(): | 26 for response in test_driver.GetHTTPResponses(): |
| 27 if not response.url.endswith('png'): | 27 if not response.url.endswith('png'): |
| 28 continue | 28 continue |
| 29 if not response.request_headers: | 29 if not response.request_headers: |
| 30 continue | 30 continue |
| 31 if (self.assertLoFiResponse(response, True)): | 31 if (self.checkLoFiResponse(response, True)): |
| 32 lofi_responses = lofi_responses + 1 | 32 lofi_responses = lofi_responses + 1 |
| 33 | 33 |
| 34 # Verify that Lo-Fi responses were seen. | 34 # Verify that Lo-Fi responses were seen. |
| 35 self.assertNotEqual(0, lofi_responses) | 35 self.assertNotEqual(0, lofi_responses) |
| 36 | 36 |
| 37 # Checks that a Lite Page is served and that the ignore_preview_blacklist | |
| 38 # experiment is being used. | |
| 39 def testLitePage(self): | |
| 40 with TestDriver() as test_driver: | |
| 41 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | |
| 42 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') | |
| 43 test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page') | |
| 44 | |
| 45 test_driver.LoadURL('http://check.googlezip.net/test.html') | |
| 46 | |
| 47 lite_page_responses = 0 | |
| 48 for response in test_driver.GetHTTPResponses(): | |
| 49 # Skip CSI requests when validating Lite Page headers. CSI requests | |
| 50 # aren't expected to have LoFi headers. | |
| 51 if '/csi?' in response.url: | |
| 52 continue | |
| 53 if response.url.startswith('data:'): | |
| 54 continue | |
| 55 chrome_proxy_request = response.request_headers['chrome-proxy'] | |
| 56 cpat_request = response.request_headers['chrome-proxy-accept-transform'] | |
| 57 cpct_response = response.response_headers[ | |
| 58 'chrome-proxy-content-transform'] | |
| 59 self.assertHasChromeProxyViaHeader(response) | |
| 60 self.assertIn('exp=ignore_preview_blacklist', | |
| 61 chrome_proxy_request) | |
| 62 if ('lite-page' in cpct_response): | |
| 63 lite_page_responses = lite_page_responses + 1 | |
| 64 self.assertIn('lite-page', cpat_request) | |
| 65 | |
| 66 # Verify that a Lite Page response for the main frame was seen. | |
| 67 self.assertEqual(1, lite_page_responses) | |
| 68 | |
| 69 # Checks that Lo-Fi placeholder images are not loaded from cache on page | 37 # Checks that Lo-Fi placeholder images are not loaded from cache on page |
| 70 # reloads when Lo-Fi mode is disabled or data reduction proxy is disabled. | 38 # reloads when Lo-Fi mode is disabled or data reduction proxy is disabled. |
| 71 # First a test page is opened with Lo-Fi and chrome proxy enabled. This allows | 39 # First a test page is opened with Lo-Fi and chrome proxy enabled. This allows |
| 72 # Chrome to cache the Lo-Fi placeholder image. The browser is restarted with | 40 # Chrome to cache the Lo-Fi placeholder image. The browser is restarted with |
| 73 # chrome proxy disabled and the same test page is loaded. This second page | 41 # chrome proxy disabled and the same test page is loaded. This second page |
| 74 # load should not pick the Lo-Fi placeholder from cache and original image | 42 # load should not pick the Lo-Fi placeholder from cache and original image |
| 75 # should be loaded. Finally, the browser is restarted with chrome proxy | 43 # should be loaded. Finally, the browser is restarted with chrome proxy |
| 76 # enabled and Lo-Fi disabled and the same test page is loaded. This third page | 44 # enabled and Lo-Fi disabled and the same test page is loaded. This third page |
| 77 # load should not pick the Lo-Fi placeholder from cache and original image | 45 # load should not pick the Lo-Fi placeholder from cache and original image |
| 78 # should be loaded. | 46 # should be loaded. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 89 'disabled') | 57 'disabled') |
| 90 | 58 |
| 91 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') | 59 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 92 | 60 |
| 93 lofi_responses = 0 | 61 lofi_responses = 0 |
| 94 for response in test_driver.GetHTTPResponses(): | 62 for response in test_driver.GetHTTPResponses(): |
| 95 if not response.url.endswith('png'): | 63 if not response.url.endswith('png'): |
| 96 continue | 64 continue |
| 97 if not response.request_headers: | 65 if not response.request_headers: |
| 98 continue | 66 continue |
| 99 if (self.assertLoFiResponse(response, True)): | 67 if (self.checkLoFiResponse(response, True)): |
| 100 lofi_responses = lofi_responses + 1 | 68 lofi_responses = lofi_responses + 1 |
| 101 | 69 |
| 102 # Verify that Lo-Fi responses were seen. | 70 # Verify that Lo-Fi responses were seen. |
| 103 self.assertNotEqual(0, lofi_responses) | 71 self.assertNotEqual(0, lofi_responses) |
| 104 | 72 |
| 105 # Second page load with the chrome proxy off. | 73 # Second page load with the chrome proxy off. |
| 106 test_driver._StopDriver() | 74 test_driver._StopDriver() |
| 107 test_driver.RemoveChromeArg('--enable-spdy-proxy-auth') | 75 test_driver.RemoveChromeArg('--enable-spdy-proxy-auth') |
| 108 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') | 76 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 109 | 77 |
| 110 responses = 0 | 78 responses = 0 |
| 111 for response in test_driver.GetHTTPResponses(): | 79 for response in test_driver.GetHTTPResponses(): |
| 112 if not response.url.endswith('png'): | 80 if not response.url.endswith('png'): |
| 113 continue | 81 continue |
| 114 if not response.request_headers: | 82 if not response.request_headers: |
| 115 continue | 83 continue |
| 116 responses = responses + 1 | 84 responses = responses + 1 |
| 117 self.assertNotHasChromeProxyViaHeader(response) | 85 self.assertNotHasChromeProxyViaHeader(response) |
| 118 self.assertLoFiResponse(response, False) | 86 self.checkLoFiResponse(response, False) |
| 119 | 87 |
| 120 # Verify that responses were seen. | 88 # Verify that responses were seen. |
| 121 self.assertNotEqual(0, responses) | 89 self.assertNotEqual(0, responses) |
| 122 | 90 |
| 123 # Third page load with the chrome proxy on and Lo-Fi off. | 91 # Third page load with the chrome proxy on and Lo-Fi off. |
| 124 test_driver._StopDriver() | 92 test_driver._StopDriver() |
| 125 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 93 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 126 test_driver.RemoveChromeArg('--data-reduction-proxy-lo-fi=always-on') | 94 test_driver.RemoveChromeArg('--data-reduction-proxy-lo-fi=always-on') |
| 127 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=disabled') | 95 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=disabled') |
| 128 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') | 96 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 129 | 97 |
| 130 responses = 0 | 98 responses = 0 |
| 131 for response in test_driver.GetHTTPResponses(): | 99 for response in test_driver.GetHTTPResponses(): |
| 132 if not response.url.endswith('png'): | 100 if not response.url.endswith('png'): |
| 133 continue | 101 continue |
| 134 if not response.request_headers: | 102 if not response.request_headers: |
| 135 continue | 103 continue |
| 136 responses = responses + 1 | 104 responses = responses + 1 |
| 137 self.assertHasChromeProxyViaHeader(response) | 105 self.assertHasChromeProxyViaHeader(response) |
| 138 self.assertLoFiResponse(response, False) | 106 self.checkLoFiResponse(response, False) |
| 139 | 107 |
| 140 # Verify that responses were seen. | 108 # Verify that responses were seen. |
| 141 self.assertNotEqual(0, responses) | 109 self.assertNotEqual(0, responses) |
| 142 | 110 |
| 143 if __name__ == '__main__': | 111 if __name__ == '__main__': |
| 144 IntegrationTest.RunAllTests() | 112 IntegrationTest.RunAllTests() |
| OLD | NEW |