1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <script src=
"../http/tests/inspector/inspector-test.js"></script>
8 function dumpArgument(name
, value
)
10 InspectorTest
.addResult(name
+ " result: " + (typeof value
=== "string" ? value
: JSON
.stringify(value
)));
13 function processResult(name
, promise
)
15 return promise
.then(dumpArgument
.bind(null, name
+ ": then"), dumpArgument
.bind(null, name
+ ": catch"));
18 function sendMessageToBackendLoopback(message
)
20 var messageObject
= JSON
.parse(message
);
21 messageObject
.result
= messageObject
.params
;
22 messageObject
.error
= messageObject
.params
&& messageObject
.params
.error
;
23 var response
= JSON
.stringify(messageObject
);
24 setTimeout(InspectorFrontendAPI
.dispatchMessage
.bind(InspectorFrontendAPI
, response
), 0);
27 var inspectorJson
= {"domains": [{
31 "name": "commandArgs0"
34 "name": "commandArgs1Rets0",
36 {"name": "arg1", "type": "number"}
40 "name": "commandArgs1Rets1",
42 {"name": "arg1", "type": "object"}
45 {"name": "arg1", "type": "object"}
49 "name": "commandArgs3Rets3",
51 {"name": "arg1", "type": "object"},
52 {"name": "arg2", "type": "number", "optional": true},
53 {"name": "arg3", "type": "string", "optional": true}
56 {"name": "arg1", "type": "object"},
57 {"name": "arg2", "type": "number"},
58 {"name": "arg3", "type": "string"}
62 "name": "commandError",
64 {"name": "error", "type": "object"}
68 var commands
= InspectorBackendClass
._generateCommands(inspectorJson
);
71 var sendMessageToBackendOriginal
= InspectorFrontendHost
.sendMessageToBackend
;
72 InspectorFrontendHost
.sendMessageToBackend
= sendMessageToBackendLoopback
;
74 function defaultHandler() {
75 return Array
.prototype.slice
.call(arguments
);
78 var agent
= WebInspector
.targetManager
.mainTarget().profilerAgent();
80 .then(function() { return processResult("commandError", agent
.commandError({"message": "this is the error message"}, defaultHandler
)); }) // Error: error in the protocol response
81 .then(function() { return processResult("commandArgs0", agent
.commandArgs0(defaultHandler
)); })
82 .then(function() { return processResult("commandArgs0", agent
.commandArgs0(1, defaultHandler
)); }) // Error: extra arg
83 .then(function() { return processResult("commandArgs1Rets0", agent
.commandArgs1Rets0(123, defaultHandler
)); })
84 .then(function() { return processResult("commandArgs1Rets0", agent
.commandArgs1Rets0(123, 456, defaultHandler
)); }) // Error: extra arg
85 .then(function() { return processResult("commandArgs1Rets0", agent
.commandArgs1Rets0("abc", defaultHandler
)); }) // Error: wrong type
86 .then(function() { return processResult("commandArgs1Rets0", agent
.commandArgs1Rets0(defaultHandler
)); }) // Error: missing arg
87 .then(function() { return processResult("commandArgs1Rets1", agent
.commandArgs1Rets1({"value1": 234}, defaultHandler
)); })
88 .then(function() { return processResult("commandArgs1Rets1", agent
.commandArgs1Rets1({"value1": 234}, defaultHandler
)); })
89 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, 345, "alph", defaultHandler
)); })
90 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, 345, defaultHandler
)); })
91 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, undefined, "alph", defaultHandler
)); })
92 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, "alph", defaultHandler
)); }) // Error: wrong type
93 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, defaultHandler
)); })
94 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3(defaultHandler
)); }) // Error: missing arg
95 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, "alph", 345, defaultHandler
)); }) // Error: wrong types
96 .then(function() { return processResult("commandArgs3Rets3", agent
.commandArgs3Rets3({}, "alph", 345, 678, defaultHandler
)); }) // Error: extra arg
101 InspectorFrontendHost
.sendMessageToBackend
= sendMessageToBackendOriginal
;
102 InspectorTest
.completeTest();
107 <body onload=
"runTest()">
108 <p>Tests correctness of promisified protocol commands.
</p>