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 _create_file(self, contents, filename): |
| 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 VerifyContentIsValid(self, contents, filename='fake.css'): |
| 49 self._create_file(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._create_file(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 25 matching lines...) Expand all Loading... |
88 } | 90 } |
89 </if>""", """ | 91 </if>""", """ |
90 - Alphabetize properties and list vendor specific (i.e. -webkit) above standard. | 92 - Alphabetize properties and list vendor specific (i.e. -webkit) above standard. |
91 display: block; | 93 display: block; |
92 color: red; | 94 color: red; |
93 | 95 |
94 z-index: 5; | 96 z-index: 5; |
95 color: black;""") | 97 color: black;""") |
96 | 98 |
97 def testCssStringWithAt(self): | 99 def testCssStringWithAt(self): |
98 self.VerifyContentsIsValid(""" | 100 self.VerifyContentIsValid(""" |
99 #logo { | 101 #logo { |
100 background-image: url(images/google_logo.png@2x); | 102 background-image: url(images/google_logo.png@2x); |
101 } | 103 } |
102 | 104 |
103 body.alternate-logo #logo { | 105 body.alternate-logo #logo { |
104 -webkit-mask-image: url(images/google_logo.png@2x); | 106 -webkit-mask-image: url(images/google_logo.png@2x); |
105 background: none; | 107 background: none; |
106 } | 108 } |
107 | 109 |
108 .stuff1 { | 110 .stuff1 { |
(...skipping 312 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 |