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 os 6 import unittest 7 8 from systrace import decorators 9 from systrace import update_systrace_trace_viewer 10 11 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 12 STABLE_VIEWER_PATH = os.path.join(SCRIPT_DIR, 'systrace_trace_viewer.html') 13 14 # Tests presence and content of static HTML files used not only for Python 15 # systrace capture, but also Java-based capture in the android SDK tools. 16 # 17 # NOTE: changes to this file should typically be accompanied by changes to the 18 # Android SDK's method of systrace capture. 19 class MonitorTest(unittest.TestCase): 20 21 @decorators.HostOnlyTest 22 def test_systrace_trace_viewer(self): 23 self.assertEqual(STABLE_VIEWER_PATH, 24 update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE) 25 26 update_systrace_trace_viewer.update(force_update=True) 27 28 with open(STABLE_VIEWER_PATH) as f: 29 content = f.read().strip() 30 31 # expect big html file 32 self.assertGreater(5 * 1024 * 1024, len(content)) 33 self.assertEqual('<', content[0]) 34 os.remove(f.name) 35 36 37 @decorators.HostOnlyTest 38 def test_prefix(self): 39 with open(os.path.join(SCRIPT_DIR, 'prefix.html')) as f: 40 content = f.read().strip() 41 42 self.assertTrue("<html>" in content) 43 self.assertTrue("<title>Android System Trace</title>" in content) 44 self.assertTrue("{{SYSTRACE_TRACE_VIEWER_HTML}}" in content) 45 46 47 @decorators.HostOnlyTest 48 def test_suffix(self): 49 with open(os.path.join(SCRIPT_DIR, 'suffix.html')) as f: 50 content = f.read().strip() 51 52 self.assertTrue("</html>" in content) 53