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

Unified Diff: chrome/browser/resources/PRESUBMIT_test.py

Issue 719463003: Presubmit checks for user actions intorduced in HTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments for mock classes Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/PRESUBMIT_test.py
diff --git a/chrome/browser/resources/PRESUBMIT_test.py b/chrome/browser/resources/PRESUBMIT_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..eccd5c9f29d78ae6df6464d16b95c1315eb816e2
--- /dev/null
+++ b/chrome/browser/resources/PRESUBMIT_test.py
@@ -0,0 +1,100 @@
+# Copyright 2014 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.
+
+import os
+import sys
+import imp
+import tempfile
+import unittest
+import PRESUBMIT
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(
+ os.path.abspath(__file__))))))
+from PRESUBMIT_test_mocks import MockFile, MockInputApi, MockOutputApi
+
+class HTMLActionAdditionTest(unittest.TestCase):
+
+ def testActionXMLChanged(self):
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [
+ MockFile('path/valid.html', ''),
+ MockFile('actions.xml', '') ]
+
+ action_xml_path = self._createActionXMLFile()
+ self.assertEqual([], PRESUBMIT.CheckUserActionUpdate(mock_input_api,
+ MockOutputApi(),
+ action_xml_path))
+
+ def testValidChange_StartOfLine(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ 'metric="validaction" type="checkbox" dialog-pref>']
+ self.assertEqual([], self._testChange(lines))
+
+ def testValidChange_StartsWithSpace(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ ' metric="validaction" type="checkbox" dialog-pref>']
+ self.assertEqual([], self._testChange(lines))
+
+ def testValidChange_Radio(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ ' metric="validaction" type="radio" dialog-pref value="true">']
+ self.assertEqual([], self._testChange(lines))
+
+ def testValidChange_UsingDatatype(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ ' metric="validaction" datatype="boolean" dialog-pref>']
+ self.assertEqual([], self._testChange(lines))
+
+ def testValidChange_NotBoolean(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ ' metric="notboolean_validaction" dialog-pref>']
+ self.assertEqual([], self._testChange(lines))
+
+ def testInvalidChange(self):
+ lines = ['<input id="testinput" pref="testpref"',
+ 'metric="invalidaction" type="checkbox" dialog-pref>']
+ warnings = self._testChange(lines)
+ self.assertEqual(1, len(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))
+
+ def _testChange(self, lines):
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [MockFile('path/test.html', lines)]
+
+ action_xml_path = self._createActionXMLFile()
+ return PRESUBMIT.CheckUserActionUpdate(mock_input_api,
+ MockOutputApi(),
+ action_xml_path)
+
+ def _createActionXMLFile(self):
+ content = ('<actions>'
+ '<action name="validaction_Disabled">'
+ ' <owner>Please list the metric\'s owners.</owner>'
+ ' <description>Enter the description of this user action.</description>'
+ '</action>'
+ '<action name="validaction_Enabled">'
+ ' <owner>Please list the metric\'s owners. </owner>'
+ ' <description>Enter the description of this user action.</description>'
+ '</action>'
+ '<action name="notboolean_validaction">'
+ ' <owner>Please list the metric\'s owners.</owner>'
+ ' <description>Enter the description of this user action.</description>'
+ '</action>'
+ '</actions>')
+ sys_temp = tempfile.gettempdir()
+ action_xml_path = os.path.join(sys_temp, 'actions_test.xml')
+ if not os.path.exists(action_xml_path):
+ with open(action_xml_path, 'w+') as action_file:
+ action_file.write(content)
+
+ return action_xml_path
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « chrome/browser/resources/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698