Bug 1337899 - [marionette] - Fix construction of script src.
Marionette builds the final javascript source to execute by
using the specified body, and wrapping it into an anonymouse
function.
Because all of this happens in a single line, a comment in
the last line of the script body will cause the source only
half-wise constructed, and the post-wrapping code assumed
as comment too.
MozReview-Commit-ID: CXtUKfr8jKO
--- a/testing/marionette/evaluate.js
+++ b/testing/marionette/evaluate.js
@@ -110,17 +110,19 @@ evaluate.sandbox = function(sb, script,
// callback function made private
// so that introspection is possible
// on the arguments object
if (async) {
sb[CALLBACK] = sb[COMPLETE];
src += `${ARGUMENTS}.push(rv => ${CALLBACK}(rv));`;
}
- src += `(function() { ${script} }).apply(null, ${ARGUMENTS})`;
+ src += `(function() {
+ ${script}
+ }).apply(null, ${ARGUMENTS})`;
// timeout and unload handlers
scriptTimeoutID = setTimeout(timeoutHandler, timeout);
sb.window.onunload = unloadHandler;
let res;
try {
res = Cu.evalInSandbox(src, sb, "1.8", file, line);
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
@@ -344,16 +344,19 @@ class TestExecuteContent(MarionetteTestC
return {
toJSON () {
return document.documentElement;
}
}""",
sandbox=None)
self.assert_is_web_element(el)
+ def test_comment_in_last_line(self):
+ self.marionette.execute_script(" // comment ")
+
@skip_if_mobile("Modal dialogs not supported in Fennec")
def test_return_value_on_alert(self):
res = self.marionette._send_message("WebDriver:ExecuteScript", {"script": "alert()"})
self.assertIn("value", res)
self.assertIsNone(res["value"])
class TestExecuteChrome(WindowManagerMixin, TestExecuteContent):