Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 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 self.assertEqual([], PRESUBMIT.CheckUserActionUpdate(mock_input_api, | |
| 26 MockOutputApi(), | |
| 27 _ACTION_XML_PATH)) | |
| 28 | |
| 29 def testValidChange_StartOfLine(self): | |
| 30 lines = ['<input id="testinput" pref="testpref"', | |
| 31 'metric="validaction" type="checkbox" dialog-pref>'] | |
| 32 self.assertEqual([], self._testChange(lines)) | |
| 33 | |
| 34 def testValidChange_StartsWithSpace(self): | |
| 35 lines = ['<input id="testinput" pref="testpref"', | |
| 36 ' metric="validaction" type="checkbox" dialog-pref>'] | |
| 37 self.assertEqual([], self._testChange(lines)) | |
| 38 | |
| 39 def testValidChange_Radio(self): | |
| 40 lines = ['<input id="testinput" pref="testpref"', | |
| 41 ' metric="validaction" type="radio" dialog-pref value="true">'] | |
| 42 self.assertEqual([], self._testChange(lines)) | |
| 43 | |
| 44 def testValidChange_UsingDatatype(self): | |
| 45 lines = ['<input id="testinput" pref="testpref"', | |
| 46 ' metric="validaction" datatype="boolean" dialog-pref>'] | |
| 47 self.assertEqual([], self._testChange(lines)) | |
| 48 | |
| 49 def testValidChange_NotBoolean(self): | |
| 50 lines = ['<input id="testinput" pref="testpref"', | |
| 51 ' metric="notboolean_validaction" dialog-pref>'] | |
| 52 self.assertEqual([], self._testChange(lines)) | |
| 53 | |
| 54 def testInvalidChange(self): | |
| 55 lines = ['<input id="testinput" pref="testpref"', | |
| 56 'metric="invalidaction" type="checkbox" dialog-pref>'] | |
| 57 warnings = self._testChange(lines) | |
| 58 self.assertEqual(1, len(warnings)) | |
| 59 | |
| 60 def testInValidChange_Radio(self): | |
| 61 lines = ['<input id="testinput" pref="testpref"', | |
| 62 ' metric="validaction" type="radio" dialog-pref value="string">'] | |
| 63 warnings = self._testChange(lines) | |
| 64 self.assertEqual(1, len(warnings)) | |
| 65 | |
| 66 def _testChange(self, lines): | |
| 67 action_xml_path = _TEST_DATA_DIR + "actions.xml" | |
| 68 mock_input_api = MockInputApi() | |
| 69 mock_input_api.files = [MockFile('path/test.html', lines)] | |
| 70 | |
| 71 return PRESUBMIT.CheckUserActionUpdate(mock_input_api, | |
| 72 MockOutputApi(), | |
|
M-A Ruel
2014/11/28 17:34:25
alignment. That's one of the reason I always use +
gayane -on leave until 09-2017
2014/11/28 20:43:14
Done.
| |
| 73 _ACTION_XML_PATH) | |
| 74 | |
| 75 | |
| 76 if __name__ == '__main__': | |
| 77 unittest.main() | |
| OLD | NEW |