Bug 1452597 - Remove debug_script functionality for injected scripts. r=maja_zf

The WebDriver:ExecuteScript and WebDriver:ExecuteAsyncScript commands
accepts a "debug_script" parameter that attaches an error handler
on the WindowProxy in the sandbox.

This used to be necessary because the error handler used to be
attached to the content window instead of the sandbox.

MozReview-Commit-ID: ImRVkC5T75O

--HG--
extra : rebase_source : c13c33b4d708879f66bd906f431157720842690c
This commit is contained in:
Andreas Tolfsen 2018-04-09 13:13:18 +01:00
Родитель 470c2e1592
Коммит 3e389d5b45
4 изменённых файлов: 3 добавлений и 38 удалений

Просмотреть файл

@ -1718,8 +1718,7 @@ class Marionette(object):
return self._from_json(rv) return self._from_json(rv)
def execute_async_script(self, script, script_args=(), new_sandbox=True, def execute_async_script(self, script, script_args=(), new_sandbox=True,
sandbox="default", script_timeout=None, sandbox="default", script_timeout=None):
debug_script=False):
"""Executes an asynchronous JavaScript script, and returns the """Executes an asynchronous JavaScript script, and returns the
result (or None if the script does return a value). result (or None if the script does return a value).
@ -1736,8 +1735,6 @@ class Marionette(object):
:param new_sandbox: If False, preserve global variables from :param new_sandbox: If False, preserve global variables from
the last execute_*script call. This is True by default, the last execute_*script call. This is True by default,
in which case no globals are preserved. in which case no globals are preserved.
:param debug_script: Capture javascript exceptions when in
`CONTEXT_CHROME` context.
Usage example: Usage example:
@ -1762,11 +1759,9 @@ class Marionette(object):
"sandbox": sandbox, "sandbox": sandbox,
"scriptTimeout": script_timeout, "scriptTimeout": script_timeout,
"line": int(frame[1]), "line": int(frame[1]),
"filename": filename, "filename": filename}
"debug_script": debug_script}
rv = self._send_message("WebDriver:ExecuteAsyncScript", rv = self._send_message("WebDriver:ExecuteAsyncScript", body, key="value")
body, key="value")
return self._from_json(rv) return self._from_json(rv)
def find_element(self, method, target, id=None): def find_element(self, method, target, id=None):

Просмотреть файл

