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 import time | 9 import time |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 'document.body.scrollHeight') | 90 'document.body.scrollHeight') |
91 self.assertGreater(new_scroll_height, original_scroll_height) | 91 self.assertGreater(new_scroll_height, original_scroll_height) |
92 | 92 |
93 # Make sure there were more requests that were proxied. | 93 # Make sure there were more requests that were proxied. |
94 responses = test_driver.GetHTTPResponses(override_has_logs=True) | 94 responses = test_driver.GetHTTPResponses(override_has_logs=True) |
95 self.assertNotEqual(0, len(responses)) | 95 self.assertNotEqual(0, len(responses)) |
96 for response in responses: | 96 for response in responses: |
97 self.assertHasChromeProxyViaHeader(response) | 97 self.assertHasChromeProxyViaHeader(response) |
98 self.assertIn(response.status, [200, 204]) | 98 self.assertIn(response.status, [200, 204]) |
99 | 99 |
100 # Lo-Fi fallback is not currently supported via the client. Check that | 100 # Lo-Fi fallback is not supported without the |
101 # no Lo-Fi response is received if a Lite Page is not served. | 101 # DataReductionProxyDecidesTransform feature. Check that no Lo-Fi response |
102 def testLitePageFallback(self): | 102 # is received if a Lite Page is not served. |
| 103 def testLitePageNoFallback(self): |
103 with TestDriver() as test_driver: | 104 with TestDriver() as test_driver: |
104 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 105 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
105 test_driver.AddChromeArg('--force-fieldtrials=' | 106 test_driver.AddChromeArg('--force-fieldtrials=' |
106 'DataCompressionProxyLoFi/Enabled_Preview/') | 107 'DataCompressionProxyLoFi/Enabled_Preview/') |
107 test_driver.AddChromeArg('--force-fieldtrial-params=' | 108 test_driver.AddChromeArg('--force-fieldtrial-params=' |
108 'DataCompressionProxyLoFi.Enabled_Preview:' | 109 'DataCompressionProxyLoFi.Enabled_Preview:' |
109 'effective_connection_type/4G') | 110 'effective_connection_type/4G') |
110 test_driver.AddChromeArg('--force-net-effective-connection-type=2g') | 111 test_driver.AddChromeArg('--force-net-effective-connection-type=2g') |
111 | 112 |
112 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') | 113 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') |
(...skipping 14 matching lines...) Expand all Loading... |
127 if not response.url.endswith('png'): | 128 if not response.url.endswith('png'): |
128 continue | 129 continue |
129 | 130 |
130 # Lo-Fi fallback is not currently supported via the client. Check that | 131 # Lo-Fi fallback is not currently supported via the client. Check that |
131 # no Lo-Fi response is received. | 132 # no Lo-Fi response is received. |
132 self.checkLoFiResponse(response, False) | 133 self.checkLoFiResponse(response, False) |
133 | 134 |
134 # Verify that a Lite Page was requested. | 135 # Verify that a Lite Page was requested. |
135 self.assertEqual(1, lite_page_requests) | 136 self.assertEqual(1, lite_page_requests) |
136 | 137 |
| 138 # Verifies Lo-Fi fallback via the page-policies server directive. |
| 139 # Note: this test is for the CPAT protocol change in M-61. |
| 140 def testLitePageFallbackViaPagePolicies(self): |
| 141 with TestDriver() as test_driver: |
| 142 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 143 test_driver.AddChromeArg('--enable-features=' |
| 144 'DataReductionProxyDecidesTransform') |
| 145 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 146 'NetworkQualityEstimator.Enabled:' |
| 147 'force_effective_connection_type/Slow2G,' |
| 148 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 149 'effective_connection_type/2G') |
| 150 test_driver.AddChromeArg('--force-fieldtrials=' |
| 151 'NetworkQualityEstimator/Enabled/' |
| 152 'DataCompressionProxyLoFi/Enabled_Preview') |
| 153 |
| 154 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') |
| 155 |
| 156 lite_page_responses = 0 |
| 157 lofi_resource = 0 |
| 158 for response in test_driver.GetHTTPResponses(): |
| 159 self.assertEqual('Slow-2G', |
| 160 response.request_headers['chrome-proxy-ect']) |
| 161 |
| 162 if response.url.endswith('html'): |
| 163 # Verify that the server provides the fallback directive |
| 164 self.assertIn('page-policies=empty-image', |
| 165 response.response_headers['chrome-proxy']) |
| 166 # Main resource should not accept and transform to lite page. |
| 167 if self.checkLitePageResponse(response): |
| 168 lite_page_responses = lite_page_responses + 1 |
| 169 if response.url.endswith('png'): |
| 170 if self.checkLoFiResponse(response, True): |
| 171 lofi_resource = lofi_resource + 1 |
| 172 |
| 173 self.assertEqual(0, lite_page_responses) |
| 174 self.assertNotEqual(0, lofi_resource) |
| 175 self.assertNotEqual(0, lofi_resource) |
| 176 |
| 177 # Checks that the server provides Lite Page for a 2G connection. |
| 178 # Note: this test is for the CPAT protocol change in M-61. |
| 179 def testLitePageProvidedForSlowConnection(self): |
| 180 with TestDriver() as test_driver: |
| 181 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 182 test_driver.AddChromeArg('--enable-features=' |
| 183 'DataReductionProxyDecidesTransform') |
| 184 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 185 'NetworkQualityEstimator.Enabled:' |
| 186 'force_effective_connection_type/2G,' |
| 187 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 188 'effective_connection_type/2G') |
| 189 test_driver.AddChromeArg('--force-fieldtrials=' |
| 190 'NetworkQualityEstimator/Enabled/' |
| 191 'DataCompressionProxyLoFi/Enabled_Preview') |
| 192 |
| 193 test_driver.LoadURL('http://check.googlezip.net/test.html') |
| 194 |
| 195 lite_page_responses = 0 |
| 196 for response in test_driver.GetHTTPResponses(): |
| 197 self.assertEqual('2G', response.request_headers['chrome-proxy-ect']) |
| 198 if response.url.endswith('html'): |
| 199 if self.checkLitePageResponse(response): |
| 200 lite_page_responses = lite_page_responses + 1 |
| 201 # Expect no fallback page policy |
| 202 if 'chrome-proxy' in response.response_headers: |
| 203 self.assertNotIn('page-policies', |
| 204 response.response_headers['chrome-proxy']) |
| 205 else: |
| 206 # No subresources should accept transforms. |
| 207 self.assertNotIn('chrome-proxy-accept-transform', |
| 208 response.request_headers) |
| 209 |
| 210 self.assertEqual(1, lite_page_responses) |
| 211 |
| 212 # Checks that the server does not provide Lite Page nor fallback |
| 213 # for a fast connection. |
| 214 # Note: this test is for the CPAT protocol change in M-61. |
| 215 def testLitePageNotProvidedForFastConnection(self): |
| 216 with TestDriver() as test_driver: |
| 217 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 218 test_driver.AddChromeArg('--enable-features=' |
| 219 'DataReductionProxyDecidesTransform') |
| 220 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 221 'NetworkQualityEstimator.Enabled:' |
| 222 'force_effective_connection_type/4G,' |
| 223 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 224 'effective_connection_type/2G') |
| 225 test_driver.AddChromeArg('--force-fieldtrials=' |
| 226 'NetworkQualityEstimator/Enabled/' |
| 227 'DataCompressionProxyLoFi/Enabled_Preview') |
| 228 |
| 229 test_driver.LoadURL('http://check.googlezip.net/test.html') |
| 230 |
| 231 for response in test_driver.GetHTTPResponses(): |
| 232 self.assertEqual('4G', response.request_headers['chrome-proxy-ect']) |
| 233 if response.url.endswith('html'): |
| 234 # Main resource should accept lite page but not be transformed. |
| 235 self.assertEqual('lite-page', |
| 236 response.request_headers['chrome-proxy-accept-transform']) |
| 237 self.assertNotIn('chrome-proxy-content-transform', |
| 238 response.response_headers) |
| 239 # Expect no fallback page policy |
| 240 if 'chrome-proxy' in response.response_headers: |
| 241 self.assertNotIn('page-policies', |
| 242 response.response_headers['chrome-proxy']) |
| 243 else: |
| 244 # No subresources should accept transforms. |
| 245 self.assertNotIn('chrome-proxy-accept-transform', |
| 246 response.request_headers) |
| 247 |
| 248 # Verifies Lo-Fi fallback via the page-policies server directive. |
| 249 # Note: this test is for the CPAT protocol change in M-61. |
| 250 def testLitePageFallbackViaPagePolicies(self): |
| 251 with TestDriver() as test_driver: |
| 252 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 253 test_driver.AddChromeArg('--enable-features=' |
| 254 'DataReductionProxyDecidesTransform') |
| 255 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| 256 'NetworkQualityEstimator.Enabled:' |
| 257 'force_effective_connection_type/Slow2G,' |
| 258 'DataCompressionProxyLoFi.Enabled_Preview:' |
| 259 'effective_connection_type/2G') |
| 260 test_driver.AddChromeArg('--force-fieldtrials=' |
| 261 'NetworkQualityEstimator/Enabled/' |
| 262 'DataCompressionProxyLoFi/Enabled_Preview') |
| 263 |
| 264 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') |
| 265 |
| 266 lite_page_responses = 0 |
| 267 lofi_resource = 0 |
| 268 for response in test_driver.GetHTTPResponses(): |
| 269 self.assertEqual('Slow-2G', |
| 270 response.request_headers['chrome-proxy-ect']) |
| 271 |
| 272 if response.url.endswith('html'): |
| 273 # Verify that the server provides the fallback directive |
| 274 self.assertIn('page-policies=empty-image', |
| 275 response.response_headers['chrome-proxy']) |
| 276 # Main resource should not accept and transform to lite page. |
| 277 if self.checkLitePageResponse(response): |
| 278 lite_page_responses = lite_page_responses + 1 |
| 279 if response.url.endswith('png'): |
| 280 if self.checkLoFiResponse(response, True): |
| 281 lofi_resource = lofi_resource + 1 |
| 282 |
| 283 self.assertEqual(0, lite_page_responses) |
| 284 |
137 if __name__ == '__main__': | 285 if __name__ == '__main__': |
138 IntegrationTest.RunAllTests() | 286 IntegrationTest.RunAllTests() |
OLD | NEW |