OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 css_checker | 6 import css_checker |
7 from os import path as os_path | 7 from os import path as os_path |
8 import re | 8 import re |
9 from sys import path as sys_path | 9 from sys import path as sys_path |
10 import unittest | 10 import unittest |
11 | 11 |
12 _HERE = os_path.dirname(os_path.abspath(__file__)) | 12 _HERE = os_path.dirname(os_path.abspath(__file__)) |
13 sys_path.append(os_path.join(_HERE, '..', '..', '..', 'build')) | 13 sys_path.append(os_path.join(_HERE, '..', '..', '..', 'build')) |
14 | 14 |
15 import find_depot_tools # pylint: disable=W0611 | 15 import find_depot_tools # pylint: disable=W0611 |
16 from testing_support.super_mox import SuperMoxTestBase | 16 from testing_support.super_mox import SuperMoxTestBase |
17 | 17 |
18 | 18 |
19 class CssCheckerTest(SuperMoxTestBase): | 19 class CssCheckerTest(SuperMoxTestBase): |
20 def setUp(self): | 20 def setUp(self): |
21 SuperMoxTestBase.setUp(self) | 21 SuperMoxTestBase.setUp(self) |
22 | 22 |
23 self.fake_file_name = 'fake.css' | |
24 | |
25 self.fake_file = self.mox.CreateMockAnything() | 23 self.fake_file = self.mox.CreateMockAnything() |
24 # Actual calls to NewContents() and LocalPath() are defined in each test. | |
26 self.mox.StubOutWithMock(self.fake_file, 'LocalPath') | 25 self.mox.StubOutWithMock(self.fake_file, 'LocalPath') |
27 self.fake_file.LocalPath().AndReturn(self.fake_file_name) | |
28 # Actual calls to NewContents() are defined in each test. | |
29 self.mox.StubOutWithMock(self.fake_file, 'NewContents') | 26 self.mox.StubOutWithMock(self.fake_file, 'NewContents') |
30 | 27 |
31 self.input_api = self.mox.CreateMockAnything() | 28 self.input_api = self.mox.CreateMockAnything() |
32 self.input_api.re = re | 29 self.input_api.re = re |
33 self.mox.StubOutWithMock(self.input_api, 'AffectedSourceFiles') | 30 self.mox.StubOutWithMock(self.input_api, 'AffectedSourceFiles') |
34 self.input_api.AffectedFiles( | 31 self.input_api.AffectedFiles( |
35 include_deletes=False, file_filter=None).AndReturn([self.fake_file]) | 32 include_deletes=False, file_filter=None).AndReturn([self.fake_file]) |
36 | 33 |
37 # Actual creations of PresubmitPromptWarning are defined in each test. | 34 # Actual creations of PresubmitPromptWarning are defined in each test. |
38 self.output_api = self.mox.CreateMockAnything() | 35 self.output_api = self.mox.CreateMockAnything() |
39 self.mox.StubOutWithMock(self.output_api, 'PresubmitPromptWarning', | 36 self.mox.StubOutWithMock(self.output_api, 'PresubmitPromptWarning', |
40 use_mock_anything=True) | 37 use_mock_anything=True) |
41 | 38 |
42 self.output_api = self.mox.CreateMockAnything() | 39 self.output_api = self.mox.CreateMockAnything() |
43 self.mox.StubOutWithMock(self.output_api, 'PresubmitNotifyResult', | 40 self.mox.StubOutWithMock(self.output_api, 'PresubmitNotifyResult', |
44 use_mock_anything=True) | 41 use_mock_anything=True) |
45 | 42 |
46 def VerifyContentsIsValid(self, contents): | 43 def CreateFile(self, contents, filename): |
Dan Beam
2016/01/27 02:50:45
nit: this should probably be _create_file or __cre
tsergeant
2016/01/27 03:12:14
Done.
| |
44 self.fake_file_name = filename | |
45 self.fake_file.LocalPath().AndReturn(self.fake_file_name) | |
47 self.fake_file.NewContents().AndReturn(contents.splitlines()) | 46 self.fake_file.NewContents().AndReturn(contents.splitlines()) |
47 | |
48 def VerifyContentsIsValid(self, contents, filename='fake.css'): | |
Dan Beam
2016/01/27 02:50:45
nit: "contents are" or "content is"
tsergeant
2016/01/27 03:12:14
Done.
| |
49 self.CreateFile(contents, filename) | |
48 self.mox.ReplayAll() | 50 self.mox.ReplayAll() |
49 css_checker.CSSChecker(self.input_api, self.output_api).RunChecks() | 51 css_checker.CSSChecker(self.input_api, self.output_api).RunChecks() |
50 | 52 |
51 def VerifyContentsProducesOutput(self, contents, output): | 53 def VerifyContentsProducesOutput(self, contents, output, filename='fake.css'): |
52 self.fake_file.NewContents().AndReturn(contents.splitlines()) | 54 self.CreateFile(contents, filename) |
53 self.output_api.PresubmitPromptWarning( | 55 self.output_api.PresubmitPromptWarning( |
54 self.fake_file_name + ':\n' + output.strip()).AndReturn(None) | 56 self.fake_file_name + ':\n' + output.strip()).AndReturn(None) |
55 self.mox.ReplayAll() | 57 self.mox.ReplayAll() |
56 css_checker.CSSChecker(self.input_api, self.output_api).RunChecks() | 58 css_checker.CSSChecker(self.input_api, self.output_api).RunChecks() |
57 | 59 |
58 def testCssAlphaWithAtBlock(self): | 60 def testCssAlphaWithAtBlock(self): |
59 self.VerifyContentsProducesOutput(""" | 61 self.VerifyContentsProducesOutput(""" |
60 <include src="../shared/css/cr/ui/overlay.css"> | 62 <include src="../shared/css/cr/ui/overlay.css"> |
61 <include src="chrome://resources/totally-cool.css" /> | 63 <include src="chrome://resources/totally-cool.css" /> |
62 | 64 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 background-position-y: 0ex; | 423 background-position-y: 0ex; |
422 border-width: 0em; | 424 border-width: 0em; |
423 opacity: .0; | 425 opacity: .0; |
424 opacity: 0.0; | 426 opacity: 0.0; |
425 opacity: 0.; | 427 opacity: 0.; |
426 border-width: 0mm; | 428 border-width: 0mm; |
427 height: 0cm; | 429 height: 0cm; |
428 width: 0in; | 430 width: 0in; |
429 """) | 431 """) |
430 | 432 |
433 def testHtmlInlineStyle(self): | |
434 self.VerifyContentsProducesOutput("""<!doctype html> | |
435 <html> | |
436 <head> | |
437 <!-- Don't warn about problems outside of style tags | |
438 html, | |
439 body { | |
440 margin: 0; | |
441 height: 100%; | |
442 } | |
443 --> | |
444 <style> | |
445 body { | |
446 flex-direction:column; | |
447 } | |
448 </style> | |
449 </head> | |
450 </html>""", """ | |
451 - Colons (:) should have a space after them. | |
452 flex-direction:column; | |
453 """, filename='test.html') | |
454 | |
431 | 455 |
432 if __name__ == '__main__': | 456 if __name__ == '__main__': |
433 unittest.main() | 457 unittest.main() |
OLD | NEW |