Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 import shutil | |
| 8 import tempfile | |
| 9 import unittest | |
|
dpapad
2017/02/07 03:44:22
Is vulcanize_gn_test.py picked up automatically by
Dan Beam
2017/02/07 03:51:02
currently manual, we'd need to make it automated
| |
| 10 import vulcanize_gn | |
| 11 | |
| 12 | |
| 13 _HERE_DIR = os.path.dirname(__file__) | |
| 14 | |
| 15 | |
| 16 class VulcanizeGnTest(unittest.TestCase): | |
| 17 def setUp(self): | |
| 18 self._out_folder = None | |
| 19 self._tmp_dirs = [] | |
| 20 self._tmp_src_dir = None | |
| 21 | |
| 22 def tearDown(self): | |
| 23 for tmp_dir in self._tmp_dirs: | |
| 24 shutil.rmtree(tmp_dir) | |
| 25 | |
| 26 def _write_file_to_src_dir(self, file_name, file_contents): | |
| 27 if not self._tmp_src_dir: | |
| 28 self._tmp_src_dir = self._create_tmp_dir() | |
| 29 with open(os.path.join(self._tmp_src_dir, file_name), 'w') as tmp_file: | |
| 30 tmp_file.write(file_contents) | |
| 31 | |
| 32 def _create_tmp_dir(self): | |
| 33 # TODO(dbeam): support cross-drive paths (i.e. d:\ vs c:\). | |
| 34 tmp_dir = tempfile.mkdtemp(dir=_HERE_DIR) | |
| 35 self._tmp_dirs.append(tmp_dir) | |
| 36 return tmp_dir | |
| 37 | |
| 38 def _read_out_file(self, file_name): | |
| 39 assert self._out_folder | |
| 40 return open(os.path.join(self._out_folder, file_name), 'r').read() | |
| 41 | |
| 42 def _run_vulcanize(self, depfile, html_in_file, html_out_file, js_out_file): | |
| 43 # TODO(dbeam): make it possible to _run_vulcanize twice? Is that useful? | |
| 44 assert not self._out_folder | |
| 45 self._out_folder = self._create_tmp_dir() | |
| 46 vulcanize_gn.main([ | |
| 47 '--depfile', os.path.join(self._out_folder,'depfile.d'), | |
| 48 '--html_in_file', html_in_file, | |
| 49 '--html_out_file', html_out_file, | |
| 50 '--host', 'fake-host', | |
| 51 '--input', self._tmp_src_dir, | |
| 52 '--js_out_file', js_out_file, | |
| 53 '--out_folder', self._out_folder, | |
| 54 ]) | |
| 55 | |
| 56 | |
| 57 def testSimpleVulcanize(self): | |
| 58 self._write_file_to_src_dir('element.html', '<div>got here!</div>') | |
| 59 self._write_file_to_src_dir('element.js', "alert('yay');") | |
| 60 self._write_file_to_src_dir('ui.html', ''' | |
| 61 <link rel="import" href="element.html"> | |
| 62 <script src="element.js"></script> | |
| 63 ''') | |
| 64 | |
| 65 self._run_vulcanize(depfile='depfile.d', | |
| 66 html_in_file='ui.html', | |
| 67 html_out_file='fast.html', | |
| 68 js_out_file='fast.js') | |
| 69 | |
| 70 fast_html = self._read_out_file('fast.html') | |
| 71 self.assertFalse('element.html' in fast_html) | |
| 72 self.assertFalse('element.js' in fast_html) | |
| 73 self.assertTrue('got here!' in fast_html) | |
| 74 | |
| 75 fast_js = self._read_out_file('fast.js') | |
| 76 self.assertTrue('yay' in fast_js) | |
| 77 | |
| 78 depfile_d = self._read_out_file('depfile.d') | |
| 79 self.assertTrue('element.html' in depfile_d) | |
| 80 self.assertTrue('element.js' in depfile_d) | |
| 81 | |
| 82 | |
| 83 if __name__ == '__main__': | |
| 84 unittest.main() | |
| OLD | NEW |