| 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 |
| 11 | 11 |
| 12 sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname( | 12 sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname( |
| 13 os.path.abspath(__file__)))))) | 13 os.path.abspath(__file__)))))) |
| 14 from PRESUBMIT_test_mocks import MockFile, MockInputApi, MockOutputApi | 14 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
| 15 from PRESUBMIT_test_mocks import MockFile, MockChange |
| 15 | 16 |
| 16 class HTMLActionAdditionTest(unittest.TestCase): | 17 class HTMLActionAdditionTest(unittest.TestCase): |
| 17 | 18 |
| 18 def testActionXMLChanged(self): | 19 def testActionXMLChanged(self): |
| 19 mock_input_api = MockInputApi() | 20 mock_input_api = MockInputApi() |
| 20 mock_input_api.files = [ | 21 lines = ['<input id="testinput" pref="testpref"', |
| 21 MockFile('path/valid.html', ''), | 22 'metric="validaction" type="checkbox" dialog-pref>'] |
| 22 MockFile('actions.xml', '') ] | 23 mock_input_api.files = [MockFile('path/valid.html', lines)] |
| 23 | 24 mock_input_api.change = MockChange(['path/valid.html','actions.xml']) |
| 24 action_xml_path = self._createActionXMLFile() | 25 action_xml_path = self._createActionXMLFile() |
| 25 self.assertEqual([], PRESUBMIT.CheckUserActionUpdate(mock_input_api, | 26 self.assertEqual([], PRESUBMIT.CheckUserActionUpdate(mock_input_api, |
| 26 MockOutputApi(), | 27 MockOutputApi(), |
| 27 action_xml_path)) | 28 action_xml_path)) |
| 28 | 29 |
| 29 def testValidChange_StartOfLine(self): | 30 def testValidChange_StartOfLine(self): |
| 30 lines = ['<input id="testinput" pref="testpref"', | 31 lines = ['<input id="testinput" pref="testpref"', |
| 31 'metric="validaction" type="checkbox" dialog-pref>'] | 32 'metric="validaction" type="checkbox" dialog-pref>'] |
| 32 self.assertEqual([], self._testChange(lines)) | 33 self.assertEqual([], self._testChange(lines)) |
| 33 | 34 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 action_xml_path = os.path.join(sys_temp, 'actions_test.xml') | 92 action_xml_path = os.path.join(sys_temp, 'actions_test.xml') |
| 92 if not os.path.exists(action_xml_path): | 93 if not os.path.exists(action_xml_path): |
| 93 with open(action_xml_path, 'w+') as action_file: | 94 with open(action_xml_path, 'w+') as action_file: |
| 94 action_file.write(content) | 95 action_file.write(content) |
| 95 | 96 |
| 96 return action_xml_path | 97 return action_xml_path |
| 97 | 98 |
| 98 | 99 |
| 99 if __name__ == '__main__': | 100 if __name__ == '__main__': |
| 100 unittest.main() | 101 unittest.main() |
| OLD | NEW |