| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 json |
| 5 import os | 6 import os |
| 6 import unittest | 7 import unittest |
| 7 import zipfile | |
| 8 | 8 |
| 9 from profile_chrome import profiler | 9 from profile_chrome import profiler |
| 10 from profile_chrome import ui | 10 from profile_chrome import ui |
| 11 from profile_chrome import fake_agent_1 | 11 from profile_chrome import fake_agent_1 |
| 12 from profile_chrome import fake_agent_2 | 12 from profile_chrome import fake_agent_2 |
| 13 from systrace import decorators | 13 from systrace import decorators |
| 14 from systrace import tracing_controller | 14 from systrace import tracing_controller |
| 15 | 15 |
| 16 | 16 |
| 17 class ProfilerTest(unittest.TestCase): | 17 class ProfilerTest(unittest.TestCase): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 finally: | 30 finally: |
| 31 if os.path.exists(result): | 31 if os.path.exists(result): |
| 32 os.remove(result) | 32 os.remove(result) |
| 33 | 33 |
| 34 @decorators.ClientOnlyTest | 34 @decorators.ClientOnlyTest |
| 35 def testCaptureJsonProfile(self): | 35 def testCaptureJsonProfile(self): |
| 36 result = profiler.CaptureProfile(self._tracing_options, 1, | 36 result = profiler.CaptureProfile(self._tracing_options, 1, |
| 37 [fake_agent_2], write_json=True) | 37 [fake_agent_2], write_json=True) |
| 38 | 38 |
| 39 try: | 39 try: |
| 40 self.assertFalse(result.endswith('.html')) | 40 self.assertTrue(result.endswith('.json')) |
| 41 with open(result) as f: | 41 with open(result) as f: |
| 42 self.assertEquals(f.read(), 'fake-contents') | 42 trace_data = json.load(f) |
| 43 self.assertListEqual(trace_data['cpuSnapshots'], ['fake-contents']) |
| 43 finally: | 44 finally: |
| 44 if os.path.exists(result): | 45 if os.path.exists(result): |
| 45 os.remove(result) | 46 os.remove(result) |
| 46 | 47 |
| 47 @decorators.ClientOnlyTest | 48 @decorators.ClientOnlyTest |
| 48 def testCaptureMultipleProfiles(self): | 49 def testCaptureMultipleProfiles(self): |
| 49 result = profiler.CaptureProfile(self._tracing_options, 1, | 50 result = profiler.CaptureProfile(self._tracing_options, 1, |
| 50 [fake_agent_1, fake_agent_2], | 51 [fake_agent_1, fake_agent_2], |
| 51 write_json=True) | 52 write_json=True) |
| 52 | 53 |
| 53 try: | 54 try: |
| 54 self.assertTrue(result.endswith('.zip')) | 55 self.assertTrue(result.endswith('.json')) |
| 55 self.assertTrue(zipfile.is_zipfile(result)) | 56 with open(result, 'r') as fp: |
| 57 json.load(fp) |
| 56 finally: | 58 finally: |
| 57 if os.path.exists(result): | 59 if os.path.exists(result): |
| 58 os.remove(result) | 60 os.remove(result) |
| OLD | NEW |