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): |
11 | 11 |
12 # Checks that the compressed image is below a certain threshold. | 12 # Checks that the compressed image is below a certain threshold. |
13 # The test page is uncacheable otherwise a cached page may be served that | 13 # The test page is uncacheable otherwise a cached page may be served that |
14 # doesn't have the correct via headers. | 14 # doesn't have the correct via headers. |
15 def testLoFi(self): | 15 def testLoFi(self): |
16 with TestDriver() as test_driver: | 16 with TestDriver() as test_driver: |
17 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 17 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
18 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') | 18 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') |
19 # Disable server experiments such as tamper detection. | 19 # Disable server experiments such as tamper detection. |
20 test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-' | 20 test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-' |
21 'disabled') | 21 'disabled') |
22 test_driver.AddChromeArg('--disable-quic') | |
23 | 22 |
24 test_driver.LoadURL('http://check.googlezip.net/static/index.html') | 23 test_driver.LoadURL('http://check.googlezip.net/static/index.html') |
25 | 24 |
26 lofi_responses = 0 | 25 lofi_responses = 0 |
27 for response in test_driver.GetHTTPResponses(): | 26 for response in test_driver.GetHTTPResponses(): |
28 if not response.url.endswith('png'): | 27 if not response.url.endswith('png'): |
29 continue | 28 continue |
30 if not response.request_headers: | 29 if not response.request_headers: |
31 continue | 30 continue |
32 self.assertHasChromeProxyViaHeader(response) | 31 if (self.assertLoFiResponse(response, True)): |
33 content_length = response.response_headers['content-length'] | |
34 cpat_request = response.request_headers['chrome-proxy-accept-transform'] | |
35 cpct_response = response.response_headers[ | |
36 'chrome-proxy-content-transform'] | |
37 if ('empty-image' in cpct_response): | |
38 lofi_responses = lofi_responses + 1 | 32 lofi_responses = lofi_responses + 1 |
39 self.assertIn('empty-image', cpat_request) | |
40 self.assertTrue(int(content_length) < 100) | |
41 | 33 |
42 # Verify that Lo-Fi responses were seen. | 34 # Verify that Lo-Fi responses were seen. |
43 self.assertNotEqual(0, lofi_responses) | 35 self.assertNotEqual(0, lofi_responses) |
44 | 36 |
45 # Checks that a Lite Page is served and that the ignore_preview_blacklist | 37 # Checks that a Lite Page is served and that the ignore_preview_blacklist |
46 # experiment is being used. | 38 # experiment is being used. |
47 def testLitePage(self): | 39 def testLitePage(self): |
48 with TestDriver() as test_driver: | 40 with TestDriver() as test_driver: |
49 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 41 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
50 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') | 42 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') |
(...skipping 16 matching lines...) Expand all Loading... |
67 self.assertHasChromeProxyViaHeader(response) | 59 self.assertHasChromeProxyViaHeader(response) |
68 self.assertIn('exp=ignore_preview_blacklist', | 60 self.assertIn('exp=ignore_preview_blacklist', |
69 chrome_proxy_request) | 61 chrome_proxy_request) |
70 if ('lite-page' in cpct_response): | 62 if ('lite-page' in cpct_response): |
71 lite_page_responses = lite_page_responses + 1 | 63 lite_page_responses = lite_page_responses + 1 |
72 self.assertIn('lite-page', cpat_request) | 64 self.assertIn('lite-page', cpat_request) |
73 | 65 |
74 # Verify that a Lite Page response for the main frame was seen. | 66 # Verify that a Lite Page response for the main frame was seen. |
75 self.assertEqual(1, lite_page_responses) | 67 self.assertEqual(1, lite_page_responses) |
76 | 68 |
| 69 # 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. |
| 71 # 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 |
| 73 # 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 |
| 75 # 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 |
| 77 # load should not pick the Lo-Fi placeholder from cache and original image |
| 78 # should be loaded. |
| 79 def testLoFiCacheBypass(self): |
| 80 with TestDriver() as test_driver: |
| 81 # First page load, enable Lo-Fi and chrome proxy. Disable server |
| 82 # experiments such as tamper detection. This test should be run with |
| 83 # --profile-type=default command line for the same user profile and cache |
| 84 # to be used across the two page loads. |
| 85 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 86 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') |
| 87 test_driver.AddChromeArg('--profile-type=default') |
| 88 test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-' |
| 89 'disabled') |
| 90 |
| 91 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 92 |
| 93 lofi_responses = 0 |
| 94 for response in test_driver.GetHTTPResponses(): |
| 95 if not response.url.endswith('png'): |
| 96 continue |
| 97 if not response.request_headers: |
| 98 continue |
| 99 if (self.assertLoFiResponse(response, True)): |
| 100 lofi_responses = lofi_responses + 1 |
| 101 |
| 102 # Verify that Lo-Fi responses were seen. |
| 103 self.assertNotEqual(0, lofi_responses) |
| 104 |
| 105 # Second page load with the chrome proxy off. |
| 106 test_driver._StopDriver() |
| 107 test_driver.RemoveChromeArg('--enable-spdy-proxy-auth') |
| 108 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 109 |
| 110 responses = 0 |
| 111 for response in test_driver.GetHTTPResponses(): |
| 112 if not response.url.endswith('png'): |
| 113 continue |
| 114 if not response.request_headers: |
| 115 continue |
| 116 responses = responses + 1 |
| 117 self.assertNotHasChromeProxyViaHeader(response) |
| 118 self.assertLoFiResponse(response, False) |
| 119 |
| 120 # Verify that responses were seen. |
| 121 self.assertNotEqual(0, responses) |
| 122 |
| 123 # Third page load with the chrome proxy on and Lo-Fi off. |
| 124 test_driver._StopDriver() |
| 125 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 126 test_driver.RemoveChromeArg('--data-reduction-proxy-lo-fi=always-on') |
| 127 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=disabled') |
| 128 test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html') |
| 129 |
| 130 responses = 0 |
| 131 for response in test_driver.GetHTTPResponses(): |
| 132 if not response.url.endswith('png'): |
| 133 continue |
| 134 if not response.request_headers: |
| 135 continue |
| 136 responses = responses + 1 |
| 137 self.assertHasChromeProxyViaHeader(response) |
| 138 self.assertLoFiResponse(response, False) |
| 139 |
| 140 # Verify that responses were seen. |
| 141 self.assertNotEqual(0, responses) |
| 142 |
77 if __name__ == '__main__': | 143 if __name__ == '__main__': |
78 IntegrationTest.RunAllTests() | 144 IntegrationTest.RunAllTests() |
OLD | NEW |