| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import gzip |
| 6 import os |
| 7 import re |
| 8 import shutil |
| 9 import subprocess |
| 10 import tempfile |
| 11 import unittest |
| 12 |
| 13 import loading_trace_analyzer |
| 14 |
| 15 LOADING_DIR = os.path.dirname(__file__) |
| 16 TEST_DATA_DIR = os.path.join(LOADING_DIR, 'testdata') |
| 17 |
| 18 |
| 19 class LoadingTraceAnalyzerTest(unittest.TestCase): |
| 20 _ROLLING_STONE = os.path.join(TEST_DATA_DIR, 'rollingstone.trace.gz') |
| 21 |
| 22 def setUp(self): |
| 23 self._temp_dir = tempfile.mkdtemp() |
| 24 self.trace_path = self._TmpPath('trace.json') |
| 25 with gzip.GzipFile(self._ROLLING_STONE) as f: |
| 26 with open(self.trace_path, 'w') as g: |
| 27 g.write(f.read()) |
| 28 |
| 29 def tearDown(self): |
| 30 shutil.rmtree(self._temp_dir) |
| 31 |
| 32 def _TmpPath(self, name): |
| 33 return os.path.join(self._temp_dir, name) |
| 34 |
| 35 def testRequestsCmd(self): |
| 36 lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path)] |
| 37 self.assertNotEqual(0, len(lines)) |
| 38 |
| 39 lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path, |
| 40 output_format='hello {protocol} world {url}')] |
| 41 self.assertNotEqual(0, len(lines)) |
| 42 for line in lines: |
| 43 self.assertTrue(re.match(r'^hello \S+ world \S+$', line)) |
| 44 |
| 45 lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path, |
| 46 where_format='{url}', where_statement=r'^http://.*$')] |
| 47 self.assertNotEqual(0, len(lines)) |
| 48 for line in lines: |
| 49 self.assertTrue(line.startswith('http://')) |
| 50 |
| 51 lines = [r for r in loading_trace_analyzer.ListRequests(self.trace_path, |
| 52 where_format='{url}', where_statement=r'^https://.*$')] |
| 53 self.assertNotEqual(0, len(lines)) |
| 54 for line in lines: |
| 55 self.assertTrue(line.startswith('https://')) |
| 56 |
| 57 |
| 58 if __name__ == '__main__': |
| 59 unittest.main() |
| OLD | NEW |