| 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 | 10 |
| 10 class LitePage(IntegrationTest): | 11 class LitePage(IntegrationTest): |
| 11 | 12 |
| 12 # Checks that a Lite Page is served and that the ignore_preview_blacklist | 13 # Checks that a Lite Page is served and that the ignore_preview_blacklist |
| 13 # experiment is being used. | 14 # experiment is being used. |
| 14 def testLitePage(self): | 15 def testLitePage(self): |
| 15 # 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. |
| 16 if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment' | 17 if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment' |
| 17 in common.ParseFlags().browser_args): | 18 in common.ParseFlags().browser_args): |
| 18 self.skipTest('This test cannot be run with other experiments.') | 19 self.skipTest('This test cannot be run with other experiments.') |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 if response.url.startswith('data:'): | 33 if response.url.startswith('data:'): |
| 33 continue | 34 continue |
| 34 self.assertIn('exp=ignore_preview_blacklist', | 35 self.assertIn('exp=ignore_preview_blacklist', |
| 35 response.request_headers['chrome-proxy']) | 36 response.request_headers['chrome-proxy']) |
| 36 if (self.checkLitePageResponse(response)): | 37 if (self.checkLitePageResponse(response)): |
| 37 lite_page_responses = lite_page_responses + 1 | 38 lite_page_responses = lite_page_responses + 1 |
| 38 | 39 |
| 39 # Verify that a Lite Page response for the main frame was seen. | 40 # Verify that a Lite Page response for the main frame was seen. |
| 40 self.assertEqual(1, lite_page_responses) | 41 self.assertEqual(1, lite_page_responses) |
| 41 | 42 |
| 43 # 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. |
| 45 def testLitePageBTF(self): |
| 46 # If it was attempted to run with another experiment, skip this test. |
| 47 if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment' |
| 48 in common.ParseFlags().browser_args): |
| 49 self.skipTest('This test cannot be run with other experiments.') |
| 50 with TestDriver() as test_driver: |
| 51 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 52 test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on') |
| 53 test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page') |
| 54 |
| 55 # This page is long and has many media resources. |
| 56 test_driver.LoadURL('http://check.googlezip.net/metrics/index.html') |
| 57 |
| 58 # Verify that a Lite Page response for the main frame was seen. |
| 59 lite_page_responses = 0 |
| 60 for response in test_driver.GetHTTPResponses(): |
| 61 # Skip CSI requests when validating Lite Page headers. CSI requests |
| 62 # aren't expected to have LoFi headers. |
| 63 if '/csi?' in response.url: |
| 64 continue |
| 65 if response.url.startswith('data:'): |
| 66 continue |
| 67 self.assertIn('exp=ignore_preview_blacklist', |
| 68 response.request_headers['chrome-proxy']) |
| 69 if (self.checkLitePageResponse(response)): |
| 70 lite_page_responses = lite_page_responses + 1 |
| 71 self.assertEqual(1, lite_page_responses) |
| 72 |
| 73 # Scroll to the bottom of the window and make sure there were more |
| 74 # requests that were proxied. |
| 75 scroll_js = 'window.scrollTo(0,Math.max(document.body.scrollHeight));' |
| 76 test_driver.ExecuteJavascriptStatement(scroll_js) |
| 77 # Give some time for loading after each scroll. |
| 78 time.sleep(2) |
| 79 test_driver.ExecuteJavascriptStatement(scroll_js) |
| 80 time.sleep(2) |
| 81 responses = test_driver.GetHTTPResponses(override_has_logs=True) |
| 82 self.assertNotEqual(0, len(responses)) |
| 83 for response in responses: |
| 84 self.assertHasChromeProxyViaHeader(response) |
| 85 |
| 42 # Checks that Lo-Fi images are used when the user is in the | 86 # Checks that Lo-Fi images are used when the user is in the |
| 43 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not | 87 # DataCompressionProxyLitePageFallback field trial and a Lite Page is not |
| 44 # served. | 88 # served. |
| 45 def testLitePageFallback(self): | 89 def testLitePageFallback(self): |
| 46 with TestDriver() as test_driver: | 90 with TestDriver() as test_driver: |
| 47 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 91 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 48 test_driver.AddChromeArg('--force-fieldtrials=' | 92 test_driver.AddChromeArg('--force-fieldtrials=' |
| 49 'DataCompressionProxyLoFi/Enabled_Preview/' | 93 'DataCompressionProxyLoFi/Enabled_Preview/' |
| 50 'DataCompressionProxyLitePageFallback/Enabled') | 94 'DataCompressionProxyLitePageFallback/Enabled') |
| 51 test_driver.AddChromeArg('--force-fieldtrial-params=' | 95 test_driver.AddChromeArg('--force-fieldtrial-params=' |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 continue | 154 continue |
| 111 | 155 |
| 112 self.checkLoFiResponse(response, False) | 156 self.checkLoFiResponse(response, False) |
| 113 | 157 |
| 114 # Verify that a Lite Page was requested and that the page fell back to | 158 # Verify that a Lite Page was requested and that the page fell back to |
| 115 # Lo-Fi images. | 159 # Lo-Fi images. |
| 116 self.assertEqual(1, lite_page_requests) | 160 self.assertEqual(1, lite_page_requests) |
| 117 | 161 |
| 118 if __name__ == '__main__': | 162 if __name__ == '__main__': |
| 119 IntegrationTest.RunAllTests() | 163 IntegrationTest.RunAllTests() |
| OLD | NEW |