| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import sys | 6 import sys |
| 7 import imp | 7 import imp |
| 8 import tempfile | 8 import tempfile |
| 9 import unittest | 9 import unittest |
| 10 import PRESUBMIT | 10 import PRESUBMIT |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 def testValidChange_NotBoolean(self): | 50 def testValidChange_NotBoolean(self): |
| 51 lines = ['<input id="testinput" pref="testpref"', | 51 lines = ['<input id="testinput" pref="testpref"', |
| 52 ' metric="notboolean_validaction" dialog-pref>'] | 52 ' metric="notboolean_validaction" dialog-pref>'] |
| 53 self.assertEqual([], self._testChange(lines)) | 53 self.assertEqual([], self._testChange(lines)) |
| 54 | 54 |
| 55 def testInvalidChange(self): | 55 def testInvalidChange(self): |
| 56 lines = ['<input id="testinput" pref="testpref"', | 56 lines = ['<input id="testinput" pref="testpref"', |
| 57 'metric="invalidaction" type="checkbox" dialog-pref>'] | 57 'metric="invalidaction" type="checkbox" dialog-pref>'] |
| 58 warnings = self._testChange(lines) | 58 warnings = self._testChange(lines) |
| 59 self.assertEqual(1, len(warnings)) | 59 self.assertEqual(1, len(warnings), warnings) |
| 60 | 60 |
| 61 def testInValidChange_Radio(self): | 61 def testInValidChange_Radio(self): |
| 62 lines = ['<input id="testinput" pref="testpref"', | 62 lines = ['<input id="testinput" pref="testpref"', |
| 63 ' metric="validaction" type="radio" dialog-pref value="string">'] | 63 ' metric="validaction" type="radio" dialog-pref value="string">'] |
| 64 warnings = self._testChange(lines) | 64 warnings = self._testChange(lines) |
| 65 self.assertEqual(1, len(warnings)) | 65 self.assertEqual(1, len(warnings), warnings) |
| 66 |
| 67 def testValidChange_MultilineType(self): |
| 68 lines = ['<input id="testinput" pref="testpref"\n' |
| 69 ' metric="validaction" type=\n' |
| 70 ' "radio" dialog-pref value=\n' |
| 71 ' "false">'] |
| 72 warnings = self._testChange(lines) |
| 73 self.assertEqual([], self._testChange(lines)) |
| 66 | 74 |
| 67 def _testChange(self, lines): | 75 def _testChange(self, lines): |
| 68 mock_input_api = MockInputApi() | 76 mock_input_api = MockInputApi() |
| 69 mock_input_api.files = [MockFile('path/test.html', lines)] | 77 mock_input_api.files = [MockFile('path/test.html', lines)] |
| 70 | 78 |
| 71 action_xml_path = self._createActionXMLFile() | 79 action_xml_path = self._createActionXMLFile() |
| 72 return PRESUBMIT.CheckUserActionUpdate(mock_input_api, | 80 return PRESUBMIT.CheckUserActionUpdate(mock_input_api, |
| 73 MockOutputApi(), | 81 MockOutputApi(), |
| 74 action_xml_path) | 82 action_xml_path) |
| 75 | 83 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 92 action_xml_path = os.path.join(sys_temp, 'actions_test.xml') | 100 action_xml_path = os.path.join(sys_temp, 'actions_test.xml') |
| 93 if not os.path.exists(action_xml_path): | 101 if not os.path.exists(action_xml_path): |
| 94 with open(action_xml_path, 'w+') as action_file: | 102 with open(action_xml_path, 'w+') as action_file: |
| 95 action_file.write(content) | 103 action_file.write(content) |
| 96 | 104 |
| 97 return action_xml_path | 105 return action_xml_path |
| 98 | 106 |
| 99 | 107 |
| 100 if __name__ == '__main__': | 108 if __name__ == '__main__': |
| 101 unittest.main() | 109 unittest.main() |
| OLD | NEW |