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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 | 541 |
542 Args: | 542 Args: |
543 http_response: The HTTPResponse object to check. | 543 http_response: The HTTPResponse object to check. |
544 """ | 544 """ |
545 expected_via_header = ParseFlags().via_header_value | 545 expected_via_header = ParseFlags().via_header_value |
546 self.assertNotIn('via', http_response.response_headers) | 546 self.assertNotIn('via', http_response.response_headers) |
547 if 'via' in http_response.response_headers: | 547 if 'via' in http_response.response_headers: |
548 self.assertNotIn(expected_via_header, | 548 self.assertNotIn(expected_via_header, |
549 http_response.response_headers['via']) | 549 http_response.response_headers['via']) |
550 | 550 |
551 def assertLoFiResponse(self, http_response, expected_lo_fi): | |
552 """Asserts that the response and request headers contain the given directive | |
553 and the content size is less than 100 if |expected_lo_fi|. Otherwise, checks | |
554 that the response and request headers don't contain the Lo-Fi directive and | |
555 the content size is greater than 100. | |
556 | |
557 Args: | |
558 http_response: The HTTPResponse object to check. | |
559 expected_lo_fi: Whether the response should be Lo-Fi. | |
560 | |
561 Returns: | |
562 Whether the response was Lo-Fi. | |
563 """ | |
564 | |
565 if (expected_lo_fi) : | |
566 self.assertHasChromeProxyViaHeader(http_response) | |
567 content_length = http_response.response_headers['content-length'] | |
568 cpat_request = http_response.request_headers[ | |
569 'chrome-proxy-accept-transform'] | |
570 cpct_response = http_response.response_headers[ | |
571 'chrome-proxy-content-transform'] | |
572 if ('empty-image' in cpct_response): | |
573 self.assertTrue('empty-image' in cpat_request) | |
574 self.assertTrue(int(content_length) < 100) | |
575 return True; | |
576 return False; | |
577 else: | |
578 self.assertNotIn('chrome-proxy-accept-transform', | |
579 http_response.request_headers) | |
580 self.assertNotIn('chrome-proxy-content-transform', | |
581 http_response.response_headers) | |
582 content_length = http_response.response_headers['content-length'] | |
583 self.assertTrue(int(content_length) > 100) | |
Robert Ogden
2017/02/23 23:45:09
Nit: Is this always true? Asking mostly out of ign
megjablon
2017/02/23 23:47:09
For our test pages it will always be true, but if
| |
584 return False; | |
585 | |
551 @staticmethod | 586 @staticmethod |
552 def RunAllTests(run_all_tests=False): | 587 def RunAllTests(run_all_tests=False): |
553 """A simple helper method to run all tests using unittest.main(). | 588 """A simple helper method to run all tests using unittest.main(). |
554 | 589 |
555 Args: | 590 Args: |
556 run_all_tests: If True, all tests in the directory will be run, Otherwise | 591 run_all_tests: If True, all tests in the directory will be run, Otherwise |
557 only the tests in the file given on the command line will be run. | 592 only the tests in the file given on the command line will be run. |
558 """ | 593 """ |
559 flags = ParseFlags() | 594 flags = ParseFlags() |
560 logger = GetLogger() | 595 logger = GetLogger() |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 args[0].skipTest('This test runs on Mac OS only.') | 677 args[0].skipTest('This test runs on Mac OS only.') |
643 return wrapper | 678 return wrapper |
644 | 679 |
645 def NotMac(func): | 680 def NotMac(func): |
646 def wrapper(*args, **kwargs): | 681 def wrapper(*args, **kwargs): |
647 if sys.platform == 'darwin': | 682 if sys.platform == 'darwin': |
648 func(*args, **kwargs) | 683 func(*args, **kwargs) |
649 else: | 684 else: |
650 args[0].skipTest('This test does not run on Mac OS.') | 685 args[0].skipTest('This test does not run on Mac OS.') |
651 return wrapper | 686 return wrapper |
OLD | NEW |