| 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 os | 7 import os |
| 8 import re | 8 import re |
| 9 import socket | 9 import socket |
| 10 import shlex | 10 import shlex |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 @property | 361 @property |
| 362 def request_type(self): | 362 def request_type(self): |
| 363 return self._request_type | 363 return self._request_type |
| 364 | 364 |
| 365 def ResponseHasViaHeader(self): | 365 def ResponseHasViaHeader(self): |
| 366 return 'via' in self._response_headers and (self._response_headers['via'] == | 366 return 'via' in self._response_headers and (self._response_headers['via'] == |
| 367 self._flags.via_header_value) | 367 self._flags.via_header_value) |
| 368 | 368 |
| 369 def WasXHR(self): | 369 def WasXHR(self): |
| 370 return self.request_type == 'XHR' | 370 return self.request_type == 'XHR' |
| 371 | |
| 372 class IntegrationTest: | |
| 373 """A parent class for all integration tests with utility and assertion | |
| 374 methods. | |
| 375 | |
| 376 All methods starting with the word 'test' (ignoring case) will be called with | |
| 377 the RunAllTests() method which can be used in place of a main method. | |
| 378 """ | |
| 379 def RunAllTests(self): | |
| 380 """Runs all methods starting with the word 'test' (ignoring case) in the | |
| 381 class. | |
| 382 | |
| 383 Can be used in place of a main method to run all tests in a class. | |
| 384 """ | |
| 385 methodList = [method for method in dir(self) if callable(getattr(self, | |
| 386 method)) and method.lower().startswith('test')] | |
| 387 for method in methodList: | |
| 388 try: | |
| 389 getattr(self, method)() | |
| 390 except Exception as e: | |
| 391 # Uses the Exception tuple from sys.exec_info(). | |
| 392 HandleException(method) | |
| 393 | |
| 394 # TODO(robertogden): Add some nice assertion functions. | |
| 395 | |
| 396 def Fail(self, msg): | |
| 397 """Called when a test fails an assertion. | |
| 398 | |
| 399 Args: | |
| 400 msg: The string message to print to stderr | |
| 401 """ | |
| 402 sys.stderr.write("**************************************\n") | |
| 403 sys.stderr.write("**************************************\n") | |
| 404 sys.stderr.write("** **\n") | |
| 405 sys.stderr.write("** TEST FAILURE **\n") | |
| 406 sys.stderr.write("** **\n") | |
| 407 sys.stderr.write("**************************************\n") | |
| 408 sys.stderr.write("**************************************\n") | |
| 409 sys.stderr.write(msg, '\n') | |
| 410 sys.exit(1) | |
| OLD | NEW |