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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 571 |
572 Args: | 572 Args: |
573 http_response: The HTTPResponse object to check. | 573 http_response: The HTTPResponse object to check. |
574 """ | 574 """ |
575 expected_via_header = ParseFlags().via_header_value | 575 expected_via_header = ParseFlags().via_header_value |
576 self.assertNotIn('via', http_response.response_headers) | 576 self.assertNotIn('via', http_response.response_headers) |
577 if 'via' in http_response.response_headers: | 577 if 'via' in http_response.response_headers: |
578 self.assertNotIn(expected_via_header, | 578 self.assertNotIn(expected_via_header, |
579 http_response.response_headers['via']) | 579 http_response.response_headers['via']) |
580 | 580 |
581 def assertLoFiResponse(self, http_response, expected_lo_fi): | 581 def checkLoFiResponse(self, http_response, expected_lo_fi): |
582 """Asserts that the response and request headers contain the given directive | 582 """Asserts that if expected the response headers contain the Lo-Fi directive |
583 and the content size is less than 100 if |expected_lo_fi|. Otherwise, checks | 583 then the request headers do too. Also checks that the content size is less |
584 that the response and request headers don't contain the Lo-Fi directive and | 584 than 100 if |expected_lo_fi|. Otherwise, checks that the response and |
585 the content size is greater than 100. | 585 request headers don't contain the Lo-Fi directive and the content size is |
| 586 greater than 100. |
586 | 587 |
587 Args: | 588 Args: |
588 http_response: The HTTPResponse object to check. | 589 http_response: The HTTPResponse object to check. |
589 expected_lo_fi: Whether the response should be Lo-Fi. | 590 expected_lo_fi: Whether the response should be Lo-Fi. |
590 | 591 |
591 Returns: | 592 Returns: |
592 Whether the response was Lo-Fi. | 593 Whether the response was Lo-Fi. |
593 """ | 594 """ |
594 | 595 |
595 if (expected_lo_fi) : | 596 if (expected_lo_fi) : |
(...skipping 10 matching lines...) Expand all Loading... |
606 return False; | 607 return False; |
607 else: | 608 else: |
608 self.assertNotIn('chrome-proxy-accept-transform', | 609 self.assertNotIn('chrome-proxy-accept-transform', |
609 http_response.request_headers) | 610 http_response.request_headers) |
610 self.assertNotIn('chrome-proxy-content-transform', | 611 self.assertNotIn('chrome-proxy-content-transform', |
611 http_response.response_headers) | 612 http_response.response_headers) |
612 content_length = http_response.response_headers['content-length'] | 613 content_length = http_response.response_headers['content-length'] |
613 self.assertTrue(int(content_length) > 100) | 614 self.assertTrue(int(content_length) > 100) |
614 return False; | 615 return False; |
615 | 616 |
| 617 def checkLitePageResponse(self, http_response): |
| 618 """Asserts that if the response headers contain the Lite Page directive then |
| 619 the request headers do too. |
| 620 |
| 621 Args: |
| 622 http_response: The HTTPResponse object to check. |
| 623 |
| 624 Returns: |
| 625 Whether the response was a Lite Page. |
| 626 """ |
| 627 |
| 628 self.assertHasChromeProxyViaHeader(http_response) |
| 629 if ('chrome-proxy-content-transform' not in http_response.response_headers): |
| 630 return False; |
| 631 cpct_response = http_response.response_headers[ |
| 632 'chrome-proxy-content-transform'] |
| 633 cpat_request = http_response.request_headers[ |
| 634 'chrome-proxy-accept-transform'] |
| 635 if ('lite-page' in cpct_response): |
| 636 self.assertIn('lite-page', cpat_request) |
| 637 return True; |
| 638 return False; |
| 639 |
616 @staticmethod | 640 @staticmethod |
617 def RunAllTests(run_all_tests=False): | 641 def RunAllTests(run_all_tests=False): |
618 """A simple helper method to run all tests using unittest.main(). | 642 """A simple helper method to run all tests using unittest.main(). |
619 | 643 |
620 Args: | 644 Args: |
621 run_all_tests: If True, all tests in the directory will be run, Otherwise | 645 run_all_tests: If True, all tests in the directory will be run, Otherwise |
622 only the tests in the file given on the command line will be run. | 646 only the tests in the file given on the command line will be run. |
623 """ | 647 """ |
624 flags = ParseFlags() | 648 flags = ParseFlags() |
625 logger = GetLogger() | 649 logger = GetLogger() |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 args[0].skipTest('This test runs on Mac OS only.') | 731 args[0].skipTest('This test runs on Mac OS only.') |
708 return wrapper | 732 return wrapper |
709 | 733 |
710 def NotMac(func): | 734 def NotMac(func): |
711 def wrapper(*args, **kwargs): | 735 def wrapper(*args, **kwargs): |
712 if sys.platform == 'darwin': | 736 if sys.platform == 'darwin': |
713 func(*args, **kwargs) | 737 func(*args, **kwargs) |
714 else: | 738 else: |
715 args[0].skipTest('This test does not run on Mac OS.') | 739 args[0].skipTest('This test does not run on Mac OS.') |
716 return wrapper | 740 return wrapper |
OLD | NEW |