Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: tools/web_dev_style/js_checker_test.py

Issue 2907763004: js_checker.py: Replace custom GetElementByIdCheck with ESLint no-restricted-properties. (Closed)
Patch Set: Resolve conflicts. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 js_checker 6 import js_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 test_util 10 import test_util
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 def testExtraDotInGenericFails(self): 197 def testExtraDotInGenericFails(self):
198 lines = [ 198 lines = [
199 "/** @private {!Array.<!Frobber>} */", 199 "/** @private {!Array.<!Frobber>} */",
200 "var a = /** @type {Object.<number>} */({});", 200 "var a = /** @type {Object.<number>} */({});",
201 "* @return {!Promise.<Change>}" 201 "* @return {!Promise.<Change>}"
202 ] 202 ]
203 for line in lines: 203 for line in lines:
204 self.ShouldFailExtraDotInGenericCheck(line) 204 self.ShouldFailExtraDotInGenericCheck(line)
205 205
206 def ShouldFailGetElementByIdCheck(self, line):
207 """Checks that the 'getElementById' checker flags |line| as a style
208 error.
209 """
210 error = self.checker.GetElementByIdCheck(1, line)
211 self.assertNotEqual('', error,
212 'Should be flagged as style error: ' + line)
213 self.assertEqual(test_util.GetHighlight(line, error),
214 'document.getElementById')
215
216 def ShouldPassGetElementByIdCheck(self, line):
217 """Checks that the 'getElementById' checker doesn't flag |line| as a style
218 error.
219 """
220 self.assertEqual('', self.checker.GetElementByIdCheck(1, line),
221 'Should not be flagged as style error: ' + line)
222
223 def testGetElementByIdFails(self):
224 lines = [
225 "document.getElementById('foo');",
226 " document.getElementById('foo');",
227 "var x = document.getElementById('foo');",
228 "if (document.getElementById('foo').hidden) {",
229 ]
230 for line in lines:
231 self.ShouldFailGetElementByIdCheck(line)
232
233 def testGetElementByIdPasses(self):
234 lines = [
235 "elem.ownerDocument.getElementById('foo');",
236 " elem.ownerDocument.getElementById('foo');",
237 "var x = elem.ownerDocument.getElementById('foo');",
238 "if (elem.ownerDocument.getElementById('foo').hidden) {",
239 "doc.getElementById('foo');",
240 " doc.getElementById('foo');",
241 "cr.doc.getElementById('foo');",
242 " cr.doc.getElementById('foo');",
243 "var x = doc.getElementById('foo');",
244 "if (doc.getElementById('foo').hidden) {",
245 ]
246 for line in lines:
247 self.ShouldPassGetElementByIdCheck(line)
248
249 def ShouldFailInheritDocCheck(self, line): 206 def ShouldFailInheritDocCheck(self, line):
250 """Checks that the '@inheritDoc' checker flags |line| as a style error.""" 207 """Checks that the '@inheritDoc' checker flags |line| as a style error."""
251 error = self.checker.InheritDocCheck(1, line) 208 error = self.checker.InheritDocCheck(1, line)
252 self.assertNotEqual('', error, 209 self.assertNotEqual('', error,
253 msg='Should be flagged as style error: ' + line) 210 msg='Should be flagged as style error: ' + line)
254 self.assertEqual(test_util.GetHighlight(line, error), '@inheritDoc') 211 self.assertEqual(test_util.GetHighlight(line, error), '@inheritDoc')
255 212
256 def ShouldPassInheritDocCheck(self, line): 213 def ShouldPassInheritDocCheck(self, line):
257 """Checks that the '@inheritDoc' checker doesn't flag |line| as a style 214 """Checks that the '@inheritDoc' checker doesn't flag |line| as a style
258 error. 215 error.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in 348 " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in
392 # front of all these vars like 349 # front of all these vars like
393 "/** @const */ CONST_VAR = 1;", # this line has (<--). 350 "/** @const */ CONST_VAR = 1;", # this line has (<--).
394 ] 351 ]
395 for line in lines: 352 for line in lines:
396 self.ShouldPassVarNameCheck(line) 353 self.ShouldPassVarNameCheck(line)
397 354
398 355
399 if __name__ == '__main__': 356 if __name__ == '__main__':
400 unittest.main() 357 unittest.main()
OLDNEW
« no previous file with comments | « tools/web_dev_style/js_checker.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698