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

Unified Diff: telemetry/telemetry/internal/actions/swipe.py

Issue 2559503002: [Telemetry] Fix JavaScript interpolation in telemetry actions (Closed)
Patch Set: inline js literals Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « telemetry/telemetry/internal/actions/seek.py ('k') | telemetry/telemetry/internal/actions/tap.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/actions/swipe.py
diff --git a/telemetry/telemetry/internal/actions/swipe.py b/telemetry/telemetry/internal/actions/swipe.py
index 05333ad443df2732a530653172c9682e32a602ff..ba6e9c656f95ae7c8b99b7202e393cddcdf5485c 100644
--- a/telemetry/telemetry/internal/actions/swipe.py
+++ b/telemetry/telemetry/internal/actions/swipe.py
@@ -4,6 +4,7 @@
from telemetry.internal.actions import page_action
from telemetry.internal.actions import utils
+from telemetry.util import js_template
class SwipeAction(page_action.PageAction):
@@ -44,36 +45,35 @@ class SwipeAction(page_action.PageAction):
raise page_action.PageActionNotSupported(
'Touch input not supported for this browser')
- done_callback = 'function() { window.__swipeActionDone = true; }'
- # TODO(catapult:#3028): Fix interpolation of JavaScript values.
tab.ExecuteJavaScript("""
window.__swipeActionDone = false;
- window.__swipeAction = new __SwipeAction(%s);"""
- % (done_callback))
+ window.__swipeAction = new __SwipeAction(function() {
+ window.__swipeActionDone = true;
+ });""")
def RunAction(self, tab):
if (self._selector is None and self._text is None and
self._element_function is None):
self._element_function = '(document.scrollingElement || document.body)'
- # TODO(catapult:#3028): Fix interpolation of JavaScript values.
- code = '''
+ code = js_template.Render('''
function(element, info) {
if (!element) {
throw Error('Cannot find element: ' + info);
}
window.__swipeAction.start({
element: element,
- left_start_ratio: %s,
- top_start_ratio: %s,
- direction: '%s',
- distance: %s,
- speed: %s
+ left_start_ratio: {{ left_start_ratio }},
+ top_start_ratio: {{ top_start_ratio }},
+ direction: {{ direction }},
+ distance: {{ distance }},
+ speed: {{ speed }}
});
- }''' % (self._left_start_ratio,
- self._top_start_ratio,
- self._direction,
- self._distance,
- self._speed)
+ }''',
+ left_start_ratio=self._left_start_ratio,
+ top_start_ratio=self._top_start_ratio,
+ direction=self._direction,
+ distance=self._distance,
+ speed=self._speed)
page_action.EvaluateCallbackWithElement(
tab, code, selector=self._selector, text=self._text,
element_function=self._element_function)
« no previous file with comments | « telemetry/telemetry/internal/actions/seek.py ('k') | telemetry/telemetry/internal/actions/tap.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698