| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <head> |
| <script src="../http/tests/inspector/inspector-test.js"></script> |
| <script> |
| async function test() |
| { |
| Protocol.InspectorBackend.Options.suppressRequestErrors = false; |
| function dumpArgument(name, value) |
| { |
| InspectorTest.addResult(name + " result: " + (typeof value === "string" ? value : JSON.stringify(value))); |
| } |
| |
| function processResult(name, promise) |
| { |
| return promise.then(dumpArgument.bind(null, name + ": then"), dumpArgument.bind(null, name + ": catch")); |
| } |
| |
| function sendMessageToBackendLoopback(message) |
| { |
| var messageObject = JSON.parse(message); |
| messageObject.result = messageObject.params; |
| messageObject.error = messageObject.params && messageObject.params.error; |
| var response = JSON.stringify(messageObject); |
| setTimeout(InspectorFrontendAPI.dispatchMessage.bind(InspectorFrontendAPI, response), 0); |
| } |
| |
| var inspectorJson = {"domains": [{ |
| "domain": "Profiler", |
| "commands": [ |
| { |
| "name": "commandArgs0" |
| }, |
| { |
| "name": "commandArgs1Rets0", |
| "parameters": [ |
| {"name": "arg1", "type": "number"} |
| ] |
| }, |
| { |
| "name": "commandArgs1Rets1", |
| "parameters": [ |
| {"name": "arg1", "type": "object"} |
| ], |
| "returns": [ |
| {"name": "arg1", "type": "object"} |
| ] |
| }, |
| { |
| "name": "commandArgs3Rets3", |
| "parameters": [ |
| {"name": "arg1", "type": "object"}, |
| {"name": "arg2", "type": "number", "optional": true}, |
| {"name": "arg3", "type": "string", "optional": true} |
| ], |
| "returns": [ |
| {"name": "arg1", "type": "object"}, |
| {"name": "arg2", "type": "number"}, |
| {"name": "arg3", "type": "string"} |
| ] |
| }, |
| { |
| "name": "commandError", |
| "parameters": [ |
| {"name": "error", "type": "object"} |
| ] |
| }] |
| }]}; |
| // The protocol definition above is not used, but is left as a reference for commands below. |
| Protocol.inspectorBackend.registerCommand("Profiler.commandArgs0", [], [], false); |
| Protocol.inspectorBackend.registerCommand("Profiler.commandArgs1Rets0", [{"name": "arg1", "type": "number", "optional": false}], [], false); |
| Protocol.inspectorBackend.registerCommand("Profiler.commandArgs1Rets1", [{"name": "arg1", "type": "object", "optional": false}], ["arg1"], false); |
| Protocol.inspectorBackend.registerCommand("Profiler.commandArgs3Rets3", |
| [{"name": "arg1", "type": "object", "optional": false}, {"name": "arg2", "type": "number", "optional": true}, {"name": "arg3", "type": "string", "optional": true}], ["arg1", "arg2", "arg3"], false); |
| Protocol.inspectorBackend.registerCommand("Profiler.commandError", [{"name": "error", "type": "object", "optional": false}], [], false); |
| |
| var sendMessageToBackendOriginal = InspectorFrontendHost.sendMessageToBackend; |
| InspectorFrontendHost.sendMessageToBackend = sendMessageToBackendLoopback; |
| |
| var agent = SDK.targetManager.mainTarget().profilerAgent(); |
| await processResult("commandError", agent.commandError({"message": "this is the error message"})); // Error: error in the protocol response |
| await processResult("commandArgs0", agent.commandArgs0()); |
| await processResult("commandArgs0", agent.commandArgs0(1)); // Error: extra arg |
| await processResult("commandArgs1Rets0", agent.commandArgs1Rets0(123)); |
| await processResult("commandArgs1Rets0", agent.commandArgs1Rets0(123, 456)); // Error: extra arg |
| await processResult("commandArgs1Rets0", agent.commandArgs1Rets0("abc")); // Error: wrong type |
| await processResult("commandArgs1Rets0", agent.commandArgs1Rets0()); // Error: missing arg |
| await processResult("commandArgs1Rets1", agent.commandArgs1Rets1({"value1": 234})); |
| await processResult("commandArgs1Rets1", agent.commandArgs1Rets1({"value1": 234})); |
| await processResult("commandArgs3Rets3", agent.invoke_commandArgs3Rets3({arg1: {}, arg2: 345, arg3: "alph"})); |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3({}, 345)); |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3({}, undefined, "alph")); |
| await processResult("commandArgs3Rets3", agent.invoke_commandArgs3Rets3({arg1: {}, arg2: "alph"})); // Error: wrong type |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3({})); |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3()); // Error: missing arg |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3({}, "alph", 345)); // Error: wrong types |
| await processResult("commandArgs3Rets3", agent.commandArgs3Rets3({}, "alph", 345, 678)); // Error: extra arg |
| |
| InspectorFrontendHost.sendMessageToBackend = sendMessageToBackendOriginal; |
| InspectorTest.completeTest(); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests correctness of promisified protocol commands.</p> |
| </body> |
| </html> |