blob: b36ea167ed3c56465a08bad25dfc38c9d136ed82 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function test()
{
let suite = ProtocolTest.createAsyncSuite("Protocol.ArgumentModeErrors");
let errorCodes = {
ParseError: -32700,
InvalidRequest: -32600,
MethodNotFound: -32601,
InvalidParams: -32602,
InternalError: -32603,
ServerError: -32000,
};
function addErrorResponseTestCase(args)
{
let {name, description, message, expectedError} = args;
suite.addTestCase({
name,
description,
test(resolve, reject) {
let stringifiedMessage = (typeof message !== "string") ? JSON.stringify(message) : message;
ProtocolTest.log("Sending message: " + stringifiedMessage);
InspectorProtocol.awaitMessage(message)
.then(function resolved(response) {
ProtocolTest.log("FAIL: the backend should send a protocol error when receiving an invalid message.");
reject();
}, function rejected(response) {
ProtocolTest.log("PASS: the backend should send a protocol error when receiving an invalid message.");
ProtocolTest.expectThat(response.code === errorCodes[expectedError], `the reported error should be "${expectedError}" (${errorCodes[expectedError]})`);
ProtocolTest.log("Actual error code: " + response.code);
ProtocolTest.log("Actual error message: " + response.message);
if (response.data)
ProtocolTest.log("Actual error data: " + JSON.stringify(response.data));
resolve();
})
.catch(reject);
}
});
}
addErrorResponseTestCase({
name: "ParametersNotAnObject",
description: "The backend should return an error if a message has a non-object 'params'.",
message: {id: 123, method: "Runtime.evaluate", params: "junk"},
expectedError: "InvalidParams"
});
addErrorResponseTestCase({
name: "MissingRequiredParameter",
description: "The backend should return an error if a message is missing a required parameter.",
message: {id: 123, method: "Runtime.evaluate", params: {stuff: 123}},
expectedError: "InvalidParams"
});
addErrorResponseTestCase({
name: "RequiredParameterWrongType",
description: "The backend should return an error if a message has a required parameter with wrong type.",
message: {id: 123, method: "Runtime.evaluate", params: {expression: []}},
expectedError: "InvalidParams"
});
addErrorResponseTestCase({
name: "OptionalParameterWrongType",
description: "The backend should return an error if a message has an optional parameter with wrong type.",
message: {id: 123, method: "Runtime.evaluate", params: {expression: "42", includeCommandLineAPI: 123}},
expectedError: "InvalidParams"
});
addErrorResponseTestCase({
name: "TestErrorCodeForSyncServerError",
description: "The backend should return a server error with the correct error code.",
message: {id: 123, method: "Runtime.getProperties", params: {objectId: "thisisNotAnId"}},
expectedError: "ServerError"
});
addErrorResponseTestCase({
name: "TestErrorCodeForAsyncServerError",
description: "The backend should return a server error with the correct error code.",
message: {id: 123, method: "Runtime.awaitPromise", params: {promiseObjectId: "thisisNotAnId"}},
expectedError: "ServerError"
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Testing the inspector backend's error handling when sending messages with wrong parameters.</p>
</body>
</html>