Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / web_dev_style / closure_lint_test.py
blobb9a7382ca8103308dd1caabf3d028463353b7a3a
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.
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
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):
20 def setUp(self):
21 SuperMoxTestBase.setUp(self)
23 input_api = self.mox.CreateMockAnything()
24 input_api.os_path = os_path
25 input_api.re = re
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()
34 self.mox.ReplayAll()
36 self.checker = js_checker.JSChecker(input_api, output_api)
38 def ShouldPassClosureLint(self, source):
39 errors = self.checker.ClosureLint('', source=source)
41 for error in errors:
42 print 'Error: ' + error.message
44 self.assertListEqual([], errors)
46 def testBindFalsePositives(self):
47 sources = [
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',
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):
65 sources = [
67 'Promise.reject(1).catch(function(error) {\n',
68 ' alert(error);\n',
69 '});\n',
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",
85 for source in sources:
86 self.ShouldPassClosureLint(source)
89 if __name__ == '__main__':
90 unittest.main()