| 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..c0868ca1258661cf2262a592e807fea54f1a6abc
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/PRESUBMIT_test.py
|
| @@ -0,0 +1,91 @@
|
| +# Copyright (c) 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 unittest
|
| +import PRESUBMIT
|
| +
|
| +sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../../../'))
|
| +from PRESUBMIT_test_mocks import MockFile, MockInputApi, MockOutputApi
|
| +
|
| +_TEST_DATA_DIR = 'base/test/data/presubmit/'
|
| +_ACTION_XML_PATH = _TEST_DATA_DIR + "actions.xml"
|
| +
|
| +class HTMLActionAdditionTest(unittest.TestCase):
|
| +
|
| + def testActionXMLChanged(self):
|
| + mock_input_api = MockInputApi()
|
| + mock_input_api.files = [
|
| + MockFile('path/valid.html', ''),
|
| + MockFile('actions.xml', '') ]
|
| +
|
| + warnings = PRESUBMIT.CheckUserActionUpdate(mock_input_api,
|
| + MockOutputApi(),
|
| + _ACTION_XML_PATH)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + def testValidChange_StartOfLine(self):
|
| + lines = ['<input id="testinput" pref="testpref"',
|
| + 'metric="validaction" type="checkbox" dialog-pref>']
|
| + warnings = self._testChange(lines)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + def testValidChange_StartsWithSpace(self):
|
| + lines = ['<input id="testinput" pref="testpref"',
|
| + ' metric="validaction" type="checkbox" dialog-pref>']
|
| + warnings = self._testChange(lines)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + def testValidChange_Radio(self):
|
| + lines = ['<input id="testinput" pref="testpref"',
|
| + ' metric="validaction" type="radio" dialog-pref value="true">']
|
| + warnings = self._testChange(lines)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + def testValidChange_UsingDatatype(self):
|
| + lines = ['<input id="testinput" pref="testpref"',
|
| + ' metric="validaction" datatype="boolean" dialog-pref>']
|
| + warnings = self._testChange(lines)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + def testValidChange_NotBoolean(self):
|
| + lines = ['<input id="testinput" pref="testpref"',
|
| + ' metric="notboolean_validaction" dialog-pref>']
|
| + warnings = self._testChange(lines)
|
| + self.assertEqual(0, len(warnings))
|
| +
|
| +
|
| + 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):
|
| + action_xml_path = _TEST_DATA_DIR + "actions.xml"
|
| + mock_input_api = MockInputApi()
|
| + mock_input_api.files = [MockFile('path/test.html', lines)]
|
| +
|
| + return PRESUBMIT.CheckUserActionUpdate(mock_input_api,
|
| + MockOutputApi(),
|
| + _ACTION_XML_PATH)
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|