diff --git a/testing/marionette/jar.mn b/testing/marionette/jar.mn index e364c31012db..3bc49bc0eb3e 100644 --- a/testing/marionette/jar.mn +++ b/testing/marionette/jar.mn @@ -8,7 +8,7 @@ marionette.jar: content/marionette-listener.js (marionette-listener.js) content/marionette-elements.js (marionette-elements.js) content/marionette-sendkeys.js (marionette-sendkeys.js) - content/marionette-log-obj.js (marionette-log-obj.js) + content/marionette-common.js (marionette-common.js) content/marionette-simpletest.js (marionette-simpletest.js) content/EventUtils.js (EventUtils.js) content/ChromeUtils.js (ChromeUtils.js) diff --git a/testing/marionette/marionette-common.js b/testing/marionette/marionette-common.js new file mode 100644 index 000000000000..3b05560ea70f --- /dev/null +++ b/testing/marionette/marionette-common.js @@ -0,0 +1,85 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * + * This file contains common code that is shared between marionette-server.js + * and marionette-listener.js. + * + */ + +/** + * Creates an error message for a JavaScript exception thrown during + * execute_(async_)script. + * + * This will generate a [msg, trace] pair like: + * + * ['ReferenceError: foo is not defined', + * 'execute_script @test_foo.py, line 10 + * inline javascript, line 2 + * src: "return foo;"'] + * + * @param error An Error object passed to a catch() clause. + fnName The name of the function to use in the stack trace message + (e.g., 'execute_script'). + pythonFile The filename of the test file containing the Marionette + command that caused this exception to occur. + pythonLine The line number of the above test file. + script The JS script being executed in text form. + */ +this.createStackMessage = function createStackMessage(error, fnName, pythonFile, + pythonLine, script) { + let python_stack = fnName + " @" + pythonFile + ", line " + pythonLine; + let stack = error.stack.split("\n"); + let line = stack[0].substr(stack[0].lastIndexOf(':') + 1); + let msg = error.name + ": " + error.message; + let trace = python_stack + + "\ninline javascript, line " + line + + "\nsrc: \"" + script.split("\n")[line] + "\""; + return [msg, trace]; +} + +this.MarionetteLogObj = function MarionetteLogObj() { + this.logs = []; +} +MarionetteLogObj.prototype = { + /** + * Log message. Accepts user defined log-level. + * @param msg String + * The message to be logged + * @param level String + * The logging level to be used + */ + log: function ML_log(msg, level) { + let lev = level ? level : "INFO"; + this.logs.push( [lev, msg, (new Date()).toString()]); + }, + + /** + * Add a list of logs to its list + * @param msgs Object + * Takes a list of strings + */ + addLogs: function ML_addLogs(msgs) { + for (let i = 0; i < msgs.length; i++) { + this.logs.push(msgs[i]); + } + }, + + /** + * Return all logged messages. + */ + getLogs: function ML_getLogs() { + let logs = this.logs; + this.clearLogs(); + return logs; + }, + + /** + * Clears the logs + */ + clearLogs: function ML_clearLogs() { + this.logs = []; + }, +} diff --git a/testing/marionette/marionette-listener.js b/testing/marionette/marionette-listener.js index 61c5639f9d1c..c7a77d81d397 100644 --- a/testing/marionette/marionette-listener.js +++ b/testing/marionette/marionette-listener.js @@ -12,7 +12,7 @@ let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader); loader.loadSubScript("chrome://marionette/content/marionette-simpletest.js"); -loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js"); +loader.loadSubScript("chrome://marionette/content/marionette-common.js"); Cu.import("chrome://marionette/content/marionette-elements.js"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); @@ -279,35 +279,6 @@ function resetValues() { mouseEventsOnly = false; } -/** - * Creates an error message for a JavaScript exception thrown during - * execute_(async_)script. - * - * This will generate a [msg, trace] pair like: - * - * ['ReferenceError: foo is not defined', - * 'execute_script @test_foo.py, line 10 - * inline javascript, line 2 - * src: "return foo;"'] - * - * @param error An Error object passed to a catch() clause. - fnName The name of the function to use in the stack trace message - (e.g., 'execute_script'). - pythonFile The filename of the test file containing the Marionette - command that caused this exception to occur. - pythonLine The line number of the above test file. - script The JS script being executed in text form. - */ -function createStackMessage(error, fnName, pythonFile, pythonLine, script) { - let python_stack = fnName + " @" + pythonFile + ", line " + pythonLine; - let stack = error.stack.split("\n"); - let line = stack[0].substr(stack[0].lastIndexOf(':') + 1); - let msg = error.name + ": " + error.message; - let trace = python_stack + - "\ninline javascript, line " + line + - "\nsrc: \"" + script.split("\n")[line] + "\""; - return [msg, trace]; -} /* * Marionette Methods diff --git a/testing/marionette/marionette-log-obj.js b/testing/marionette/marionette-log-obj.js deleted file mode 100644 index 442e4e081536..000000000000 --- a/testing/marionette/marionette-log-obj.js +++ /dev/null @@ -1,47 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -this.MarionetteLogObj = function MarionetteLogObj() { - this.logs = []; -} -MarionetteLogObj.prototype = { - /** - * Log message. Accepts user defined log-level. - * @param msg String - * The message to be logged - * @param level String - * The logging level to be used - */ - log: function ML_log(msg, level) { - let lev = level ? level : "INFO"; - this.logs.push( [lev, msg, (new Date()).toString()]); - }, - - /** - * Add a list of logs to its list - * @param msgs Object - * Takes a list of strings - */ - addLogs: function ML_addLogs(msgs) { - for (let i = 0; i < msgs.length; i++) { - this.logs.push(msgs[i]); - } - }, - - /** - * Return all logged messages. - */ - getLogs: function ML_getLogs() { - let logs = this.logs; - this.clearLogs(); - return logs; - }, - - /** - * Clears the logs - */ - clearLogs: function ML_clearLogs() { - this.logs = []; - }, -} diff --git a/testing/marionette/marionette-server.js b/testing/marionette/marionette-server.js index c94ce9eb9a70..2a5ccc22a6da 100644 --- a/testing/marionette/marionette-server.js +++ b/testing/marionette/marionette-server.js @@ -14,7 +14,7 @@ logger.info('marionette-server.js loaded'); let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader); loader.loadSubScript("chrome://marionette/content/marionette-simpletest.js"); -loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js"); +loader.loadSubScript("chrome://marionette/content/marionette-common.js"); Cu.import("chrome://marionette/content/marionette-elements.js"); let utils = {}; loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils); @@ -380,37 +380,6 @@ MarionetteServerConnection.prototype = { this.sendToClient({from:this.actorID, error: error_msg}, command_id); }, - /** - * Creates an error message for a JavaScript exception thrown during - * execute_(async_)script. - * - * This will generate a [msg, trace] pair like: - * - * ['ReferenceError: foo is not defined', - * 'execute_script @test_foo.py, line 10 - * inline javascript, line 2 - * src: "return foo;"'] - * - * @param error An Error object passed to a catch() clause. - fnName The name of the function to use in the stack trace message - (e.g., 'execute_script'). - pythonFile The filename of the test file containing the Marionette - command that caused this exception to occur. - pythonLine The line number of the above test file. - script The JS script being executed in text form. - */ - createStackMessage: function MDA_createStackMessage(error, fnName, pythonFile, - pythonLine, script) { - let python_stack = fnName + " @" + pythonFile + ", line " + pythonLine; - let stack = error.stack.split("\n"); - let line = stack[0].substr(stack[0].lastIndexOf(':') + 1); - let msg = error.name + ": " + error.message; - let trace = python_stack + - "\ninline javascript, line " + line + - "\nsrc: \"" + script.split("\n")[line] + "\""; - return [msg, trace]; - }, - /** * Gets the current active window * @@ -848,11 +817,11 @@ MarionetteServerConnection.prototype = { false, command_id, timeout); } catch (e) { - let error = this.createStackMessage(e, - "execute_script", - aRequest.filename, - aRequest.line, - script); + let error = createStackMessage(e, + "execute_script", + aRequest.filename, + aRequest.line, + script); this.sendError(error[0], 17, error[1], command_id); } }, @@ -1036,11 +1005,11 @@ MarionetteServerConnection.prototype = { this.executeScriptInSandbox(_chromeSandbox, script, directInject, true, command_id, timeout); } catch (e) { - let error = this.createStackMessage(e, - "execute_async_script", - aRequest.filename, - aRequest.line, - script); + let error = createStackMessage(e, + "execute_async_script", + aRequest.filename, + aRequest.line, + script); chromeAsyncReturnFunc(error[0], 17, error[1]); } },