Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: tools/chrome_proxy/webdriver/lite_page.py

Issue 2802843003: Update CPAT protocol to send lite-page transform acceptance with ect
Patch Set: Merge with testLitePageBTF Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 class LitePage(IntegrationTest): 11 class LitePage(IntegrationTest):
12 12
13 # Checks that a Lite Page is served and that the ignore_preview_blacklist 13 # Checks that a Lite Page is served and the force_lite_page experiment
14 # experiment is being used. 14 # provided when always-on.
bengr 2017/05/01 16:53:15 is provided?
15 def testLitePage(self): 15 def testLitePageForcedExperiment(self):
16 # If it was attempted to run with another experiment, skip this test. 16 # If it was attempted to run with another experiment, skip this test.
17 if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment' 17 if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment'
18 in common.ParseFlags().browser_args): 18 in common.ParseFlags().browser_args):
19 self.skipTest('This test cannot be run with other experiments.') 19 self.skipTest('This test cannot be run with other experiments.')
20 with TestDriver() as test_driver: 20 with TestDriver() as test_driver:
21 test_driver.AddChromeArg('--enable-spdy-proxy-auth') 21 test_driver.AddChromeArg('--enable-spdy-proxy-auth')
22 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') 22 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
23 test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page') 23 test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')
24 24
25 test_driver.LoadURL('http://check.googlezip.net/test.html') 25 test_driver.LoadURL('http://check.googlezip.net/test.html')
26 26
27 lite_page_responses = 0 27 lite_page_responses = 0
28 for response in test_driver.GetHTTPResponses(): 28 for response in test_driver.GetHTTPResponses():
29 # Skip CSI requests when validating Lite Page headers. CSI requests 29 # Skip CSI requests when validating Lite Page headers. CSI requests
30 # aren't expected to have LoFi headers. 30 # aren't expected to have LoFi headers.
31 if '/csi?' in response.url: 31 if '/csi?' in response.url:
32 continue 32 continue
33 if response.url.startswith('data:'): 33 if response.url.startswith('data:'):
34 continue 34 continue
35 self.assertIn('exp=ignore_preview_blacklist', 35 # Main resource should force lite page.
36 response.request_headers['chrome-proxy']) 36 if response.url.endswith('html'):
37 self.assertIn('exp=force_lite_page',
38 response.request_headers['chrome-proxy'])
37 if (self.checkLitePageResponse(response)): 39 if (self.checkLitePageResponse(response)):
38 lite_page_responses = lite_page_responses + 1 40 lite_page_responses = lite_page_responses + 1
39 41
40 # Verify that a Lite Page response for the main frame was seen. 42 # Verify that a Lite Page response for the main frame was seen.
41 self.assertEqual(1, lite_page_responses) 43 self.assertEqual(1, lite_page_responses)
42 44
43 # Checks that a Lite Page does not have an error when scrolling to the bottom 45 # Checks that a Lite Page does not have an error when scrolling to the bottom
44 # of the page and is able to load all resources. 46 # of the page and is able to load all resources.
45 def testLitePageBTF(self): 47 def testLitePageBTF(self):
46 # If it was attempted to run with another experiment, skip this test. 48 # If it was attempted to run with another experiment, skip this test.
(...skipping 10 matching lines...) Expand all
57 59
58 # Verify that a Lite Page response for the main frame was seen. 60 # Verify that a Lite Page response for the main frame was seen.
59 lite_page_responses = 0 61 lite_page_responses = 0
60 for response in test_driver.GetHTTPResponses(): 62 for response in test_driver.GetHTTPResponses():
61 # Skip CSI requests when validating Lite Page headers. CSI requests 63 # Skip CSI requests when validating Lite Page headers. CSI requests
62 # aren't expected to have LoFi headers. 64 # aren't expected to have LoFi headers.
63 if '/csi?' in response.url: 65 if '/csi?' in response.url:
64 continue 66 continue
65 if response.url.startswith('data:'): 67 if response.url.startswith('data:'):
66 continue 68 continue
67 self.assertIn('exp=ignore_preview_blacklist', 69 self.assertIn('exp=force_lite_page',
68 response.request_headers['chrome-proxy']) 70 response.request_headers['chrome-proxy'])
69 if (self.checkLitePageResponse(response)): 71 if (self.checkLitePageResponse(response)):
70 lite_page_responses = lite_page_responses + 1 72 lite_page_responses = lite_page_responses + 1
71 self.assertEqual(1, lite_page_responses) 73 self.assertEqual(1, lite_page_responses)
72 74
73 # Scroll to the bottom of the window and make sure there were more 75 # Scroll to the bottom of the window and make sure there were more
74 # requests that were proxied. 76 # requests that were proxied.
75 scroll_js = 'window.scrollTo(0,Math.max(document.body.scrollHeight));' 77 scroll_js = 'window.scrollTo(0,Math.max(document.body.scrollHeight));'
76 test_driver.ExecuteJavascriptStatement(scroll_js) 78 test_driver.ExecuteJavascriptStatement(scroll_js)
77 # Give some time for loading after each scroll. 79 # Give some time for loading after each scroll.
78 time.sleep(2) 80 time.sleep(2)
79 test_driver.ExecuteJavascriptStatement(scroll_js) 81 test_driver.ExecuteJavascriptStatement(scroll_js)
80 time.sleep(2) 82 time.sleep(2)
81 responses = test_driver.GetHTTPResponses(override_has_logs=True) 83 responses = test_driver.GetHTTPResponses(override_has_logs=True)
82 self.assertNotEqual(0, len(responses)) 84 self.assertNotEqual(0, len(responses))
83 for response in responses: 85 for response in responses:
84 self.assertHasChromeProxyViaHeader(response) 86 self.assertHasChromeProxyViaHeader(response)
85 87
88 # Checks that the server provides Lite Page for slow connection.
89 def testLitePageForSlowConnection(self):
90 with TestDriver() as test_driver:
91 test_driver.AddChromeArg('--enable-spdy-proxy-auth')
92 test_driver.AddChromeArg('--force-fieldtrial-params='
93 'NetworkQualityEstimator.Enabled:'
94 'force_effective_connection_type/Slow2G,'
95 'DataCompressionProxyLoFi.Enabled_Preview:'
96 'effective_connection_type/2G')
97 test_driver.AddChromeArg('--force-fieldtrials='
98 'NetworkQualityEstimator/Enabled/'
99 'DataCompressionProxyLoFi/Enabled_Preview/'
100 'DataCompressionProxyLitePageFallback/Enabled')
101
102 test_driver.LoadURL('http://check.googlezip.net/test.html')
103
104
105 lite_page_responses = 0
106 for response in test_driver.GetHTTPResponses():
107 self.assertEqual('Slow-2G',
108 response.request_headers['chrome-proxy-ect'])
109
110 if response.url.endswith('html'):
111 # Main resource should accept and transform to lite page.
112 self.assertTrue(self.checkLitePageResponse(response));
113 lite_page_responses = lite_page_responses + 1
114
115 # Be sure force exp not set.
116 self.assertNotIn('exp=force_lite_page',
117 response.request_headers['chrome-proxy'])
118 else:
119 # No subresources should accept transforms.
120 self.assertNotIn('chrome-proxy-accept-transform',
121 response.request_headers)
122
123 self.assertEqual(1, lite_page_responses)
124
125 # Checks that the server does not provide Lite Page for fast connection.
bengr 2017/05/01 16:53:15 for -> for a
126 def testLitePageNotProvidedForFastConnection(self):
127 with TestDriver() as test_driver:
128 test_driver.AddChromeArg('--enable-spdy-proxy-auth')
129 test_driver.AddChromeArg('--force-fieldtrial-params='
130 'NetworkQualityEstimator.Enabled:'
131 'force_effective_connection_type/3G,'
132 'DataCompressionProxyLoFi.Enabled_Preview:'
133 'effective_connection_type/2G')
134 test_driver.AddChromeArg('--force-fieldtrials='
135 'NetworkQualityEstimator/Enabled/'
136 'DataCompressionProxyLoFi/Enabled_Preview/'
137 'DataCompressionProxyLitePageFallback/Enabled')
138
139 test_driver.LoadURL('http://check.googlezip.net/test.html')
140
141 for response in test_driver.GetHTTPResponses():
142 self.assertEqual('3G', response.request_headers['chrome-proxy-ect'])
143
144 if response.url.endswith('html'):
145 # Main resource should accept lite page but not be transformed.
146 self.assertEqual('lite-page',
147 response.request_headers['chrome-proxy-accept-transform'])
148 self.assertNotIn('chrome-proxy-content-transform',
149 response.response_headers)
150 self.assertNotIn('chrome-proxy-content-transform',
151 response.response_headers)
152 self.assertEqual('3G', response.request_headers['chrome-proxy-ect'])
153 else:
154 # No subresources should accept transforms.
155 self.assertNotIn('chrome-proxy-accept-transform',
156 response.request_headers)
157
86 # Checks that Lo-Fi images are used when the user is in the 158 # Checks that Lo-Fi images are used when the user is in the
87 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not 159 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not
88 # served. 160 # served.
89 def testLitePageFallback(self): 161 def testLitePageFallback(self):
90 with TestDriver() as test_driver: 162 with TestDriver() as test_driver:
91 test_driver.AddChromeArg('--enable-spdy-proxy-auth') 163 test_driver.AddChromeArg('--enable-spdy-proxy-auth')
164 test_driver.AddChromeArg('--force-fieldtrial-params='
165 'NetworkQualityEstimator.Enabled:'
166 'force_effective_connection_type/Slow2G,'
167 'DataCompressionProxyLoFi.Enabled_Preview:'
168 'effective_connection_type/2G')
92 test_driver.AddChromeArg('--force-fieldtrials=' 169 test_driver.AddChromeArg('--force-fieldtrials='
170 'NetworkQualityEstimator/Enabled/'
93 'DataCompressionProxyLoFi/Enabled_Preview/' 171 'DataCompressionProxyLoFi/Enabled_Preview/'
94 'DataCompressionProxyLitePageFallback/Enabled') 172 'DataCompressionProxyLitePageFallback/Enabled')
95 test_driver.AddChromeArg('--force-fieldtrial-params='
96 'DataCompressionProxyLoFi.Enabled_Preview:'
97 'effective_connection_type/4G')
98 test_driver.AddChromeArg('--force-net-effective-connection-type=2g')
99 173
100 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') 174 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback')
101 175
102 lite_page_requests = 0 176 lite_page_requests = 0
103 lo_fi_responses = 0 177 lo_fi_responses = 0
104 for response in test_driver.GetHTTPResponses(): 178 for response in test_driver.GetHTTPResponses():
105 if not response.request_headers: 179 if not response.request_headers:
106 continue 180 continue
107 181
182 self.assertEqual("Slow-2G",
183 response.request_headers['chrome-proxy-ect'])
184
108 cpat_request = response.request_headers['chrome-proxy-accept-transform'] 185 cpat_request = response.request_headers['chrome-proxy-accept-transform']
109 if ('lite-page' in cpat_request): 186 if ('lite-page' in cpat_request):
110 lite_page_requests = lite_page_requests + 1 187 lite_page_requests = lite_page_requests + 1
111 self.assertFalse(self.checkLitePageResponse(response)) 188 self.assertFalse(self.checkLitePageResponse(response))
112 189
113 if not response.url.endswith('png'): 190 if not response.url.endswith('png'):
114 continue 191 continue
115 192
116 if (self.checkLoFiResponse(response, True)): 193 if (self.checkLoFiResponse(response, True)):
117 lo_fi_responses = lo_fi_responses + 1 194 lo_fi_responses = lo_fi_responses + 1
118 195
119 # Verify that a Lite Page was requested and that the page fell back to 196 # Verify that a Lite Page was requested and that the page fell back to
120 # Lo-Fi images. 197 # Lo-Fi images.
121 self.assertEqual(1, lite_page_requests) 198 self.assertEqual(1, lite_page_requests)
122 self.assertEqual(1, lo_fi_responses) 199 self.assertEqual(1, lo_fi_responses)
123 200
124 # Checks that Lo-Fi images are not used when the user is not in the 201 # Checks that Lo-Fi images are not used when the user is not in the
125 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not 202 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not
126 # served. 203 # served.
127 def testLitePageNoFallback(self): 204 def testLitePageNoFallback(self):
128 with TestDriver() as test_driver: 205 with TestDriver() as test_driver:
129 test_driver.AddChromeArg('--enable-spdy-proxy-auth') 206 test_driver.AddChromeArg('--enable-spdy-proxy-auth')
130 # Lite Pages must be enabled via the field trial because the Lite Page 207 # Lite Pages must be enabled via the field trial because the Lite Page
131 # flag always falls back to Lo-Fi. 208 # flag always falls back to Lo-Fi.
209 test_driver.AddChromeArg('--force-fieldtrial-params='
210 'NetworkQualityEstimator.Enabled:'
211 'force_effective_connection_type/Slow2G,'
212 'DataCompressionProxyLoFi.Enabled_Preview:'
213 'effective_connection_type/2G')
132 test_driver.AddChromeArg('--force-fieldtrials=' 214 test_driver.AddChromeArg('--force-fieldtrials='
215 'NetworkQualityEstimator/Enabled/'
133 'DataCompressionProxyLoFi/Enabled_Preview') 216 'DataCompressionProxyLoFi/Enabled_Preview')
134 test_driver.AddChromeArg('--force-fieldtrial-params='
135 'DataCompressionProxyLoFi.Enabled_Preview:'
136 'effective_connection_type/4G')
137 test_driver.AddChromeArg('--force-net-effective-connection-type=2g')
138 217
139 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback') 218 test_driver.LoadURL('http://check.googlezip.net/lite-page-fallback')
140 219
141 lite_page_requests = 0 220 lite_page_requests = 0
142 for response in test_driver.GetHTTPResponses(): 221 for response in test_driver.GetHTTPResponses():
143 if not response.request_headers: 222 if not response.request_headers:
144 continue 223 continue
145 224
225 self.assertEqual("Slow-2G",
226 response.request_headers['chrome-proxy-ect'])
227
146 if ('chrome-proxy-accept-transform' in response.request_headers): 228 if ('chrome-proxy-accept-transform' in response.request_headers):
147 cpat_request = response.request_headers[ 229 cpat_request = response.request_headers[
148 'chrome-proxy-accept-transform'] 230 'chrome-proxy-accept-transform']
149 if ('lite-page' in cpat_request): 231 if ('lite-page' in cpat_request):
150 lite_page_requests = lite_page_requests + 1 232 lite_page_requests = lite_page_requests + 1
151 self.assertFalse(self.checkLitePageResponse(response)) 233 self.assertFalse(self.checkLitePageResponse(response))
152 234
153 if not response.url.endswith('png'): 235 if not response.url.endswith('png'):
154 continue 236 continue
155 237
156 self.checkLoFiResponse(response, False) 238 self.checkLoFiResponse(response, False)
157 239
158 # Verify that a Lite Page was requested and that the page fell back to 240 # Verify that a Lite Page was requested and that the page fell back to
159 # Lo-Fi images. 241 # Lo-Fi images.
160 self.assertEqual(1, lite_page_requests) 242 self.assertEqual(1, lite_page_requests)
161 243
162 if __name__ == '__main__': 244 if __name__ == '__main__':
163 IntegrationTest.RunAllTests() 245 IntegrationTest.RunAllTests()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698