mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 945729: Replace error number codes with strings
Brings Marionette closer to compliance with the W3C WebDriver standard which prescribes that errors should be identified by a string rather than a magic number. r=dburns --HG-- extra : rebase_source : 2bdb28f3c05e56b17cc13ceacbf3167dabe89fd0 extra : source : 2b691bf191db1a83ae489116649602a74e64007a
This commit is contained in:
parent
a469e611a5
commit
0a912ae1c7
@ -56,7 +56,7 @@ this.Response = function(cmdId, okHandler, respHandler, msg, sanitizer) {
|
||||
|
||||
this.data = new Map([
|
||||
["sessionId", msg.sessionId ? msg.sessionId : null],
|
||||
["status", msg.status ? msg.status : 0 /* success */],
|
||||
["status", msg.status ? msg.status : "success"],
|
||||
["value", msg.value ? msg.value : undefined],
|
||||
]);
|
||||
};
|
||||
@ -93,10 +93,10 @@ Response.prototype.send = function() {
|
||||
/**
|
||||
* @param {(Error|Object)} err
|
||||
* The error to send, either an instance of the Error prototype,
|
||||
* or an object with the properties "message", "code", and "stack".
|
||||
* or an object with the properties "message", "status", and "stack".
|
||||
*/
|
||||
Response.prototype.sendError = function(err) {
|
||||
this.status = "code" in err ? err.code : new UnknownError().code;
|
||||
this.status = "status" in err ? err.status : new UnknownError().status;
|
||||
this.value = error.toJSON(err);
|
||||
this.send();
|
||||
|
||||
|
@ -124,7 +124,7 @@ Dispatcher.prototype.quitApplication = function(msg) {
|
||||
if (this.driver.appName != "Firefox") {
|
||||
this.sendError({
|
||||
"message": "In app initiated quit only supported on Firefox",
|
||||
"status": 500
|
||||
"status": "webdriver error",
|
||||
}, id);
|
||||
return;
|
||||
}
|
||||
|
@ -59,26 +59,14 @@ error.toJSON = function(err) {
|
||||
return {
|
||||
message: err.message,
|
||||
stacktrace: err.stack || null,
|
||||
status: err.code
|
||||
status: err.status
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if the given status code is successful.
|
||||
* Determines if the given status is successful.
|
||||
*/
|
||||
error.isSuccess = code => code === 0;
|
||||
|
||||
/**
|
||||
* Old-style errors are objects that has all of the properties
|
||||
* "message", "code", and "stack".
|
||||
*
|
||||
* When listener.js starts forwarding real errors by CPOW
|
||||
* we can remove this.
|
||||
*/
|
||||
let isOldStyleError = function(obj) {
|
||||
return typeof obj == "object" &&
|
||||
["message", "code", "stack"].every(c => obj.hasOwnProperty(c));
|
||||
}
|
||||
error.isSuccess = status => status === "success";
|
||||
|
||||
/**
|
||||
* Checks if obj is an instance of the Error prototype in a safe manner.
|
||||
@ -97,7 +85,7 @@ error.isError = function(val) {
|
||||
} else if ("result" in val && val.result in XPCOM_EXCEPTIONS) {
|
||||
return true;
|
||||
} else {
|
||||
return Object.getPrototypeOf(val) == "Error" || isOldStyleError(val);
|
||||
return Object.getPrototypeOf(val) == "Error";
|
||||
}
|
||||
};
|
||||
|
||||
@ -106,8 +94,7 @@ error.isError = function(val) {
|
||||
*/
|
||||
error.isWebDriverError = function(obj) {
|
||||
return error.isError(obj) &&
|
||||
(("name" in obj && errors.indexOf(obj.name) > 0) ||
|
||||
isOldStyleError(obj));
|
||||
("name" in obj && errors.indexOf(obj.name) > 0);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -147,7 +134,6 @@ this.WebDriverError = function(msg) {
|
||||
this.name = "WebDriverError";
|
||||
this.message = msg;
|
||||
this.status = "webdriver error";
|
||||
this.code = 500; // overridden
|
||||
};
|
||||
WebDriverError.prototype = Object.create(Error.prototype);
|
||||
|
||||
@ -155,7 +141,6 @@ this.ElementNotAccessibleError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "ElementNotAccessibleError";
|
||||
this.status = "element not accessible";
|
||||
this.code = 56;
|
||||
};
|
||||
ElementNotAccessibleError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -163,7 +148,6 @@ this.ElementNotVisibleError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "ElementNotVisibleError";
|
||||
this.status = "element not visible";
|
||||
this.code = 11;
|
||||
};
|
||||
ElementNotVisibleError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -172,7 +156,6 @@ this.FrameSendFailureError = function(frame) {
|
||||
WebDriverError.call(this, this.message);
|
||||
this.name = "FrameSendFailureError";
|
||||
this.status = "frame send failure error";
|
||||
this.code = 55;
|
||||
this.frame = frame;
|
||||
this.errMsg = `${this.message} ${this.frame}; frame not responding.`;
|
||||
};
|
||||
@ -183,7 +166,6 @@ this.FrameSendNotInitializedError = function(frame) {
|
||||
WebDriverError.call(this, this.message);
|
||||
this.name = "FrameSendNotInitializedError";
|
||||
this.status = "frame send not initialized error";
|
||||
this.code = 54;
|
||||
this.frame = frame;
|
||||
this.errMsg = `${this.message} ${this.frame}; frame has closed.`;
|
||||
};
|
||||
@ -193,7 +175,6 @@ this.IllegalArgumentError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "IllegalArgumentError";
|
||||
this.status = "illegal argument";
|
||||
this.code = 13; // unknown error
|
||||
};
|
||||
IllegalArgumentError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -201,7 +182,6 @@ this.InvalidElementStateError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "InvalidElementStateError";
|
||||
this.status = "invalid element state";
|
||||
this.code = 12;
|
||||
};
|
||||
InvalidElementStateError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -209,7 +189,6 @@ this.InvalidSelectorError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "InvalidSelectorError";
|
||||
this.status = "invalid selector";
|
||||
this.code = 32;
|
||||
};
|
||||
InvalidSelectorError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -264,7 +243,6 @@ this.JavaScriptError = function(err, fnName, file, line, script) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "JavaScriptError";
|
||||
this.status = "javascript error";
|
||||
this.code = 17;
|
||||
this.stack = trace;
|
||||
};
|
||||
JavaScriptError.prototype = Object.create(WebDriverError.prototype);
|
||||
@ -273,7 +251,6 @@ this.NoAlertOpenError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "NoAlertOpenError";
|
||||
this.status = "no such alert";
|
||||
this.code = 27;
|
||||
}
|
||||
NoAlertOpenError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -281,7 +258,6 @@ this.NoSuchElementError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "NoSuchElementError";
|
||||
this.status = "no such element";
|
||||
this.code = 7;
|
||||
};
|
||||
NoSuchElementError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -289,7 +265,6 @@ this.NoSuchFrameError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "NoSuchFrameError";
|
||||
this.status = "no such frame";
|
||||
this.code = 8;
|
||||
};
|
||||
NoSuchFrameError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -297,7 +272,6 @@ this.NoSuchWindowError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "NoSuchWindowError";
|
||||
this.status = "no such window";
|
||||
this.code = 23;
|
||||
};
|
||||
NoSuchWindowError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -305,7 +279,6 @@ this.ScriptTimeoutError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "ScriptTimeoutError";
|
||||
this.status = "script timeout";
|
||||
this.code = 28;
|
||||
};
|
||||
ScriptTimeoutError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -313,8 +286,6 @@ this.SessionNotCreatedError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "SessionNotCreatedError";
|
||||
this.status = "session not created";
|
||||
// should be 33 to match Selenium
|
||||
this.code = 71;
|
||||
};
|
||||
SessionNotCreatedError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -322,7 +293,6 @@ this.StaleElementReferenceError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "StaleElementReferenceError";
|
||||
this.status = "stale element reference";
|
||||
this.code = 10;
|
||||
};
|
||||
StaleElementReferenceError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -330,7 +300,6 @@ this.TimeoutError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "TimeoutError";
|
||||
this.status = "timeout";
|
||||
this.code = 21;
|
||||
};
|
||||
TimeoutError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -346,7 +315,6 @@ this.UnknownCommandError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "UnknownCommandError";
|
||||
this.status = "unknown command";
|
||||
this.code = 9;
|
||||
};
|
||||
UnknownCommandError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -354,7 +322,6 @@ this.UnknownError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "UnknownError";
|
||||
this.status = "unknown error";
|
||||
this.code = 13;
|
||||
};
|
||||
UnknownError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
@ -362,6 +329,5 @@ this.UnsupportedOperationError = function(msg) {
|
||||
WebDriverError.call(this, msg);
|
||||
this.name = "UnsupportedOperationError";
|
||||
this.status = "unsupported operation";
|
||||
this.code = 405;
|
||||
};
|
||||
UnsupportedOperationError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
@ -522,7 +522,8 @@ function createExecuteContentSandbox(aWindow, timeout) {
|
||||
inactivityTimeoutId = null;
|
||||
}
|
||||
};
|
||||
sandbox.finish = function sandbox_finish() {
|
||||
|
||||
sandbox.finish = function() {
|
||||
if (asyncTestRunning) {
|
||||
sandbox.asyncComplete(marionette.generate_results(), sandbox.asyncTestCommandId);
|
||||
} else {
|
||||
@ -699,11 +700,6 @@ function executeWithCallback(msg, useFinish) {
|
||||
}
|
||||
sandbox.tag = script;
|
||||
|
||||
// Error code 28 is scriptTimeout, but spec says execute_async should return 21 (Timeout),
|
||||
// see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute_async.
|
||||
// However Selenium code returns 28, see
|
||||
// http://code.google.com/p/selenium/source/browse/trunk/javascript/firefox-driver/js/evaluate.js.
|
||||
// We'll stay compatible with the Selenium code.
|
||||
asyncTestTimeoutId = curFrame.setTimeout(function() {
|
||||
sandbox.asyncComplete(new ScriptTimeoutError("timed out"), asyncTestCommandId);
|
||||
}, msg.json.timeout);
|
||||
@ -1445,7 +1441,7 @@ function isElementDisplayed(msg) {
|
||||
* the element that will be checked
|
||||
* 'propertyName' is the CSS rule that is being requested
|
||||
*/
|
||||
function getElementValueOfCssProperty(msg){
|
||||
function getElementValueOfCssProperty(msg) {
|
||||
let command_id = msg.json.command_id;
|
||||
let propertyName = msg.json.propertyName;
|
||||
try {
|
||||
@ -1617,6 +1613,11 @@ function clearElement(msg) {
|
||||
}
|
||||
sendOk(command_id);
|
||||
} catch (e) {
|
||||
// Bug 964738: Newer atoms contain status codes which makes wrapping
|
||||
// this in an error prototype that has a status property unnecessary
|
||||
if (e.name == "InvalidElementStateError") {
|
||||
e = new InvalidElementStateError(e.message);
|
||||
}
|
||||
sendError(e, command_id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user