summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrdevlin.cronin <rdevlin.cronin@chromium.org>2016-03-10 15:25:58 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-10 23:27:37 +0000
commit953fd79d9cebebe12504985d3ef1c9291047425a (patch)
treebde900d2233522807a004a3f486ec47a79f7d7bc
parent0958a444aefc5b2847e46dff8bc6f82fb27ec6f1 (diff)
downloadchromium_src-953fd79d9cebebe12504985d3ef1c9291047425a.zip
chromium_src-953fd79d9cebebe12504985d3ef1c9291047425a.tar.gz
chromium_src-953fd79d9cebebe12504985d3ef1c9291047425a.tar.bz2
[Closure Externs] Add more APIs to the presubmit warning list
Add a bunch of private APIs to the list that will get presubmit checks. Also normalize the paths and check that each exists. BUG=469920 Review URL: https://codereview.chromium.org/1761663002 Cr-Commit-Position: refs/heads/master@{#380488}
-rw-r--r--chrome/common/extensions/api/PRESUBMIT.py51
-rw-r--r--extensions/common/api/externs_checker.py4
-rwxr-xr-xextensions/common/api/externs_checker_test.py9
3 files changed, 63 insertions, 1 deletions
diff --git a/chrome/common/extensions/api/PRESUBMIT.py b/chrome/common/extensions/api/PRESUBMIT.py
new file mode 100644
index 0000000..c4dc1aa
--- /dev/null
+++ b/chrome/common/extensions/api/PRESUBMIT.py
@@ -0,0 +1,51 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Chromium presubmit script for src/extensions/common.
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details on the presubmit API built into depot_tools.
+"""
+
+import sys
+
+
+def _CheckExterns(input_api, output_api):
+ original_sys_path = sys.path
+
+ join = input_api.os_path.join
+ api_root = input_api.PresubmitLocalPath()
+ src_root = join(api_root, '..', '..', '..', '..')
+ try:
+ sys.path.append(join(src_root, 'extensions', 'common', 'api'))
+ from externs_checker import ExternsChecker
+ finally:
+ sys.path = original_sys_path
+
+ externs_root = join(src_root, 'third_party', 'closure_compiler', 'externs')
+
+ api_pair_names = {
+ 'autofill_private.idl': 'autofill_private.js',
+ 'developer_private.idl': 'developer_private.js',
+ 'bookmark_manager_private.json': 'bookmark_manager_private.js',
+ 'command_line_private.json': 'command_line_private.js',
+ 'file_manager_private.idl': 'file_manager_private.js',
+ 'language_settings_private.idl': 'language_settings_private.js',
+ 'metrics_private.json': 'metrics_private.js',
+ 'passwords_private.idl': 'passwords_private.js',
+ 'system_private.json': 'system_private.js',
+ 'users_private.idl': 'users_private.js',
+ # TODO(rdevlin.cronin): Add more!
+ }
+ normpath = input_api.os_path.normpath
+ api_pairs = {
+ normpath(join(api_root, k)):
+ normpath(join(externs_root, v)) for k, v in api_pair_names.items()
+ }
+
+ return ExternsChecker(input_api, output_api, api_pairs).RunChecks()
+
+
+def CheckChangeOnUpload(input_api, output_api):
+ return _CheckExterns(input_api, output_api)
diff --git a/extensions/common/api/externs_checker.py b/extensions/common/api/externs_checker.py
index 58c0076..fd60fdd 100644
--- a/extensions/common/api/externs_checker.py
+++ b/extensions/common/api/externs_checker.py
@@ -12,6 +12,10 @@ class ExternsChecker(object):
self._output_api = output_api
self._api_pairs = api_pairs
+ for path in api_pairs.keys() + api_pairs.values():
+ if not input_api.os_path.exists(path):
+ raise OSError('Path Not Found: %s' % path)
+
def RunChecks(self):
bad_files = []
affected = [f.AbsoluteLocalPath() for f in self._input_api.AffectedFiles()]
diff --git a/extensions/common/api/externs_checker_test.py b/extensions/common/api/externs_checker_test.py
index 73b65fa..9bcc651 100755
--- a/extensions/common/api/externs_checker_test.py
+++ b/extensions/common/api/externs_checker_test.py
@@ -18,8 +18,9 @@ from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile
class ExternsCheckerTest(unittest.TestCase):
API_PAIRS = {'a': '1', 'b': '2', 'c': '3'}
- def _runChecks(self, files):
+ def _runChecks(self, files, exists=lambda f: True):
input_api = MockInputApi()
+ input_api.os_path.exists = exists
input_api.files = [MockFile(f, '') for f in files]
output_api = MockOutputApi()
checker = ExternsChecker(input_api, output_api, self.API_PAIRS)
@@ -58,6 +59,12 @@ class ExternsCheckerTest(unittest.TestCase):
self.assertEquals(1, len(results[0].items))
self.assertEquals('c', results[0].items[0])
+ def testApiFileDoesNotExist(self):
+ exists = lambda f: f in ['a', 'b', 'c', '1', '2']
+ with self.assertRaises(OSError) as e:
+ self._runChecks(['a'], exists)
+ self.assertEqual('Path Not Found: 3', str(e.exception))
+
if __name__ == '__main__':
unittest.main()