<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[193172] branches/safari-601-branch</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/193172">193172</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2015-12-03 10:53:42 -0800 (Thu, 03 Dec 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/188897">r188897</a>. rdar://problem/23221163</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601branchLayoutTestsChangeLog">branches/safari-601-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceJavaScriptCoreChangeLog">branches/safari-601-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceJavaScriptCoreinspectorInspectorBackendDispatchercpp">branches/safari-601-branch/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUIChangeLog">branches/safari-601-branch/Source/WebInspectorUI/ChangeLog</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari601branchLayoutTestsinspectorprotocolbackenddispatcherargumenterrorsexpectedtxt">branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt</a></li>
<li><a href="#branchessafari601branchLayoutTestsinspectorprotocolbackenddispatcherargumenterrorshtml">branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors.html</a></li>
<li><a href="#branchessafari601branchLayoutTestsinspectorprotocolbackenddispatchermalformedmessageerrorsexpectedtxt">branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors-expected.txt</a></li>
<li><a href="#branchessafari601branchLayoutTestsinspectorprotocolbackenddispatchermalformedmessageerrorshtml">branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/LayoutTests/ChangeLog (193171 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/LayoutTests/ChangeLog        2015-12-03 18:53:31 UTC (rev 193171)
+++ branches/safari-601-branch/LayoutTests/ChangeLog        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2015-12-02 Timothy Hatcher <timothy@apple.com>
</span><span class="cx">
</span><ins>+ Merge r188897. rdar://problem/23221163
+
+ 2015-08-24 Brian Burg <bburg@apple.com>
+
+ Web Inspector: add protocol test for existing error handling performed by the backend
+ https://bugs.webkit.org/show_bug.cgi?id=147097
+
+ Reviewed by Joseph Pecoraro.
+
+ Add a bunch of test cases to cover existing error handling by the backend dispatcher.
+
+ * inspector/protocol/backend-dispatcher-argument-errors-expected.txt: Added.
+ * inspector/protocol/backend-dispatcher-argument-errors.html: Added.
+ * inspector/protocol/backend-dispatcher-malformed-message-errors-expected.txt: Added.
+ * inspector/protocol/backend-dispatcher-malformed-message-errors.html: Added.
+
+2015-12-02 Timothy Hatcher <timothy@apple.com>
+
</ins><span class="cx"> Merge r188756. rdar://problem/23221163
</span><span class="cx">
</span><span class="cx"> 2015-08-20 Brian Burg <bburg@apple.com>
</span></span></pre></div>
<a id="branchessafari601branchLayoutTestsinspectorprotocolbackenddispatcherargumenterrorsexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt (0 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt         (rev 0)
+++ branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+Testing the inspector backend's error handling when sending messages with wrong parameters.
+
+
+== Running test suite: Protocol.ArgumentModeErrors
+-- Running test case: ParametersNotAnObject
+Sending message: {"id":123,"method":"Runtime.evaluate","params":"junk"}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "InvalidParams" (-32602)
+Actual error code: -32602
+Actual error message: Some arguments of method 'Runtime.evaluate' can't be processed
+Actual error data: 'params' object must contain required parameter 'expression' with type 'String'.
+
+-- Running test case: MissingRequiredParameter
+Sending message: {"id":123,"method":"Runtime.evaluate","params":{"stuff":123}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "InvalidParams" (-32602)
+Actual error code: -32602
+Actual error message: Some arguments of method 'Runtime.evaluate' can't be processed
+Actual error data: Parameter 'expression' with type 'String' was not found.
+
+-- Running test case: RequiredParameterWrongType
+Sending message: {"id":123,"method":"Runtime.evaluate","params":{"expression":[]}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "InvalidParams" (-32602)
+Actual error code: -32602
+Actual error message: Some arguments of method 'Runtime.evaluate' can't be processed
+Actual error data: Parameter 'expression' has wrong type. It must be 'String'.
+
+-- Running test case: OptionalParameterWrongType
+Sending message: {"id":123,"method":"Runtime.evaluate","params":{"expression":"42","includeCommandLineAPI":123}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "InvalidParams" (-32602)
+Actual error code: -32602
+Actual error message: Some arguments of method 'Runtime.evaluate' can't be processed
+Actual error data: Parameter 'includeCommandLineAPI' has wrong type. It must be 'Boolean'.
+
+-- Running test case: TestErrorCodeForSyncServerError
+Sending message: {"id":123,"method":"Database.getDatabaseTableNames","params":{"databaseId":"thisisNotADatabase"}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "ServerError" (-32000)
+Actual error code: -32000
+Actual error message: Database agent is not enabled
+
+-- Running test case: TestErrorCodeForAsyncServerError
+Sending message: {"id":123,"method":"Database.executeSQL","params":{"databaseId":"thisisNotADatabase","query":"asdf"}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "ServerError" (-32000)
+Actual error code: -32000
+Actual error message: Database agent is not enabled
+
+-- Running test case: CommandWithBadArgumentValue
+Sending message: {"id":123,"method":"Runtime.getProperties","params":{"objectId":"thisisNotAnId"}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be "ServerError" (-32000)
+Actual error code: -32000
+Actual error message: Inspected frame has gone
+
</ins></span></pre></div>
<a id="branchessafari601branchLayoutTestsinspectorprotocolbackenddispatcherargumenterrorshtml"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors.html (0 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors.html         (rev 0)
+++ branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-argument-errors.html        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+<!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: " + 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: "Database.getDatabaseTableNames", params: {databaseId: "thisisNotADatabase"}},
+ expectedError: "ServerError"
+ });
+
+ addErrorResponseTestCase({
+ name: "TestErrorCodeForAsyncServerError",
+ description: "The backend should return a server error with the correct error code.",
+ message: {id: 123, method: "Database.executeSQL", params: {databaseId: "thisisNotADatabase", query: "asdf"}},
+ expectedError: "ServerError"
+ });
+
+ addErrorResponseTestCase({
+ name: "CommandWithBadArgumentValue",
+ description: "The backend should return an error if something went wrong when invoking the agent's method.",
+ message: {id: 123, method: "Runtime.getProperties", params: {objectId: "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>
</ins></span></pre></div>
<a id="branchessafari601branchLayoutTestsinspectorprotocolbackenddispatchermalformedmessageerrorsexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors-expected.txt (0 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors-expected.txt         (rev 0)
+++ branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors-expected.txt        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -0,0 +1,123 @@
</span><ins>+Testing the inspector backend's error handling when sending invalid messages.
+
+
+== Running test suite: Protocol.MalformedMessageErrors
+-- Running test case: UnparseableStringMessage
+Sending message: not-a-json-object
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "ParseError" (-32700)
+Actual error code: -32700
+Actual error message: Message must be in JSON format
+
+-- Running test case: JSONObjectWithSyntaxError
+Sending message: {name: 123,}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "ParseError" (-32700)
+Actual error code: -32700
+Actual error message: Message must be in JSON format
+
+-- Running test case: EmptyJSONObject
+Sending message: {}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: 'id' property was not found
+
+-- Running test case: MissingIdField
+Sending message: {"lucky":123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: 'id' property was not found
+
+-- Running test case: IdFieldWithArrayType
+Sending message: {"id":[]}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The type of 'id' property must be integer
+
+-- Running test case: IdFieldWithStringType
+Sending message: {"id":"123"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The type of 'id' property must be integer
+
+-- Running test case: MissingMethodField
+Sending message: {"id":123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: 'method' property wasn't found
+
+-- Running test case: MethodFieldWithArrayType
+Sending message: {"id":123,"method":[]}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The type of 'method' property must be string
+
+-- Running test case: MethodFieldWithNumberType
+Sending message: {"id":123,"method":123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The type of 'method' property must be string
+
+-- Running test case: MethodFieldWithBadFormatting
+Sending message: {"id":123,"method":"ThisIsDefinitelyNotADomainAndMethod"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithBadFormatting2
+Sending message: {"id":123,"method":"ThisIsDefinitelyNotADomainAndMethod."}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithBadFormatting3
+Sending message: {"id":123,"method":".ThisIsDefinitelyNotADomainAndMethod"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithBadFormatting4
+Sending message: {"id":123,"method":"."}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithBadFormatting5
+Sending message: {"id":123,"method":".FooBar."}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithBadFormatting6
+Sending message: {"id":123,"method":"Foo.Bar.Baz"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "InvalidRequest" (-32600)
+Actual error code: -32600
+Actual error message: The 'method' property was formatted incorrectly. It should be 'Domain.method'
+
+-- Running test case: MethodFieldWithFakeDomain
+Sending message: {"id":123,"method":"DummyDomain.DummyMethod"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "MethodNotFound" (-32601)
+Actual error code: -32601
+Actual error message: 'DummyDomain' domain was not found
+
+-- Running test case: MethodFieldWithFakeMethod
+Sending message: {"id":123,"method":"Inspector.DummyMethod"}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be "MethodNotFound" (-32601)
+Actual error code: -32601
+Actual error message: 'Inspector.DummyMethod' was not found
+
</ins></span></pre></div>
<a id="branchessafari601branchLayoutTestsinspectorprotocolbackenddispatchermalformedmessageerrorshtml"></a>
<div class="addfile"><h4>Added: branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors.html (0 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors.html         (rev 0)
+++ branches/safari-601-branch/LayoutTests/inspector/protocol/backend-dispatcher-malformed-message-errors.html        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -0,0 +1,172 @@
</span><ins>+<!doctype html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
+<script>
+function test()
+{
+ let suite = ProtocolTest.createAsyncSuite("Protocol.MalformedMessageErrors");
+
+ 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 for an invalid message.");
+ reject();
+ }, function rejected(response) {
+ ProtocolTest.log("PASS: the backend should send a protocol error when receiving for 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);
+ resolve();
+ })
+ .catch(reject);
+ }
+ });
+ }
+
+ addErrorResponseTestCase({
+ name: "UnparseableStringMessage",
+ description: "The backend should return an error if a message is not valid JSON.",
+ message: "not-a-json-object",
+ expectedError: "ParseError"
+ });
+
+ addErrorResponseTestCase({
+ name: "JSONObjectWithSyntaxError",
+ description: "The backend should return an error if a message is not valid JSON.",
+ message: "{name: 123,}",
+ expectedError: "ParseError"
+ });
+
+ addErrorResponseTestCase({
+ name: "EmptyJSONObject",
+ description: "The backend should return an error if a message lacks an 'id' field.",
+ message: {},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MissingIdField",
+ description: "The backend should return an error if a message lacks an 'id' field.",
+ message: {lucky: 123},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "IdFieldWithArrayType",
+ description: "The backend should return an error if a message has a non-numeric 'id' field.",
+ message: {id: []},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "IdFieldWithStringType",
+ description: "The backend should return an error if a message has a non-numeric 'id' field.",
+ message: {id: "123"},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MissingMethodField",
+ description: "The backend should return an error if a message lacks a 'method' field.",
+ message: {id: 123},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithArrayType",
+ description: "The backend should return an error if a message has a non-string 'method' field.",
+ message: {id: 123, method: []},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithNumberType",
+ description: "The backend should return an error if a message has a non-string 'method' field.",
+ message: {id: 123, method: 123},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: "ThisIsDefinitelyNotADomainAndMethod"},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting2",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: "ThisIsDefinitelyNotADomainAndMethod."},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting3",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: ".ThisIsDefinitelyNotADomainAndMethod"},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting4",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: "."},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting5",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: ".FooBar."},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithBadFormatting6",
+ description: "The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.",
+ message: {id: 123, method: "Foo.Bar.Baz"},
+ expectedError: "InvalidRequest"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithFakeDomain",
+ description: "The backend should return an error if a message specifies a domain that doesn't exist.",
+ message: {id: 123, method: "DummyDomain.DummyMethod"},
+ expectedError: "MethodNotFound"
+ });
+
+ addErrorResponseTestCase({
+ name: "MethodFieldWithFakeMethod",
+ description: "The backend should return an error if a message specifies a method that doesn't exist.",
+ message: {id: 123, method: "Inspector.DummyMethod"},
+ expectedError: "MethodNotFound"
+ });
+
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+ <p>Testing the inspector backend's error handling when sending invalid messages.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchessafari601branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/JavaScriptCore/ChangeLog (193171 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/JavaScriptCore/ChangeLog        2015-12-03 18:53:31 UTC (rev 193171)
+++ branches/safari-601-branch/Source/JavaScriptCore/ChangeLog        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -1,5 +1,22 @@
</span><span class="cx"> 2015-12-02 Timothy Hatcher <timothy@apple.com>
</span><span class="cx">
</span><ins>+ Merge r188897. rdar://problem/23221163
+
+ 2015-08-24 Brian Burg <bburg@apple.com>
+
+ Web Inspector: add protocol test for existing error handling performed by the backend
+ https://bugs.webkit.org/show_bug.cgi?id=147097
+
+ Reviewed by Joseph Pecoraro.
+
+ A new test revealed that the protocol "method" parameter was being parsed in a naive way.
+ Rewrite it to use String::split and improve error checking to avoid failing later.
+
+ * inspector/InspectorBackendDispatcher.cpp:
+ (Inspector::BackendDispatcher::dispatch):
+
+2015-12-02 Timothy Hatcher <timothy@apple.com>
+
</ins><span class="cx"> Merge r188631. rdar://problem/23221163
</span><span class="cx">
</span><span class="cx"> 2015-08-18 Joseph Pecoraro <pecoraro@apple.com>
</span></span></pre></div>
<a id="branchessafari601branchSourceJavaScriptCoreinspectorInspectorBackendDispatchercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp (193171 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp        2015-12-03 18:53:31 UTC (rev 193171)
+++ branches/safari-601-branch/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -106,27 +106,28 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- String method;
- if (!methodValue->asString(method)) {
</del><ins>+ String methodString;
+ if (!methodValue->asString(methodString)) {
</ins><span class="cx"> reportProtocolError(&callId, InvalidRequest, ASCIILiteral("The type of 'method' property must be string"));
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- size_t position = method.find('.');
- if (position == WTF::notFound) {
</del><ins>+ Vector<String> domainAndMethod;
+ methodString.split('.', true, domainAndMethod);
+ if (domainAndMethod.size() != 2 || !domainAndMethod[0].length() || !domainAndMethod[1].length()) {
</ins><span class="cx"> reportProtocolError(&callId, InvalidRequest, ASCIILiteral("The 'method' property was formatted incorrectly. It should be 'Domain.method'"));
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- String domain = method.substring(0, position);
</del><ins>+ String domain = domainAndMethod[0];
</ins><span class="cx"> SupplementalBackendDispatcher* domainDispatcher = m_dispatchers.get(domain);
</span><span class="cx"> if (!domainDispatcher) {
</span><span class="cx"> reportProtocolError(&callId, MethodNotFound, "'" + domain + "' domain was not found");
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- String domainMethod = method.substring(position + 1);
- domainDispatcher->dispatch(callId, domainMethod, messageObject.releaseNonNull());
</del><ins>+ String method = domainAndMethod[1];
+ domainDispatcher->dispatch(callId, method, messageObject.releaseNonNull());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void BackendDispatcher::sendResponse(long callId, RefPtr<InspectorObject>&& result, const ErrorString& invocationError)
</span></span></pre></div>
<a id="branchessafari601branchSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/ChangeLog (193171 => 193172)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/ChangeLog        2015-12-03 18:53:31 UTC (rev 193171)
+++ branches/safari-601-branch/Source/WebInspectorUI/ChangeLog        2015-12-03 18:53:42 UTC (rev 193172)
</span><span class="lines">@@ -1,5 +1,28 @@
</span><span class="cx"> 2015-12-02 Timothy Hatcher <timothy@apple.com>
</span><span class="cx">
</span><ins>+ Merge r188897. rdar://problem/23221163
+
+ 2015-08-24 Brian Burg <bburg@apple.com>
+
+ Web Inspector: add protocol test for existing error handling performed by the backend
+ https://bugs.webkit.org/show_bug.cgi?id=147097
+
+ Reviewed by Joseph Pecoraro.
+
+ Add a way to send raw messages to the backend while still awaiting on responses.
+ This is necessary to test protocol error handling in the inspector backend.
+
+ * UserInterface/Test/InspectorProtocol.js:
+ (InspectorProtocol.sendCommand):
+ (InspectorProtocol.awaitCommand): Use awaitMessage internally.
+ (InspectorProtocol.awaitMessage): Added. Use a dummy requestId if none is supplied.
+ (InspectorProtocol._sendMessage): Added.
+ (InspectorProtocol.dispatchMessageFromBackend):
+ Reject with the error object instead of the error message, so error code/data can be checked.
+ (InspectorProtocol.sendMessage): Deleted, it is now a private method.
+
+2015-12-02 Timothy Hatcher <timothy@apple.com>
+
</ins><span class="cx"> Merge r188876. rdar://problem/23221163
</span><span class="cx">
</span><span class="cx"> 2015-08-24 Timothy Hatcher <timothy@apple.com>
</span></span></pre>
</div>
</div>
</body>
</html>