зеркало из https://github.com/mozilla/gecko-dev.git
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 : cde9ecded568fb17c46cd5940ec2241cd4446aaf extra : source : 2b691bf191db1a83ae489116649602a74e64007a
This commit is contained in:
Родитель
86e4115d5b
Коммит
4916729cb0
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -58,25 +58,25 @@ 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;
|
||||
error.isSuccess = status => status === "success";
|
||||
|
||||
/**
|
||||
* Old-style errors are objects that has all of the properties
|
||||
* "message", "code", and "stack".
|
||||
* "message", "status", 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));
|
||||
["message", "status", "stack"].every(c => obj.hasOwnProperty(c));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +146,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);
|
||||
|
||||
|
@ -154,7 +153,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);
|
||||
|
||||
|
@ -162,7 +160,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);
|
||||
|
||||
|
@ -171,7 +168,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.`;
|
||||
};
|
||||
|
@ -182,7 +178,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.`;
|
||||
};
|
||||
|
@ -192,7 +187,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);
|
||||
|
||||
|
@ -200,7 +194,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);
|
||||
|
||||
|
@ -208,7 +201,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);
|
||||
|
||||
|
@ -263,7 +255,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);
|
||||
|
@ -272,7 +263,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);
|
||||
|
||||
|
@ -280,7 +270,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);
|
||||
|
||||
|
@ -288,7 +277,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);
|
||||
|
||||
|
@ -296,7 +284,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);
|
||||
|
||||
|
@ -304,7 +291,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);
|
||||
|
||||
|
@ -312,8 +298,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);
|
||||
|
||||
|
@ -321,7 +305,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);
|
||||
|
||||
|
@ -329,7 +312,6 @@ this.TimeoutError = function(msg) {
|
|||
WebDriverError.call(this, msg);
|
||||
this.name = "TimeoutError";
|
||||
this.status = "timeout";
|
||||
this.code = 21;
|
||||
};
|
||||
TimeoutError.prototype = Object.create(WebDriverError.prototype);
|
||||
|
||||
|
@ -337,7 +319,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);
|
||||
|
||||
|
@ -345,7 +326,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);
|
||||
|
||||
|
@ -353,6 +333,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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче