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

Unified Diff: tools/metrics/actions/extract_actions_test.py

Issue 1025673004: Extract actions from WebUI JS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dbeam + rebase Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « tools/metrics/actions/extract_actions.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698