| Index: tools/metrics/actions/extract_actions_test.py
|
| diff --git a/tools/metrics/actions/extract_actions_test.py b/tools/metrics/actions/extract_actions_test.py
|
| index f755cd5b3fb71572b9a85023cf7f4ce471fc1f18..d1bc37ba06ec2c1ede91c078b7a027f62f1c4c24 100755
|
| --- a/tools/metrics/actions/extract_actions_test.py
|
| +++ b/tools/metrics/actions/extract_actions_test.py
|
| @@ -507,25 +507,29 @@ class ActionXmlTest(unittest.TestCase):
|
|
|
| def testUserMetricsActionSpanningTwoLines(self):
|
| code = 'base::UserMetricsAction(\n"Foo.Bar"));'
|
| - finder = extract_actions.ActionNameFinder('dummy', code)
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| self.assertEqual('Foo.Bar', finder.FindNextAction())
|
| self.assertFalse(finder.FindNextAction())
|
|
|
| def testUserMetricsActionAsAParam(self):
|
| code = 'base::UserMetricsAction("Test.Foo"), "Test.Bar");'
|
| - finder = extract_actions.ActionNameFinder('dummy', code)
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| self.assertEqual('Test.Foo', finder.FindNextAction())
|
| self.assertFalse(finder.FindNextAction())
|
|
|
| def testNonLiteralUserMetricsAction(self):
|
| code = 'base::UserMetricsAction(FOO)'
|
| - finder = extract_actions.ActionNameFinder('dummy', code)
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| with self.assertRaises(Exception):
|
| finder.FindNextAction()
|
|
|
| def testTernaryUserMetricsAction(self):
|
| code = 'base::UserMetricsAction(foo ? "Foo.Bar" : "Bar.Foo"));'
|
| - finder = extract_actions.ActionNameFinder('dummy', code)
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| with self.assertRaises(Exception):
|
| finder.FindNextAction()
|
|
|
| @@ -533,10 +537,78 @@ class ActionXmlTest(unittest.TestCase):
|
| code = """base::UserMetricsAction(
|
| foo_bar ? "Bar.Foo" :
|
| "Foo.Car")"""
|
| - finder = extract_actions.ActionNameFinder('dummy', code)
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| with self.assertRaises(extract_actions.InvalidStatementException):
|
| finder.FindNextAction()
|
|
|
| + def testUserMetricsActionWithExtraWhitespace(self):
|
| + code = """base::UserMetricsAction("Foo.Bar" )"""
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE)
|
| + with self.assertRaises(extract_actions.InvalidStatementException):
|
| + finder.FindNextAction()
|
| +
|
| + def testUserMetricsActionSpanningTwoLinesJs(self):
|
| + code = "chrome.send('coreOptionsUserMetricsAction',\n['Foo.Bar']);"
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertEqual('Foo.Bar', finder.FindNextAction())
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testNonLiteralUserMetricsActionJs(self):
|
| + code = "chrome.send('coreOptionsUserMetricsAction',\n[FOO]);"
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testTernaryUserMetricsActionJs(self):
|
| + code = ("chrome.send('coreOptionsUserMetricsAction', "
|
| + "[foo ? 'Foo.Bar' : 'Bar.Foo']);")
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testTernaryUserMetricsActionWithNewLinesJs(self):
|
| + code = """chrome.send('coreOptionsUserMetricsAction',
|
| + [foo ? 'Foo.Bar' :
|
| + 'Bar.Foo']);"""
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testUserMetricsActionWithExtraCharactersJs(self):
|
| + code = """chrome.send('coreOptionsUserMetricsAction',
|
| + ['Foo.Bar' + 1]);"""
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testComputedUserMetricsActionJs(self):
|
| + code = """chrome.send('coreOptionsUserMetricsAction',
|
| + ['Foo.' + foo_bar ? 'Bar' : 'Foo']);"""
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testUserMetricsActionWithMismatchedQuotes(self):
|
| + code = "chrome.send('coreOptionsUserMetricsAction', [\"Foo.Bar']);"
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testUserMetricsActionFromPropertyJs(self):
|
| + code = "chrome.send('coreOptionsUserMetricsAction', [objOrArray[key]]);"
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
| + def testUserMetricsActionFromFunctionJs(self):
|
| + code = "chrome.send('coreOptionsUserMetricsAction', [getAction(param)]);"
|
| + finder = extract_actions.ActionNameFinder('dummy', code,
|
| + extract_actions.USER_METRICS_ACTION_RE_JS)
|
| + self.assertFalse(finder.FindNextAction())
|
| +
|
|
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|