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 | |
| 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, args): | |
| 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(args + [ | |
| 47 '--host', 'fake-host', | |
| 48 '--input', self._tmp_src_dir, | |
| 49 '--out_folder', self._out_folder, | |
| 50 ]) | |
| 51 | |
| 52 def testSimpleVulcanize(self): | |
| 53 self._write_file_to_src_dir('element.html', '<div>got here!</div>') | |
| 54 self._write_file_to_src_dir('element.js', "alert('yay');") | |
| 55 self._write_file_to_src_dir('ui.html', ''' | |
| 56 <link rel="import" href="element.html"> | |
|
dpapad
2017/02/07 03:00:32
That's a good start. I think it would be valuable
Dan Beam
2017/02/07 03:02:39
#patcheswelcome, I named this "simple" for a reaso
dpapad
2017/02/07 03:44:21
I was not implying to do this in this CL. Mostly I
| |
| 57 <script src="element.js"></script> | |
| 58 ''') | |
| 59 | |
| 60 self._run_vulcanize(['--html_in_file', 'ui.html', | |
| 61 '--html_out_file', 'fast.html', | |
| 62 '--js_out_file', 'fast.js']) | |
| 63 | |
| 64 fast_html_css = self._read_out_file('fast.html') | |
|
dpapad
2017/02/07 03:00:32
I am confused by the '_css' suffix. Aren't we just
Dan Beam
2017/02/07 03:02:39
fixed in updated patch
| |
| 65 self.assertFalse('element.html' in fast_html_css) | |
| 66 self.assertFalse('element.js' in fast_html_css) | |
| 67 self.assertTrue('got here!' in fast_html_css) | |
| 68 | |
| 69 fast_js = self._read_out_file('fast.js') | |
| 70 self.assertTrue('yay' in fast_js) | |
| 71 | |
| 72 | |
| 73 if __name__ == '__main__': | |
| 74 unittest.main() | |
| OLD | NEW |