1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import common
from common import TestDriver
from common import IntegrationTest
from decorators import ChromeVersionBeforeM
from decorators import ChromeVersionEqualOrAfterM
class LoFi(IntegrationTest):
# Checks that the compressed image is below a certain threshold.
# The test page is uncacheable otherwise a cached page may be served that
# doesn't have the correct via headers.
@ChromeVersionBeforeM(65)
def testLoFiOldFlags(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
# Disable server experiments such as tamper detection.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Verify Lo-Fi previews info bar recorded
histogram = test_driver.GetHistogram('Previews.InfoBarAction.LoFi', 5)
self.assertEqual(1, histogram['count'])
# Checks that LoFi images are served when LoFi slow connections are used and
# the network quality estimator returns Slow2G.
@ChromeVersionBeforeM(65)
def testLoFiSlowConnectionOldFlags(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=slow-connections-'
'only')
# Disable server experiments such as tamper detection.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/Slow2G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Verify Lo-Fi previews info bar recorded
histogram = test_driver.GetHistogram('Previews.InfoBarAction.LoFi', 5)
self.assertEqual(1, histogram['count'])
# Checks that LoFi images are served when LoFi slow connections are used and
# the network quality estimator returns Slow2G.
@ChromeVersionEqualOrAfterM(65)
def testLoFiOnSlowConnection(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
# Disable server experiments such as tamper detection.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/Slow2G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Verify Lo-Fi previews info bar recorded
histogram = test_driver.GetHistogram('Previews.InfoBarAction.LoFi', 5)
self.assertEqual(1, histogram['count'])
# Checks that LoFi images are NOT served when the network quality estimator
# returns fast connection type.
@ChromeVersionBeforeM(65)
def testLoFiFastConnectionOldFlags(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=slow-connections-'
'only')
# Disable server experiments such as tamper detection.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/4G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if response.url.endswith('html'):
# Main resource should accept transforms but not be transformed.
self.assertEqual('lite-page',
response.request_headers['chrome-proxy-accept-transform'])
self.assertNotIn('chrome-proxy-content-transform',
response.response_headers)
if 'chrome-proxy' in response.response_headers:
self.assertNotIn('page-policies',
response.response_headers['chrome-proxy'])
else:
# No subresources should accept transforms.
self.assertNotIn('chrome-proxy-accept-transform',
response.request_headers)
# Verify no Lo-Fi previews info bar recorded
histogram = test_driver.GetHistogram('Previews.InfoBarAction.LoFi', 5)
self.assertEqual(histogram, {})
# Checks that LoFi images are NOT served when the network quality estimator
# returns fast connection.
@ChromeVersionEqualOrAfterM(65)
def testLoFiFastConnection(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
# Disable server experiments such as tamper detection.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/4G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if response.url.endswith('html'):
# Main resource should accept transforms but not be transformed.
self.assertEqual('lite-page',
response.request_headers['chrome-proxy-accept-transform'])
self.assertNotIn('chrome-proxy-content-transform',
response.response_headers)
if 'chrome-proxy' in response.response_headers:
self.assertNotIn('page-policies',
response.response_headers['chrome-proxy'])
else:
# No subresources should accept transforms.
self.assertNotIn('chrome-proxy-accept-transform',
response.request_headers)
# Verify no Lo-Fi previews info bar recorded
histogram = test_driver.GetHistogram('Previews.InfoBarAction.LoFi', 5)
self.assertEqual(histogram, {})
# Checks that LoFi images are not served, but the if-heavy CPAT header is
# added when LoFi slow connections are used and the network quality estimator
# returns 4G.
# If-heavy stopped being added in M61.
@ChromeVersionBeforeM(61)
def testLoFiIfHeavyFastConnection(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=slow-connections-'
'only')
# Disable server experiments.
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/4G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
non_lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
self.assertIn('chrome-proxy-accept-transform', response.request_headers)
actual_cpat_headers = \
response.request_headers['chrome-proxy-accept-transform'].split(';')
self.assertIn('empty-image', actual_cpat_headers)
self.assertIn('if-heavy', actual_cpat_headers)
if (not self.checkLoFiResponse(response, False)):
non_lofi_responses = non_lofi_responses + 1
# Verify that non Lo-Fi image responses were seen.
self.assertNotEqual(0, non_lofi_responses)
# Checks that Lo-Fi placeholder images are not loaded from cache on page
# reloads when Lo-Fi mode is disabled or data reduction proxy is disabled.
# First a test page is opened with Lo-Fi and chrome proxy enabled. This allows
# Chrome to cache the Lo-Fi placeholder image. The browser is restarted with
# chrome proxy disabled and the same test page is loaded. This second page
# load should not pick the Lo-Fi placeholder from cache and original image
# should be loaded. Finally, the browser is restarted with chrome proxy
# enabled and Lo-Fi disabled and the same test page is loaded. This third page
# load should not pick the Lo-Fi placeholder from cache and original image
# should be loaded.
@ChromeVersionBeforeM(65)
def testLoFiCacheBypassOldFlags(self):
# If it was attempted to run with another experiment, skip this test.
if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment'
in common.ParseFlags().browser_args):
self.skipTest('This test cannot be run with other experiments.')
with TestDriver() as test_driver:
# First page load, enable Lo-Fi and chrome proxy. Disable server
# experiments such as tamper detection. This test should be run with
# --profile-type=default command line for the same user profile and cache
# to be used across the two page loads.
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
test_driver.AddChromeArg('--profile-type=default')
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Second page load with the chrome proxy off.
test_driver._StopDriver()
test_driver.RemoveChromeArg('--enable-spdy-proxy-auth')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
responses = responses + 1
self.assertNotHasChromeProxyViaHeader(response)
self.checkLoFiResponse(response, False)
# Verify that responses were seen.
self.assertNotEqual(0, responses)
# Third page load with the chrome proxy on and Lo-Fi off.
test_driver._StopDriver()
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.RemoveChromeArg('--data-reduction-proxy-lo-fi=always-on')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=disabled')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
responses = responses + 1
self.assertHasChromeProxyViaHeader(response)
self.checkLoFiResponse(response, False)
# Verify that responses were seen.
self.assertNotEqual(0, responses)
# Checks that Lo-Fi placeholder images are not loaded from cache on page
# reloads when Lo-Fi mode is disabled or data reduction proxy is disabled.
# First a test page is opened with Lo-Fi and chrome proxy enabled. This allows
# Chrome to cache the Lo-Fi placeholder image. The browser is restarted with
# chrome proxy disabled and the same test page is loaded. This second page
# load should not pick the Lo-Fi placeholder from cache and original image
# should be loaded. Finally, the browser is restarted with chrome proxy
# enabled and Lo-Fi disabled and the same test page is loaded. This third page
# load should not pick the Lo-Fi placeholder from cache and original image
# should be loaded.
@ChromeVersionEqualOrAfterM(65)
def testLoFiCacheBypass(self):
# If it was attempted to run with another experiment, skip this test.
if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment'
in common.ParseFlags().browser_args):
self.skipTest('This test cannot be run with other experiments.')
with TestDriver() as test_driver:
# First page load, enable Lo-Fi and chrome proxy. Disable server
# experiments such as tamper detection. This test should be run with
# --profile-type=default command line for the same user profile and cache
# to be used across the two page loads.
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--profile-type=default')
test_driver.AddChromeArg('--data-reduction-proxy-server-experiments-'
'disabled')
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/Slow2G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
if (self.checkLoFiResponse(response, True)):
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Second page load with the chrome proxy off.
test_driver._StopDriver()
test_driver.RemoveChromeArg('--enable-spdy-proxy-auth')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
responses = responses + 1
self.assertNotHasChromeProxyViaHeader(response)
self.checkLoFiResponse(response, False)
# Verify that responses were seen.
self.assertNotEqual(0, responses)
# Third page load with the chrome proxy on and Lo-Fi off.
test_driver._StopDriver()
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.RemoveChromeArg('--enable-features='
'DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--disable-features='
'DataReductionProxyDecidesTransform')
test_driver.LoadURL('http://check.googlezip.net/cacheable/test.html')
responses = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('png'):
continue
if not response.request_headers:
continue
responses = responses + 1
self.assertHasChromeProxyViaHeader(response)
self.checkLoFiResponse(response, False)
# Verify that responses were seen.
self.assertNotEqual(0, responses)
# Checks that LoFi images are served and the force empty image experiment
# directive is provided when LoFi is always-on without Lite Pages enabled.
@ChromeVersionEqualOrAfterM(61)
@ChromeVersionBeforeM(65)
def testLoFiForcedExperimentOldFlags(self):
# If it was attempted to run with another experiment, skip this test.
if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment'
in common.ParseFlags().browser_args):
self.skipTest('This test cannot be run with other experiments.')
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
# Ensure fast network (4G) to ensure force flag ignores ECT.
test_driver.AddChromeArg('--force-fieldtrial-params='
'NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/4G')
test_driver.AddChromeArg('--force-fieldtrials=NetworkQualityEstimator/'
'Enabled')
test_driver.LoadURL('http://check.googlezip.net/static/index.html')
lofi_responses = 0
for response in test_driver.GetHTTPResponses():
self.assertIn('exp=force_page_policies_empty_image',
response.request_headers['chrome-proxy'])
if response.url.endswith('html'):
# Verify that the server provides the fallback directive
self.assertIn('chrome-proxy', response.response_headers)
self.assertIn('page-policies=empty-image',
response.response_headers['chrome-proxy'])
continue
if response.url.endswith('png'):
self.checkLoFiResponse(response, True)
lofi_responses = lofi_responses + 1
# Verify that Lo-Fi responses were seen.
self.assertNotEqual(0, lofi_responses)
# Checks that Client LoFi resource requests have the Intervention header.
@ChromeVersionEqualOrAfterM(61)
def testClientLoFiInterventionHeader(self):
with TestDriver() as test_driver:
test_driver.AddChromeArg('--enable-spdy-proxy-auth')
test_driver.AddChromeArg('--enable-features='
'Previews,DataReductionProxyDecidesTransform')
test_driver.AddChromeArg(
'--force-fieldtrial-params=NetworkQualityEstimator.Enabled:'
'force_effective_connection_type/2G,'
'PreviewsClientLoFi.Enabled:'
'max_allowed_effective_connection_type/4G')
test_driver.AddChromeArg(
'--force-fieldtrials=NetworkQualityEstimator/Enabled/'
'PreviewsClientLoFi/Enabled')
test_driver.LoadURL('https://check.googlezip.net/static/index.html')
intervention_headers = 0
for response in test_driver.GetHTTPResponses():
if not response.url.endswith('html'):
self.assertIn('intervention', response.request_headers)
intervention_headers = intervention_headers + 1
self.assertNotEqual(0, intervention_headers)
if __name__ == '__main__':
IntegrationTest.RunAllTests()
|