summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgayane <gayane@chromium.org>2015-02-24 06:28:30 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-24 14:29:00 +0000
commit940df072ba1d09a1095d3c67bb5d06d6b1a4ba02 (patch)
treec9e3d600cc3f977f36bb88a589b07b7a474059f9
parent86c9a9b5470c3c1292fc7a8e7e276045ab0f512c (diff)
downloadchromium_src-940df072ba1d09a1095d3c67bb5d06d6b1a4ba02.zip
chromium_src-940df072ba1d09a1095d3c67bb5d06d6b1a4ba02.tar.gz
chromium_src-940df072ba1d09a1095d3c67bb5d06d6b1a4ba02.tar.bz2
Presubmit for chrome/browser/resources matches multiline metric type.
Also added a testcase for it and a nice print of errors. BUG=443026 Review URL: https://codereview.chromium.org/809053003 Cr-Commit-Position: refs/heads/master@{#317794}
-rw-r--r--PRESUBMIT_test_mocks.py3
-rw-r--r--chrome/browser/resources/PRESUBMIT.py6
-rw-r--r--chrome/browser/resources/PRESUBMIT_test.py12
3 files changed, 16 insertions, 5 deletions
diff --git a/PRESUBMIT_test_mocks.py b/PRESUBMIT_test_mocks.py
index 5caa156..03d9232 100644
--- a/PRESUBMIT_test_mocks.py
+++ b/PRESUBMIT_test_mocks.py
@@ -58,6 +58,9 @@ class MockOutputApi(object):
self.items = items
self.long_text = long_text
+ def __repr__(self):
+ return self.message
+
class PresubmitError(PresubmitResult):
def __init__(self, message, items, long_text=''):
MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
diff --git a/chrome/browser/resources/PRESUBMIT.py b/chrome/browser/resources/PRESUBMIT.py
index 9d6dfaa..502d47a 100644
--- a/chrome/browser/resources/PRESUBMIT.py
+++ b/chrome/browser/resources/PRESUBMIT.py
@@ -79,10 +79,10 @@ def IsBoolean(new_content_lines, metric_name, input_api):
new_content = '\n'.join(new_content_lines)
html_element_re = r'<(.*?)(^|\s+)metric\s*=\s*"%s"(.*?)>' % (metric_name)
- type_re = (r'datatype="boolean"|type="checkbox"|type="radio".*?'
- 'value=("true"|"false")')
+ type_re = (r'datatype\s*=\s*"boolean"|type\s*=\s*"checkbox"|'
+ 'type\s*=\s*"radio".*?value\s*=\s*("true"|"false")')
- match = input_api.re.search(html_element_re, new_content)
+ match = input_api.re.search(html_element_re, new_content, input_api.re.DOTALL)
return (match and
any(input_api.re.search(type_re, match.group(i)) for i in (1, 3)))
diff --git a/chrome/browser/resources/PRESUBMIT_test.py b/chrome/browser/resources/PRESUBMIT_test.py
index d46f3b7..923f2be 100644
--- a/chrome/browser/resources/PRESUBMIT_test.py
+++ b/chrome/browser/resources/PRESUBMIT_test.py
@@ -56,13 +56,21 @@ class HTMLActionAdditionTest(unittest.TestCase):
lines = ['<input id="testinput" pref="testpref"',
'metric="invalidaction" type="checkbox" dialog-pref>']
warnings = self._testChange(lines)
- self.assertEqual(1, len(warnings))
+ self.assertEqual(1, len(warnings), warnings)
def testInValidChange_Radio(self):
lines = ['<input id="testinput" pref="testpref"',
' metric="validaction" type="radio" dialog-pref value="string">']
warnings = self._testChange(lines)
- self.assertEqual(1, len(warnings))
+ self.assertEqual(1, len(warnings), warnings)
+
+ def testValidChange_MultilineType(self):
+ lines = ['<input id="testinput" pref="testpref"\n'
+ ' metric="validaction" type=\n'
+ ' "radio" dialog-pref value=\n'
+ ' "false">']
+ warnings = self._testChange(lines)
+ self.assertEqual([], self._testChange(lines))
def _testChange(self, lines):
mock_input_api = MockInputApi()