OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 import sys |
| 7 import imp |
| 8 import unittest |
| 9 import PRESUBMIT |
| 10 |
| 11 sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../../../')) |
| 12 from PRESUBMIT_test_mocks import MockFile, MockInputApi, MockOutputApi |
| 13 |
| 14 _TEST_DATA_DIR = 'base/test/data/presubmit/' |
| 15 _ACTION_XML_PATH = _TEST_DATA_DIR + "actions.xml" |
| 16 |
| 17 class HTMLActionAdditionTest(unittest.TestCase): |
| 18 |
| 19 def testActionXMLChanged(self): |
| 20 mock_input_api = MockInputApi() |
| 21 mock_input_api.files = [ |
| 22 MockFile('path/valid.html', ''), |
| 23 MockFile('actions.xml', '') ] |
| 24 |
| 25 warnings = PRESUBMIT.CheckUserActionUpdate(mock_input_api, |
| 26 MockOutputApi(), |
| 27 _ACTION_XML_PATH) |
| 28 self.assertEqual(0, len(warnings)) |
| 29 |
| 30 |
| 31 def testValidChange_StartOfLine(self): |
| 32 lines = ['<input id="testinput" pref="testpref"', |
| 33 'metric="validaction" type="checkbox" dialog-pref>'] |
| 34 warnings = self._testChange(lines) |
| 35 self.assertEqual(0, len(warnings)) |
| 36 |
| 37 |
| 38 def testValidChange_StartsWithSpace(self): |
| 39 lines = ['<input id="testinput" pref="testpref"', |
| 40 ' metric="validaction" type="checkbox" dialog-pref>'] |
| 41 warnings = self._testChange(lines) |
| 42 self.assertEqual(0, len(warnings)) |
| 43 |
| 44 |
| 45 def testValidChange_Radio(self): |
| 46 lines = ['<input id="testinput" pref="testpref"', |
| 47 ' metric="validaction" type="radio" dialog-pref value="true">'] |
| 48 warnings = self._testChange(lines) |
| 49 self.assertEqual(0, len(warnings)) |
| 50 |
| 51 |
| 52 def testValidChange_UsingDatatype(self): |
| 53 lines = ['<input id="testinput" pref="testpref"', |
| 54 ' metric="validaction" datatype="boolean" dialog-pref>'] |
| 55 warnings = self._testChange(lines) |
| 56 self.assertEqual(0, len(warnings)) |
| 57 |
| 58 |
| 59 def testValidChange_NotBoolean(self): |
| 60 lines = ['<input id="testinput" pref="testpref"', |
| 61 ' metric="notboolean_validaction" dialog-pref>'] |
| 62 warnings = self._testChange(lines) |
| 63 self.assertEqual(0, len(warnings)) |
| 64 |
| 65 |
| 66 def testInvalidChange(self): |
| 67 lines = ['<input id="testinput" pref="testpref"', |
| 68 'metric="invalidaction" type="checkbox" dialog-pref>'] |
| 69 warnings = self._testChange(lines) |
| 70 self.assertEqual(1, len(warnings)) |
| 71 |
| 72 |
| 73 def testInValidChange_Radio(self): |
| 74 lines = ['<input id="testinput" pref="testpref"', |
| 75 ' metric="validaction" type="radio" dialog-pref value="string">'] |
| 76 warnings = self._testChange(lines) |
| 77 self.assertEqual(1, len(warnings)) |
| 78 |
| 79 |
| 80 def _testChange(self, lines): |
| 81 action_xml_path = _TEST_DATA_DIR + "actions.xml" |
| 82 mock_input_api = MockInputApi() |
| 83 mock_input_api.files = [MockFile('path/test.html', lines)] |
| 84 |
| 85 return PRESUBMIT.CheckUserActionUpdate(mock_input_api, |
| 86 MockOutputApi(), |
| 87 _ACTION_XML_PATH) |
| 88 |
| 89 |
| 90 if __name__ == '__main__': |
| 91 unittest.main() |
OLD | NEW |