| 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 LitePage(IntegrationTest): | 10 class LitePage(IntegrationTest): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 test_driver.LoadURL('http://check.googlezip.net/test.html') | 24 test_driver.LoadURL('http://check.googlezip.net/test.html') |
| 25 | 25 |
| 26 lite_page_responses = 0 | 26 lite_page_responses = 0 |
| 27 for response in test_driver.GetHTTPResponses(): | 27 for response in test_driver.GetHTTPResponses(): |
| 28 # Skip CSI requests when validating Lite Page headers. CSI requests | 28 # Skip CSI requests when validating Lite Page headers. CSI requests |
| 29 # aren't expected to have LoFi headers. | 29 # aren't expected to have LoFi headers. |
| 30 if '/csi?' in response.url: | 30 if '/csi?' in response.url: |
| 31 continue | 31 continue |
| 32 if response.url.startswith('data:'): | 32 if response.url.startswith('data:'): |
| 33 continue | 33 continue |
| 34 self.assertIn('exp=ignore_preview_blacklist', | 34 # Main resource should force lite page. |
| 35 response.request_headers['chrome-proxy']) | 35 if response.url.endswith('html'): |
| 36 self.assertIn('exp=force_lite_page', |
| 37 response.request_headers['chrome-proxy']) |
| 36 if (self.checkLitePageResponse(response)): | 38 if (self.checkLitePageResponse(response)): |
| 37 lite_page_responses = lite_page_responses + 1 | 39 lite_page_responses = lite_page_responses + 1 |
| 38 | 40 |
| 39 # Verify that a Lite Page response for the main frame was seen. | 41 # Verify that a Lite Page response for the main frame was seen. |
| 40 self.assertEqual(1, lite_page_responses) | 42 self.assertEqual(1, lite_page_responses) |
| 41 | 43 |
| 42 # Checks that Lo-Fi images are used when the user is in the | 44 # Checks that Lo-Fi images are used when the user is in the |
| 43 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not | 45 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not |
| 44 # served. | 46 # served. |
| 45 def testLitePageFallback(self): | 47 def testLitePageFallback(self): |
| 46 with TestDriver() as test_driver: | 48 with TestDriver() as test_driver: |
| 47 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 49 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 50 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 51 'NetworkQualityEstimator.Enabled:' |
| 52 'force_effective_connection_type/Slow2G,' |
| 53 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 54 'effective_connection_type/4G') |
| 48 test_driver.AddChromeArg('--force-fieldtrials=' | 55 test_driver.AddChromeArg('--force-fieldtrials=' |
| 56 'NetworkQualityEstimator/Enabled/' |
| 49 'DataCompressionProxyLoFi/Enabled_Preview/' | 57 'DataCompressionProxyLoFi/Enabled_Preview/' |
| 50 'DataCompressionProxyLitePageFallback/Enabled') | 58 'DataCompressionProxyLitePageFallback/Enabled') |
| 51 test_driver.AddChromeArg('--force-fieldtrial-params=' | |
| 52 'DataCompressionProxyLoFi.Enabled_Preview:' | |
| 53 'effective_connection_type/4G') | |
| 54 test_driver.AddChromeArg('--force-net-effective-connection-type=2g') | |
| 55 | 59 |
| 56 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') | 60 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') |
| 57 | 61 |
| 58 lite_page_requests = 0 | 62 lite_page_requests = 0 |
| 59 lo_fi_responses = 0 | 63 lo_fi_responses = 0 |
| 60 for response in test_driver.GetHTTPResponses(): | 64 for response in test_driver.GetHTTPResponses(): |
| 61 if not response.request_headers: | 65 if not response.request_headers: |
| 62 continue | 66 continue |
| 63 | 67 |
| 68 self.assertEqual("Slow-2G", |
| 69 response.request_headers['chrome-proxy-ect']) |
| 70 |
| 64 cpat_request = response.request_headers['chrome-proxy-accept-transform'] | 71 cpat_request = response.request_headers['chrome-proxy-accept-transform'] |
| 65 if ('lite-page' in cpat_request): | 72 if ('lite-page' in cpat_request): |
| 66 lite_page_requests = lite_page_requests + 1 | 73 lite_page_requests = lite_page_requests + 1 |
| 67 self.assertFalse(self.checkLitePageResponse(response)) | 74 self.assertFalse(self.checkLitePageResponse(response)) |
| 68 | 75 |
| 69 if not response.url.endswith('png'): | 76 if not response.url.endswith('png'): |
| 70 continue | 77 continue |
| 71 | 78 |
| 72 if (self.checkLoFiResponse(response, True)): | 79 if (self.checkLoFiResponse(response, True)): |
| 73 lo_fi_responses = lo_fi_responses + 1 | 80 lo_fi_responses = lo_fi_responses + 1 |
| 74 | 81 |
| 75 # Verify that a Lite Page was requested and that the page fell back to | 82 # Verify that a Lite Page was requested and that the page fell back to |
| 76 # Lo-Fi images. | 83 # Lo-Fi images. |
| 77 self.assertEqual(1, lite_page_requests) | 84 self.assertEqual(1, lite_page_requests) |
| 78 self.assertEqual(1, lo_fi_responses) | 85 self.assertEqual(1, lo_fi_responses) |
| 79 | 86 |
| 80 # Checks that Lo-Fi images are not used when the user is not in the | 87 # Checks that Lo-Fi images are not used when the user is not in the |
| 81 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not | 88 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not |
| 82 # served. | 89 # served. |
| 83 def testLitePageNoFallback(self): | 90 def testLitePageNoFallback(self): |
| 84 with TestDriver() as test_driver: | 91 with TestDriver() as test_driver: |
| 85 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 92 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 86 # Lite Pages must be enabled via the field trial because the Lite Page | 93 # Lite Pages must be enabled via the field trial because the Lite Page |
| 87 # flag always falls back to Lo-Fi. | 94 # flag always falls back to Lo-Fi. |
| 88 test_driver.AddChromeArg('--force-fieldtrials=' | |
| 89 'DataCompressionProxyLoFi/Enabled_Preview') | |
| 90 test_driver.AddChromeArg('--force-fieldtrial-params=' | 95 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 96 'NetworkQualityEstimator.Enabled:' |
| 97 'force_effective_connection_type/Slow2G,' |
| 91 'DataCompressionProxyLoFi.Enabled_Preview:' | 98 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 92 'effective_connection_type/4G') | 99 'effective_connection_type/4G') |
| 93 test_driver.AddChromeArg('--force-net-effective-connection-type=2g') | 100 test_driver.AddChromeArg('--force-fieldtrials=' |
| 101 'NetworkQualityEstimator/Enabled/' |
| 102 'DataCompressionProxyLoFi/Enabled_Preview') |
| 94 | 103 |
| 95 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') | 104 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') |
| 96 | 105 |
| 97 lite_page_requests = 0 | 106 lite_page_requests = 0 |
| 98 for response in test_driver.GetHTTPResponses(): | 107 for response in test_driver.GetHTTPResponses(): |
| 99 if not response.request_headers: | 108 if not response.request_headers: |
| 100 continue | 109 continue |
| 101 | 110 |
| 111 self.assertEqual("Slow-2G", |
| 112 response.request_headers['chrome-proxy-ect']) |
| 113 |
| 102 if ('chrome-proxy-accept-transform' in response.request_headers): | 114 if ('chrome-proxy-accept-transform' in response.request_headers): |
| 103 cpat_request = response.request_headers[ | 115 cpat_request = response.request_headers[ |
| 104 'chrome-proxy-accept-transform'] | 116 'chrome-proxy-accept-transform'] |
| 105 if ('lite-page' in cpat_request): | 117 if ('lite-page' in cpat_request): |
| 106 lite_page_requests = lite_page_requests + 1 | 118 lite_page_requests = lite_page_requests + 1 |
| 107 self.assertFalse(self.checkLitePageResponse(response)) | 119 self.assertFalse(self.checkLitePageResponse(response)) |
| 108 | 120 |
| 109 if not response.url.endswith('png'): | 121 if not response.url.endswith('png'): |
| 110 continue | 122 continue |
| 111 | 123 |
| 112 self.checkLoFiResponse(response, False) | 124 self.checkLoFiResponse(response, False) |
| 113 | 125 |
| 114 # Verify that a Lite Page was requested and that the page fell back to | 126 # Verify that a Lite Page was requested and that the page fell back to |
| 115 # Lo-Fi images. | 127 # Lo-Fi images. |
| 116 self.assertEqual(1, lite_page_requests) | 128 self.assertEqual(1, lite_page_requests) |
| 117 | 129 |
| 118 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 119 IntegrationTest.RunAllTests() | 131 IntegrationTest.RunAllTests() |
| OLD | NEW |