Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: chrome/browser/resources/PRESUBMIT_test.py

Issue 719463003: Presubmit checks for user actions intorduced in HTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits and clean up Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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__) + '/../../../'))
M-A Ruel 2014/11/26 20:43:27 Normally, it's safer to do: os.path.dirname(os.pa
gayane -on leave until 09-2017 2014/11/26 21:57:28 Do you mean to have something like this? sys.path.
M-A Ruel 2014/11/28 17:34:24 Yes but if it works, it's fine with me.
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))
M-A Ruel 2014/11/26 20:43:27 I meant for this one too.
gayane -on leave until 09-2017 2014/11/26 21:57:28 Done.
29
30 def testValidChange_StartOfLine(self):
31 lines = ['<input id="testinput" pref="testpref"',
32 'metric="validaction" type="checkbox" dialog-pref>']
33 self.assertEqual([], self._testChange(lines))
34
35 def testValidChange_StartsWithSpace(self):
36 lines = ['<input id="testinput" pref="testpref"',
37 ' metric="validaction" type="checkbox" dialog-pref>']
38 self.assertEqual([], self._testChange(lines))
39
40 def testValidChange_Radio(self):
41 lines = ['<input id="testinput" pref="testpref"',
42 ' metric="validaction" type="radio" dialog-pref value="true">']
43 self.assertEqual([], self._testChange(lines))
44
45 def testValidChange_UsingDatatype(self):
46 lines = ['<input id="testinput" pref="testpref"',
47 ' metric="validaction" datatype="boolean" dialog-pref>']
48 self.assertEqual([], self._testChange(lines))
49
50 def testValidChange_NotBoolean(self):
51 lines = ['<input id="testinput" pref="testpref"',
52 ' metric="notboolean_validaction" dialog-pref>']
53 self.assertEqual([], self._testChange(lines))
54
55 def testInvalidChange(self):
56 lines = ['<input id="testinput" pref="testpref"',
57 'metric="invalidaction" type="checkbox" dialog-pref>']
58 warnings = self._testChange(lines)
59 self.assertEqual(1, len(warnings))
60
61 def testInValidChange_Radio(self):
62 lines = ['<input id="testinput" pref="testpref"',
63 ' metric="validaction" type="radio" dialog-pref value="string">']
64 warnings = self._testChange(lines)
65 self.assertEqual(1, len(warnings))
66
67 def _testChange(self, lines):
68 action_xml_path = _TEST_DATA_DIR + "actions.xml"
69 mock_input_api = MockInputApi()
70 mock_input_api.files = [MockFile('path/test.html', lines)]
71
72 return PRESUBMIT.CheckUserActionUpdate(mock_input_api,
73 MockOutputApi(),
74 _ACTION_XML_PATH)
75
76
77 if __name__ == '__main__':
78 unittest.main()
OLDNEW
« chrome/browser/resources/PRESUBMIT.py ('K') | « chrome/browser/resources/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698