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

Unified Diff: tools/telemetry/telemetry/page/actions/tap.py

Issue 323833003: Create ActionRunner wrapper API over TapAction and ClickElementAction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to head. Created 6 years, 6 months 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
Index: tools/telemetry/telemetry/page/actions/tap.py
diff --git a/tools/telemetry/telemetry/page/actions/tap.py b/tools/telemetry/telemetry/page/actions/tap.py
index a458dc0bc843f9c1742d9fc0f57634f8914c77f7..f369f1db447c984175b8c18054154e3d7f4d4d39 100644
--- a/tools/telemetry/telemetry/page/actions/tap.py
+++ b/tools/telemetry/telemetry/page/actions/tap.py
@@ -44,24 +44,28 @@ class TapAction(GestureAction):
util.FindElementAndPerformAction(tab, self.text, callback_code)
else:
if hasattr(self, 'element_function'):
+ # TODO(chrishenry): This special case is around to not break
+ # page sets in other repo. This special case will be deleted when
+ # these page sets are updated.
+ if self.element_function.strip().startswith('function(callback)'):
+ tab.ExecuteJavaScript('(%s)(function(element) { %s });' %
+ (self.element_function, js_cmd))
+ return
+
element_function = self.element_function
elif hasattr(self, 'selector'):
- element_cmd = ('document.querySelector(\'' +
- _EscapeSelector(self.selector) + '\')')
- element_function = 'function(callback) { callback(%s); }' % element_cmd
+ element_function = 'document.querySelector(\'%s\')' % _EscapeSelector(
+ self.selector)
elif hasattr(self, 'xpath'):
- element_cmd = ('document.evaluate("%s",'
- 'document,'
- 'null,'
- 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
- 'null)'
- '.singleNodeValue' % re.escape(self.xpath))
- element_function = 'function(callback) { callback(%s); }' % element_cmd
+ element_function = (
+ 'document.evaluate("%s", document, null, '
+ ' XPathResult.FIRST_ORDERED_NODE_TYPE, null)'
+ ' .singleNodeValue') % re.escape(self.xpath)
else:
assert False
- tab.ExecuteJavaScript('(%s)(function(element) { %s });' %
- (element_function, js_cmd))
+ tab.ExecuteJavaScript(
+ '(function(element) { %s })(%s)' % (js_cmd, element_function))
def RunGesture(self, tab):
left_position_percentage = 0.5

Powered by Google App Engine
This is Rietveld 408576698