| 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 Bypass(IntegrationTest): | 10 class Bypass(IntegrationTest): |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 # Ensure Chrome does not use Data Saver for HTTPS requests. | 40 # Ensure Chrome does not use Data Saver for HTTPS requests. |
| 41 def testHttpsBypass(self): | 41 def testHttpsBypass(self): |
| 42 with TestDriver() as t: | 42 with TestDriver() as t: |
| 43 t.AddChromeArg('--enable-spdy-proxy-auth') | 43 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 44 | 44 |
| 45 # Load HTTP page and check that Data Saver is used. | 45 # Load HTTP page and check that Data Saver is used. |
| 46 t.LoadURL('http://check.googlezip.net/test.html') | 46 t.LoadURL('http://check.googlezip.net/test.html') |
| 47 responses = t.GetHTTPResponses() | 47 responses = t.GetHTTPResponses() |
| 48 self.assertEqual(2, len(responses)) | 48 self.assertEqual(2, len(responses)) |
| 49 for response in t.GetHTTPResponses(): | 49 for response in responses: |
| 50 self.assertHasChromeProxyViaHeader(response) | 50 self.assertHasChromeProxyViaHeader(response) |
| 51 | 51 |
| 52 # Load HTTPS page and check that Data Saver is not used. | 52 # Load HTTPS page and check that Data Saver is not used. |
| 53 t.LoadURL('https://check.googlezip.net/test.html') | 53 t.LoadURL('https://check.googlezip.net/test.html') |
| 54 responses = t.GetHTTPResponses() | 54 responses = t.GetHTTPResponses() |
| 55 self.assertEqual(2, len(responses)) | 55 self.assertEqual(2, len(responses)) |
| 56 for response in t.GetHTTPResponses(): | 56 for response in responses: |
| 57 self.assertNotHasChromeProxyViaHeader(response) | 57 self.assertNotHasChromeProxyViaHeader(response) |
| 58 | 58 |
| 59 # Verify that CORS requests receive a block-once from the data reduction | 59 # Verify that CORS requests receive a block-once from the data reduction |
| 60 # proxy by checking that those requests are retried without data reduction | 60 # proxy by checking that those requests are retried without data reduction |
| 61 # proxy. | 61 # proxy. |
| 62 def testCorsBypass(self): | 62 def testCorsBypass(self): |
| 63 with TestDriver() as test_driver: | 63 with TestDriver() as test_driver: |
| 64 test_driver.AddChromeArg('--enable-spdy-proxy-auth') | 64 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 65 test_driver.LoadURL('http://www.gstatic.com/chrome/googlezip/cors/') | 65 test_driver.LoadURL('http://www.gstatic.com/chrome/googlezip/cors/') |
| 66 | 66 |
| 67 # Navigate to a different page to verify that later requests are not | 67 # Navigate to a different page to verify that later requests are not |
| 68 # blocked. | 68 # blocked. |
| 69 test_driver.LoadURL('http://check.googlezip.net/test.html') | 69 test_driver.LoadURL('http://check.googlezip.net/test.html') |
| 70 | 70 |
| 71 cors_requests = 0 | 71 cors_requests = 0 |
| 72 same_origin_requests = 0 | 72 same_origin_requests = 0 |
| 73 for response in test_driver.GetHTTPResponses(): | 73 for response in test_driver.GetHTTPResponses(): |
| 74 # The origin header implies that |response| is a CORS request. | 74 # The origin header implies that |response| is a CORS request. |
| 75 if ('origin' not in response.request_headers): | 75 if ('origin' not in response.request_headers): |
| 76 self.assertHasChromeProxyViaHeader(response) | 76 self.assertHasChromeProxyViaHeader(response) |
| 77 same_origin_requests = same_origin_requests + 1 | 77 same_origin_requests = same_origin_requests + 1 |
| 78 else: | 78 else: |
| 79 self.assertNotHasChromeProxyViaHeader(response) | 79 self.assertNotHasChromeProxyViaHeader(response) |
| 80 cors_requests = cors_requests + 1 | 80 cors_requests = cors_requests + 1 |
| 81 # Verify that both CORS and same origin requests were seen. | 81 # Verify that both CORS and same origin requests were seen. |
| 82 self.assertNotEqual(0, same_origin_requests) | 82 self.assertNotEqual(0, same_origin_requests) |
| 83 self.assertNotEqual(0, cors_requests) | 83 self.assertNotEqual(0, cors_requests) |
| 84 | 84 |
| 85 # Verify that when an origin times out using Data Saver, the request is |
| 86 # fetched directly and data saver is bypassed only for one request. |
| 87 def testOriginTimeoutBlockOnce(self): |
| 88 with TestDriver() as test_driver: |
| 89 test_driver.AddChromeArg('--enable-spdy-proxy-auth') |
| 90 |
| 91 # Load URL that times out when the proxy server tries to access it. |
| 92 test_driver.LoadURL('http://chromeproxy-test.appspot.com/blackhole') |
| 93 responses = test_driver.GetHTTPResponses() |
| 94 self.assertNotEqual(0, len(responses)) |
| 95 for response in responses: |
| 96 self.assertNotHasChromeProxyViaHeader(response) |
| 97 |
| 98 # Load HTTP page and check that Data Saver is used. |
| 99 test_driver.LoadURL('http://check.googlezip.net/test.html') |
| 100 responses = test_driver.GetHTTPResponses() |
| 101 self.assertNotEqual(0, len(responses)) |
| 102 for response in responses: |
| 103 self.assertHasChromeProxyViaHeader(response) |
| 104 |
| 105 |
| 85 if __name__ == '__main__': | 106 if __name__ == '__main__': |
| 86 IntegrationTest.RunAllTests() | 107 IntegrationTest.RunAllTests() |
| OLD | NEW |