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

Side by Side Diff: chrome/browser/web_dev_style/closure_lint_test.py

Issue 2592193002: Remove closure_linter from Chrome (Closed)
Patch Set: Created 4 years 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 | « chrome/browser/test_presubmit.py ('k') | chrome/browser/web_dev_style/js_checker.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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.
5
6 import js_checker
7 from os import path as os_path
8 import re
9 from sys import path as sys_path
10 import unittest
11
12 _HERE = os_path.dirname(os_path.abspath(__file__))
13 sys_path.append(os_path.join(_HERE, '..', '..', '..', 'build'))
14
15 import find_depot_tools # pylint: disable=W0611
16 from testing_support.super_mox import SuperMoxTestBase
17
18
19 class ClosureLintTest(SuperMoxTestBase):
20 def setUp(self):
21 SuperMoxTestBase.setUp(self)
22
23 input_api = self.mox.CreateMockAnything()
24 input_api.os_path = os_path
25 input_api.re = re
26
27 input_api.change = self.mox.CreateMockAnything()
28 self.mox.StubOutWithMock(input_api.change, 'RepositoryRoot')
29 src_root = os_path.join(os_path.dirname(__file__), '..', '..', '..')
30 input_api.change.RepositoryRoot().MultipleTimes().AndReturn(src_root)
31
32 output_api = self.mox.CreateMockAnything()
33
34 self.mox.ReplayAll()
35
36 self.checker = js_checker.JSChecker(input_api, output_api)
37
38 def ShouldPassClosureLint(self, source):
39 errors = self.checker.ClosureLint('', source=source)
40
41 for error in errors:
42 print 'Error: ' + error.message
43
44 self.assertListEqual([], errors)
45
46 def testBindFalsePositives(self):
47 sources = [
48 [
49 'var addOne = function(prop) {\n',
50 ' this[prop] += 1;\n',
51 '}.bind(counter, timer);\n',
52 '\n',
53 'setInterval(addOne, 1000);\n',
54 '\n',
55 ],
56 [
57 '/** Da clickz. */\n',
58 'button.onclick = function() { this.add_(this.total_); }.bind(this);\n',
59 ],
60 ]
61 for source in sources:
62 self.ShouldPassClosureLint(source)
63
64 def testPromiseFalsePositives(self):
65 sources = [
66 [
67 'Promise.reject(1).catch(function(error) {\n',
68 ' alert(error);\n',
69 '});\n',
70 ],
71 [
72 'var loaded = new Promise();\n',
73 'loaded.then(runAwesomeApp);\n',
74 'loaded.catch(showSadFace);\n',
75 '\n',
76 '/** Da loadz. */\n',
77 'document.onload = function() { loaded.resolve(); };\n',
78 '\n',
79 '/** Da errorz. */\n',
80 'document.onerror = function() { loaded.reject(); };\n',
81 '\n',
82 "if (document.readystate == 'complete') loaded.resolve();\n",
83 ],
84 ]
85 for source in sources:
86 self.ShouldPassClosureLint(source)
87
88
89 if __name__ == '__main__':
90 unittest.main()
OLDNEW
« no previous file with comments | « chrome/browser/test_presubmit.py ('k') | chrome/browser/web_dev_style/js_checker.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698