| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 import extract_actions | 8 import extract_actions |
| 9 | 9 |
| 10 # Empty value to be inserted to |ACTIONS_MOCK|. | 10 # Empty value to be inserted to |ACTIONS_MOCK|. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 '<!--comment-->\n\n' | 107 '<!--comment-->\n\n' |
| 108 '<actions>\n\n' | 108 '<actions>\n\n' |
| 109 '<action name="action1">\n' | 109 '<action name="action1">\n' |
| 110 ' <owner>name1@google.com</owner>\n' | 110 ' <owner>name1@google.com</owner>\n' |
| 111 ' <owner>name2@google.com</owner>\n' | 111 ' <owner>name2@google.com</owner>\n' |
| 112 ' <description>Description.</description>\n' | 112 ' <description>Description.</description>\n' |
| 113 '</action>\n\n' | 113 '</action>\n\n' |
| 114 '</actions>\n' | 114 '</actions>\n' |
| 115 ) | 115 ) |
| 116 | 116 |
| 117 | |
| 118 class ActionXmlTest(unittest.TestCase): | 117 class ActionXmlTest(unittest.TestCase): |
| 119 | 118 |
| 120 def _GetProcessedAction(self, owner, description, obsolete, new_actions=[], | 119 def _GetProcessedAction(self, owner, description, obsolete, new_actions=[], |
| 121 comment=NO_VALUE): | 120 comment=NO_VALUE): |
| 122 """Forms an actions XML string and returns it after processing. | 121 """Forms an actions XML string and returns it after processing. |
| 123 | 122 |
| 124 It parses the original XML string, adds new user actions (if there is any), | 123 It parses the original XML string, adds new user actions (if there is any), |
| 125 and pretty prints it. | 124 and pretty prints it. |
| 126 | 125 |
| 127 Args: | 126 Args: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 def testAddNewActions(self): | 186 def testAddNewActions(self): |
| 188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 187 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 189 new_actions=['action2']) | 188 new_actions=['action2']) |
| 190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) | 189 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) |
| 191 | 190 |
| 192 def testComment(self): | 191 def testComment(self): |
| 193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 192 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 194 comment=COMMENT) | 193 comment=COMMENT) |
| 195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) | 194 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) |
| 196 | 195 |
| 196 def testUserMetricsActionSpanningTwoLines(self): |
| 197 code = 'base::UserMetricsAction(\n"Foo.Bar"));' |
| 198 names, _ = extract_actions.FindActionNames(code, 0) |
| 199 self.assertEqual(['Foo.Bar'], names) |
| 200 |
| 201 def testTernaryUserMetricsAction(self): |
| 202 code = 'base::UserMetricsAction(foo ? "Foo.Bar" : "Bar.Foo"));' |
| 203 names, _ = extract_actions.FindActionNames(code, 0) |
| 204 self.assertEqual(['Foo.Bar', 'Bar.Foo'], names) |
| 205 |
| 206 def testUserMetricsActionAsAParam(self): |
| 207 code = 'base::UserMetricsAction("Test.Foo"), "Test.Bar");' |
| 208 names, _ = extract_actions.FindActionNames(code, 0) |
| 209 self.assertEqual(['Test.Foo'], names) |
| 197 | 210 |
| 198 if __name__ == '__main__': | 211 if __name__ == '__main__': |
| 199 unittest.main() | 212 unittest.main() |
| OLD | NEW |