OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 argparse | 5 import argparse |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import socket | 10 import socket |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 """ | 579 """ |
580 if 'via' in http_response.response_headers: | 580 if 'via' in http_response.response_headers: |
581 expected_via_header = ParseFlags().via_header_value | 581 expected_via_header = ParseFlags().via_header_value |
582 actual_via_headers = http_response.response_headers['via'].split(',') | 582 actual_via_headers = http_response.response_headers['via'].split(',') |
583 self.assertNotIn(expected_via_header, actual_via_headers, "Via header " | 583 self.assertNotIn(expected_via_header, actual_via_headers, "Via header " |
584 "found in response headers! Not expected: %s, Actual: %s" % | 584 "found in response headers! Not expected: %s, Actual: %s" % |
585 (expected_via_header, actual_via_headers)) | 585 (expected_via_header, actual_via_headers)) |
586 | 586 |
587 def checkLoFiResponse(self, http_response, expected_lo_fi): | 587 def checkLoFiResponse(self, http_response, expected_lo_fi): |
588 """Asserts that if expected the response headers contain the Lo-Fi directive | 588 """Asserts that if expected the response headers contain the Lo-Fi directive |
589 then the request headers do too. Also checks that the content size is less | 589 then the request headers do too. If the CPAT header contains if-heavy, the |
bengr
2017/04/27 18:45:49
Note somewhere that 'if-heavy' is being deprecated
RyanSturm
2017/04/27 18:50:32
Done.
| |
590 than 100 if |expected_lo_fi|. Otherwise, checks that the response and | 590 request should not be LoFi. Also checks that the content size is less than |
591 request headers don't contain the Lo-Fi directive and the content size is | 591 100 if |expected_lo_fi|. Otherwise, checks that the response and request |
592 greater than 100. | 592 headers don't contain the Lo-Fi directive and the content size is greater |
593 than 100. | |
593 | 594 |
594 Args: | 595 Args: |
595 http_response: The HTTPResponse object to check. | 596 http_response: The HTTPResponse object to check. |
596 expected_lo_fi: Whether the response should be Lo-Fi. | 597 expected_lo_fi: Whether the response should be Lo-Fi. |
597 | 598 |
598 Returns: | 599 Returns: |
599 Whether the response was Lo-Fi. | 600 Whether the response was Lo-Fi. |
600 """ | 601 """ |
601 | 602 |
602 if (expected_lo_fi) : | 603 if (expected_lo_fi) : |
603 self.assertHasChromeProxyViaHeader(http_response) | 604 self.assertHasChromeProxyViaHeader(http_response) |
604 content_length = http_response.response_headers['content-length'] | 605 content_length = http_response.response_headers['content-length'] |
605 cpat_request = http_response.request_headers[ | 606 cpat_request = http_response.request_headers[ |
606 'chrome-proxy-accept-transform'] | 607 'chrome-proxy-accept-transform'] |
607 cpct_response = http_response.response_headers[ | 608 cpct_response = http_response.response_headers[ |
608 'chrome-proxy-content-transform'] | 609 'chrome-proxy-content-transform'] |
609 if ('empty-image' in cpct_response): | 610 if ('empty-image' in cpct_response): |
610 self.assertIn('empty-image', cpat_request) | 611 self.assertIn('empty-image', cpat_request) |
611 self.assertTrue(int(content_length) < 100) | 612 self.assertTrue(int(content_length) < 100) |
612 return True; | 613 return True; |
613 return False; | 614 return False; |
614 else: | 615 else: |
615 self.assertNotIn('chrome-proxy-accept-transform', | 616 if ('chrome-proxy-accept-transform' in http_response.request_headers): |
616 http_response.request_headers) | 617 cpat_request = http_response.request_headers[ |
618 'chrome-proxy-accept-transform'] | |
619 if ('empty-image' in cpat_request): | |
620 self.assertIn('if-heavy', cpat_request) | |
617 self.assertNotIn('chrome-proxy-content-transform', | 621 self.assertNotIn('chrome-proxy-content-transform', |
618 http_response.response_headers) | 622 http_response.response_headers) |
619 content_length = http_response.response_headers['content-length'] | 623 content_length = http_response.response_headers['content-length'] |
620 self.assertTrue(int(content_length) > 100) | 624 self.assertTrue(int(content_length) > 100) |
621 return False; | 625 return False; |
622 | 626 |
623 def checkLitePageResponse(self, http_response): | 627 def checkLitePageResponse(self, http_response): |
624 """Asserts that if the response headers contain the Lite Page directive then | 628 """Asserts that if the response headers contain the Lite Page directive then |
625 the request headers do too. | 629 the request headers do too. |
626 | 630 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 for test_suite in test_suite_iter: | 673 for test_suite in test_suite_iter: |
670 for test_case in test_suite: | 674 for test_case in test_suite: |
671 for test in test_case: | 675 for test in test_case: |
672 # Drop the file name in the form <filename>.<classname>.<methodname> | 676 # Drop the file name in the form <filename>.<classname>.<methodname> |
673 test_id = test.id()[test.id().find('.') + 1:] | 677 test_id = test.id()[test.id().find('.') + 1:] |
674 if re.match(test_filter_re, test_id): | 678 if re.match(test_filter_re, test_id): |
675 tests.addTest(test) | 679 tests.addTest(test) |
676 testRunner = unittest.runner.TextTestRunner(verbosity=2, | 680 testRunner = unittest.runner.TextTestRunner(verbosity=2, |
677 failfast=flags.failfast, buffer=(not flags.disable_buffer)) | 681 failfast=flags.failfast, buffer=(not flags.disable_buffer)) |
678 testRunner.run(tests) | 682 testRunner.run(tests) |
OLD | NEW |