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
4 # found in the LICENSE file.
7 from os
import path
as os_path
9 from sys
import path
as sys_path
13 _HERE
= os_path
.dirname(os_path
.abspath(__file__
))
14 sys_path
.append(os_path
.join(_HERE
, '..', '..', '..', 'tools'))
16 import find_depot_tools
# pylint: disable=W0611
17 from testing_support
.super_mox
import SuperMoxTestBase
20 class HtmlCheckerTest(SuperMoxTestBase
):
22 SuperMoxTestBase
.setUp(self
)
24 input_api
= self
.mox
.CreateMockAnything()
26 output_api
= self
.mox
.CreateMockAnything()
27 self
.checker
= html_checker
.HtmlChecker(input_api
, output_api
)
29 def ShouldFailCheck(self
, line
, checker
):
30 """Checks that the |checker| flags |line| as a style error."""
31 error
= checker(1, line
)
32 self
.assertNotEqual('', error
, 'Should be flagged as style error: ' + line
)
33 highlight
= test_util
.GetHighlight(line
, error
).strip()
35 def ShouldPassCheck(self
, line
, checker
):
36 """Checks that the |checker| doesn't flag |line| as a style error."""
37 error
= checker(1, line
)
38 self
.assertEqual('', error
, 'Should not be flagged as style error: ' + line
)
40 def testClassesUseDashFormCheckFails(self
):
42 ' <a class="Foo-bar" href="classBar"> ',
43 '<b class="foo-Bar"> ',
44 '<i class="foo_bar" >',
45 ' <hr class="fooBar"> ',
48 self
.ShouldFailCheck(line
, self
.checker
.ClassesUseDashFormCheck
)
50 def testClassesUseDashFormCheckPasses(self
):
54 '<div class="foo-bar" id="classBar"',
57 self
.ShouldPassCheck(line
, self
.checker
.ClassesUseDashFormCheck
)
59 def testDoNotCloseSingleTagsCheckFails(self
):
68 self
.ShouldFailCheck(line
, self
.checker
.DoNotCloseSingleTagsCheck
)
70 def testDoNotCloseSingleTagsCheckPasses(self
):
78 self
.ShouldPassCheck(line
, self
.checker
.DoNotCloseSingleTagsCheck
)
80 def testDoNotUseBrElementCheckFails(self
):
89 line
, self
.checker
.DoNotUseBrElementCheck
)
91 def testDoNotUseBrElementCheckPasses(self
):
99 line
, self
.checker
.DoNotUseBrElementCheck
)
101 def testDoNotUseInputTypeButtonCheckFails(self
):
103 '<input type="button">',
104 ' <input id="a" type="button" >',
105 '<input type="button" id="a"> ',
108 self
.ShouldFailCheck(line
, self
.checker
.DoNotUseInputTypeButtonCheck
)
110 def testDoNotUseInputTypeButtonCheckPasses(self
):
113 '<input type="text">',
114 '<input type="result">',
115 '<input type="submit">',
117 '<button type="button">',
118 '<button type="reset">',
119 '<button type="submit">',
123 self
.ShouldPassCheck(line
, self
.checker
.DoNotUseInputTypeButtonCheck
)
125 def testI18nContentJavaScriptCaseCheckFails(self
):
127 ' i18n-content="foo-bar" ',
128 'i18n-content="foo_bar"',
129 'i18n-content="FooBar"',
130 'i18n-content="_foo"',
131 'i18n-content="foo_"',
132 'i18n-content="-foo"',
133 'i18n-content="foo-"',
134 'i18n-content="Foo"',
137 self
.ShouldFailCheck(line
, self
.checker
.I18nContentJavaScriptCaseCheck
)
139 def testI18nContentJavaScriptCaseCheckPasses(self
):
141 ' i18n-content="abc" ',
142 'i18n-content="fooBar"',
143 'i18n-content="validName" attr="invalidName_"',
144 '<div i18n-content="exampleTitle"',
147 self
.ShouldPassCheck(line
, self
.checker
.I18nContentJavaScriptCaseCheck
)
149 def testLabelCheckFails(self
):
157 self
.ShouldFailCheck(line
, self
.checker
.LabelCheck
)
159 def testLabelCheckPass(self
):
166 self
.ShouldPassCheck(line
, self
.checker
.LabelCheck
)
169 if __name__
== '__main__':