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
12 _HERE
= os_path
.dirname(os_path
.abspath(__file__
))
13 sys_path
.append(os_path
.join(_HERE
, '..', '..', '..', 'tools'))
15 import find_depot_tools
# pylint: disable=W0611
16 from testing_support
.super_mox
import SuperMoxTestBase
19 class ClosureLintTest(SuperMoxTestBase
):
21 SuperMoxTestBase
.setUp(self
)
23 input_api
= self
.mox
.CreateMockAnything()
24 input_api
.os_path
= os_path
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
)
32 output_api
= self
.mox
.CreateMockAnything()
36 self
.checker
= js_checker
.JSChecker(input_api
, output_api
)
38 def ShouldPassClosureLint(self
, source
):
39 errors
= self
.checker
.ClosureLint('', source
=source
)
42 print 'Error: ' + error
.message
44 self
.assertListEqual([], errors
)
46 def testBindFalsePositives(self
):
49 'var addOne = function(prop) {\n',
50 ' this[prop] += 1;\n',
51 '}.bind(counter, timer);\n',
53 'setInterval(addOne, 1000);\n',
57 '/** Da clickz. */\n',
58 'button.onclick = function() { this.add_(this.total_); }.bind(this);\n',
61 for source
in sources
:
62 self
.ShouldPassClosureLint(source
)
64 def testPromiseFalsePositives(self
):
67 'Promise.reject(1).catch(function(error) {\n',
72 'var loaded = new Promise();\n',
73 'loaded.then(runAwesomeApp);\n',
74 'loaded.catch(showSadFace);\n',
77 'document.onload = function() { loaded.resolve(); };\n',
79 '/** Da errorz. */\n',
80 'document.onerror = function() { loaded.reject(); };\n',
82 "if (document.readystate == 'complete') loaded.resolve();\n",
85 for source
in sources
:
86 self
.ShouldPassClosureLint(source
)
89 if __name__
== '__main__':