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

Unified Diff: telemetry/telemetry/internal/actions/pinch.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/page_action.py ('k') | telemetry/telemetry/internal/actions/play.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/actions/pinch.py
diff --git a/telemetry/telemetry/internal/actions/pinch.py b/telemetry/telemetry/internal/actions/pinch.py
index 5b4564dc137f04a9bf16374bbce8ec2247a57bd0..e3debe6ba6b9d2b299b37b8966b1700f1b16b1b8 100644
--- a/telemetry/telemetry/internal/actions/pinch.py
+++ b/telemetry/telemetry/internal/actions/pinch.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 PinchAction(page_action.PageAction):
@@ -35,12 +36,11 @@ class PinchAction(page_action.PageAction):
raise page_action.PageActionNotSupported(
'Synthetic pinch not supported for this browser')
- done_callback = 'function() { window.__pinchActionDone = true; }'
- # TODO(catapult:#3028): Fix interpolation of JavaScript values.
tab.ExecuteJavaScript("""
window.__pinchActionDone = false;
- window.__pinchAction = new __PinchAction(%s);"""
- % done_callback)
+ window.__pinchAction = new __PinchAction(function() {
+ window.__pinchActionDone = true;
+ });""")
@staticmethod
def _GetDefaultScaleFactorForPage(tab):
@@ -51,23 +51,23 @@ class PinchAction(page_action.PageAction):
def RunAction(self, tab):
scale_factor = (self._scale_factor if self._scale_factor else
PinchAction._GetDefaultScaleFactorForPage(tab))
- # 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.__pinchAction.start({
element: element,
- left_anchor_ratio: %s,
- top_anchor_ratio: %s,
- scale_factor: %s,
- speed: %s
+ left_anchor_ratio: {{ left_anchor_ratio }},
+ top_anchor_ratio: {{ top_anchor_ratio }},
+ scale_factor: {{ scale_factor }},
+ speed: {{ speed }}
});
- }''' % (self._left_anchor_ratio,
- self._top_anchor_ratio,
- scale_factor,
- self._speed)
+ }''',
+ left_anchor_ratio=self._left_anchor_ratio,
+ top_anchor_ratio=self._top_anchor_ratio,
+ scale_factor=scale_factor,
+ 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/page_action.py ('k') | telemetry/telemetry/internal/actions/play.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698