Bug 885940 - Move common code inato marionette-common.js, r=mdas

--HG--
rename : testing/marionette/marionette-log-obj.js => testing/marionette/marionette-common.js
This commit is contained in:
Jonathan Griffin 2013-06-28 14:07:55 -07:00
parent 5ece5b7fe9
commit 5457563e70
5 changed files with 98 additions and 120 deletions

View File

@ -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)

View File

@ -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 = [];
},
}

View File

@ -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

View File

@ -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 = [];
},
}

View File

@ -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,7 +817,7 @@ MarionetteServerConnection.prototype = {
false, command_id, timeout);
}
catch (e) {
let error = this.createStackMessage(e,
let error = createStackMessage(e,
"execute_script",
aRequest.filename,
aRequest.line,
@ -1036,7 +1005,7 @@ MarionetteServerConnection.prototype = {
this.executeScriptInSandbox(_chromeSandbox, script, directInject,
true, command_id, timeout);
} catch (e) {
let error = this.createStackMessage(e,
let error = createStackMessage(e,
"execute_async_script",
aRequest.filename,
aRequest.line,