@ -854,9 +854,6 @@ GeckoDriver.prototype.getContext = function() {
* Filename of the client's program where this script is evaluated. * Filename of the client's program where this script is evaluated.
* @param {number=} line * @param {number=} line
* Line in the client's program where this script is evaluated. * Line in the client's program where this script is evaluated.
* @param {boolean=} debug_script
* Attach an <code>onerror</code> event handler on the {@link Window}
* object. It does not differentiate content errors from chrome errors.
* *
* @return {(string|boolean|number|object|WebElement)} * @return {(string|boolean|number|object|WebElement)}
* Return value from the script, or null which signifies either the * Return value from the script, or null which signifies either the
@ -878,7 +875,6 @@ GeckoDriver.prototype.executeScript = async function(cmd, resp) {
newSandbox: cmd.parameters.newSandbox, newSandbox: cmd.parameters.newSandbox,
file: cmd.parameters.filename, file: cmd.parameters.filename,
line: cmd.parameters.line, line: cmd.parameters.line,
debug: cmd.parameters.debug_script,
}; };
resp.body.value = await this.execute_(script, args, opts); resp.body.value = await this.execute_(script, args, opts);
}; };
@ -926,9 +922,6 @@ GeckoDriver.prototype.executeScript = async function(cmd, resp) {
* Filename of the client's program where this script is evaluated. * Filename of the client's program where this script is evaluated.
* @param {number=} line * @param {number=} line
* Line in the client's program where this script is evaluated. * Line in the client's program where this script is evaluated.
* @param {boolean=} debug_script
* Attach an <code>onerror</code> event handler on the {@link Window}
* object. It does not differentiate content errors from chrome errors.
* *
* @return {(string|boolean|number|object|WebElement)} * @return {(string|boolean|number|object|WebElement)}
* Return value from the script, or null which signifies either the * Return value from the script, or null which signifies either the
@ -950,7 +943,6 @@ GeckoDriver.prototype.executeAsyncScript = async function(cmd, resp) {
newSandbox: cmd.parameters.newSandbox, newSandbox: cmd.parameters.newSandbox,
file: cmd.parameters.filename, file: cmd.parameters.filename,
line: cmd.parameters.line, line: cmd.parameters.line,
debug: cmd.parameters.debug_script,
async: true, async: true,
}; };
resp.body.value = await this.execute_(script, args, opts); resp.body.value = await this.execute_(script, args, opts);
@ -965,7 +957,6 @@ GeckoDriver.prototype.execute_ = async function(
newSandbox = false, newSandbox = false,
file = "", file = "",
line = 0, line = 0,
debug = false,
async = false, async = false,
} = {}) { } = {}) {
@ -984,7 +975,6 @@ GeckoDriver.prototype.execute_ = async function(
assert.boolean(newSandbox, pprint`Expected newSandbox to be boolean: ${newSandbox}`); assert.boolean(newSandbox, pprint`Expected newSandbox to be boolean: ${newSandbox}`);
assert.string(file, pprint`Expected file to be a string: ${file}`); assert.string(file, pprint`Expected file to be a string: ${file}`);
assert.number(line, pprint`Expected line to be a number: ${line}`); assert.number(line, pprint`Expected line to be a number: ${line}`);
assert.boolean(debug, pprint`Expected debug_script to be boolean: ${debug}`);
let opts = { let opts = {
timeout, timeout,
@ -992,7 +982,6 @@ GeckoDriver.prototype.execute_ = async function(
newSandbox, newSandbox,
file, file,
line, line,
debug,
async, async,
}; };

Просмотреть файл

@ -69,8 +69,6 @@ this.evaluate = {};
* @param {boolean=} [async=false] async * @param {boolean=} [async=false] async
* Indicates if the script should return immediately or wait for * Indicates if the script should return immediately or wait for
* the callback to be invoked before returning. * the callback to be invoked before returning.
* @param {boolean=} [debug=false] debug
* Attaches an <code>onerror</code> event listener.
* @param {string=} [file="dummy file"] file * @param {string=} [file="dummy file"] file
* File location of the program in the client. * File location of the program in the client.
* @param {number=} [line=0] line * @param {number=} [line=0] line
@ -94,7 +92,6 @@ this.evaluate = {};
evaluate.sandbox = function(sb, script, args = [], evaluate.sandbox = function(sb, script, args = [],
{ {
async = false, async = false,
debug = false,
file = "dummy file", file = "dummy file",
line = 0, line = 0,
sandboxName = null, sandboxName = null,
@ -131,17 +128,6 @@ evaluate.sandbox = function(sb, script, args = [],
sb[MARIONETTE_SCRIPT_FINISHED] = sb[CALLBACK]; sb[MARIONETTE_SCRIPT_FINISHED] = sb[CALLBACK];
} }
// onerror is not hooked on by default because of the inability to
// differentiate content errors from chrome errors.
//
// see bug 1128760 for more details
if (debug) {
sb.window.onerror = (msg, url, line) => {
let err = new JavaScriptError(`${msg} at ${url}:${line}`);
reject(err);
};
}
// timeout and unload handlers // timeout and unload handlers
scriptTimeoutID = setTimeout(timeoutHandler, timeout); scriptTimeoutID = setTimeout(timeoutHandler, timeout);
sb.window.onunload = unloadHandler; sb.window.onunload = unloadHandler;

Просмотреть файл

@ -142,8 +142,3 @@ marionetteScriptFinished(5);
var callback = arguments[arguments.length - 1]; var callback = arguments[arguments.length - 1];
setTimeout("callback(foo())", 50); setTimeout("callback(foo())", 50);
""") """)
self.assertRaises(JavascriptException,
self.marionette.execute_async_script, """
var callback = arguments[arguments.length - 1];
setTimeout("callback(foo())", 50);
""", debug_script=True)