OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import unittest | 7 import unittest |
8 | 8 |
9 from compile import Checker | 9 from compile import Checker |
10 from processor import FileCache, Processor | 10 from processor import FileCache, Processor |
11 | 11 |
12 | 12 |
13 _SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 _SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
14 _SRC_DIR = os.path.join(_SCRIPT_DIR, os.pardir, os.pardir) | 14 _SRC_DIR = os.path.join(_SCRIPT_DIR, os.pardir, os.pardir) |
15 _RESOURCES_DIR = os.path.join(_SRC_DIR, "ui", "webui", "resources", "js") | 15 _RESOURCES_DIR = os.path.join(_SRC_DIR, "ui", "webui", "resources", "js") |
16 _ASSERT_JS = os.path.join(_RESOURCES_DIR, "assert.js") | 16 _ASSERT_JS = os.path.join(_RESOURCES_DIR, "assert.js") |
17 _CR_JS = os.path.join(_RESOURCES_DIR, "cr.js") | 17 _CR_JS = os.path.join(_RESOURCES_DIR, "cr.js") |
18 _CR_UI_JS = os.path.join(_RESOURCES_DIR, "cr", "ui.js") | 18 _CR_UI_JS = os.path.join(_RESOURCES_DIR, "cr", "ui.js") |
| 19 _POLYMER_EXTERNS = os.path.join(_SRC_DIR, "third_party", "polymer", "v0_8", |
| 20 "components-chromium", "polymer-externs", |
| 21 "polymer.externs.js") |
19 | 22 |
20 | 23 |
21 class CompilerCustomizationTest(unittest.TestCase): | 24 class CompilerCustomizationTest(unittest.TestCase): |
22 _ASSERT_DEFINITION = Processor(_ASSERT_JS).contents | 25 _ASSERT_DEFINITION = Processor(_ASSERT_JS).contents |
23 _CR_DEFINE_DEFINITION = Processor(_CR_JS).contents | 26 _CR_DEFINE_DEFINITION = Processor(_CR_JS).contents |
24 _CR_UI_DECORATE_DEFINITION = Processor(_CR_UI_JS).contents | 27 _CR_UI_DECORATE_DEFINITION = Processor(_CR_UI_JS).contents |
25 | 28 |
26 def setUp(self): | 29 def setUp(self): |
27 self._checker = Checker() | 30 self._checker = Checker() |
28 | 31 |
29 def _runChecker(self, source_code): | 32 def _runChecker(self, source_code): |
30 file_path = "/script.js" | 33 file_path = "/script.js" |
31 FileCache._cache[file_path] = source_code | 34 FileCache._cache[file_path] = source_code |
32 return self._checker.check(file_path) | 35 return self._checker.check(file_path, externs=[_POLYMER_EXTERNS]) |
33 | 36 |
34 def _runCheckerTestExpectError(self, source_code, expected_error): | 37 def _runCheckerTestExpectError(self, source_code, expected_error): |
35 _, stderr = self._runChecker(source_code) | 38 _, stderr = self._runChecker(source_code) |
36 | 39 |
37 self.assertTrue(expected_error in stderr, | 40 self.assertTrue(expected_error in stderr, |
38 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % ( | 41 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % ( |
39 expected_error, stderr)) | 42 expected_error, stderr)) |
40 | 43 |
41 def _runCheckerTestExpectSuccess(self, source_code): | 44 def _runCheckerTestExpectSuccess(self, source_code): |
42 found_errors, stderr = self._runChecker(source_code) | 45 found_errors, stderr = self._runChecker(source_code) |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 function f() { | 231 function f() { |
229 var a = document.createElement('div'); | 232 var a = document.createElement('div'); |
230 cr.ui.decorate(a, Class); | 233 cr.ui.decorate(a, Class); |
231 return a; | 234 return a; |
232 } | 235 } |
233 """) | 236 """) |
234 | 237 |
235 | 238 |
236 if __name__ == "__main__": | 239 if __name__ == "__main__": |
237 unittest.main() | 240 unittest.main() |
OLD | NEW |