1# Copyright (c) 2014 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 5import codecs 6import os 7import tempfile 8import unittest 9 10from tracing.build import trace2html 11 12 13class Trace2HTMLTests(unittest.TestCase): 14 15 def test_writeHTMLForTracesToFile(self): 16 # Note: We can't use "with" when working with tempfile.NamedTemporaryFile as 17 # that does not work on Windows. We use the longer, more clunky version 18 # instead. See https://bugs.python.org/issue14243 for detials. 19 raw_tmpfile = tempfile.NamedTemporaryFile( 20 mode='w', suffix='.html', delete=False) 21 raw_tmpfile.close() 22 try: 23 with codecs.open(raw_tmpfile.name, 'w', encoding='utf-8') as tmpfile: 24 simple_trace_path = os.path.join( 25 os.path.dirname(__file__), 26 '..', 'test_data', 'simple_trace.json') 27 big_trace_path = os.path.join( 28 os.path.dirname(__file__), 29 '..', 'test_data', 'big_trace.json') 30 non_json_trace_path = os.path.join( 31 os.path.dirname(__file__), 32 '..', 'test_data', 'android_systrace.txt') 33 trace2html.WriteHTMLForTracesToFile( 34 [big_trace_path, simple_trace_path, non_json_trace_path], tmpfile) 35 finally: 36 os.remove(raw_tmpfile.name) 37