<!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  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r188897. rdar://problem/23221163
+
+    2015-08-24  Brian Burg  &lt;bburg@apple.com&gt;
+
+            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  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r188756. rdar://problem/23221163
</span><span class="cx"> 
</span><span class="cx">     2015-08-20  Brian Burg  &lt;bburg@apple.com&gt;
</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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Runtime.evaluate&quot;,&quot;params&quot;:&quot;junk&quot;}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;InvalidParams&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Runtime.evaluate&quot;,&quot;params&quot;:{&quot;stuff&quot;:123}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;InvalidParams&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Runtime.evaluate&quot;,&quot;params&quot;:{&quot;expression&quot;:[]}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;InvalidParams&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Runtime.evaluate&quot;,&quot;params&quot;:{&quot;expression&quot;:&quot;42&quot;,&quot;includeCommandLineAPI&quot;:123}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;InvalidParams&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Database.getDatabaseTableNames&quot;,&quot;params&quot;:{&quot;databaseId&quot;:&quot;thisisNotADatabase&quot;}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;ServerError&quot; (-32000)
+Actual error code: -32000
+Actual error message: Database agent is not enabled
+
+-- Running test case: TestErrorCodeForAsyncServerError
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:&quot;Database.executeSQL&quot;,&quot;params&quot;:{&quot;databaseId&quot;:&quot;thisisNotADatabase&quot;,&quot;query&quot;:&quot;asdf&quot;}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;ServerError&quot; (-32000)
+Actual error code: -32000
+Actual error message: Database agent is not enabled
+
+-- Running test case: CommandWithBadArgumentValue
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:&quot;Runtime.getProperties&quot;,&quot;params&quot;:{&quot;objectId&quot;:&quot;thisisNotAnId&quot;}}
+PASS: the backend should send a protocol error when receiving an invalid message.
+PASS: the reported error should be &quot;ServerError&quot; (-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>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/protocol-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function test()
+{
+    let suite = ProtocolTest.createAsyncSuite(&quot;Protocol.ArgumentModeErrors&quot;);
+
+    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) =&gt; {
+                let stringifiedMessage = (typeof message !== &quot;string&quot;) ? JSON.stringify(message) : message;
+                ProtocolTest.log(&quot;Sending message: &quot; + stringifiedMessage);
+                InspectorProtocol.awaitMessage(message)
+                .then(function resolved(response) {
+                    ProtocolTest.log(&quot;FAIL: the backend should send a protocol error when receiving an invalid message.&quot;);
+                    reject();
+                }, function rejected(response) {
+                    ProtocolTest.log(&quot;PASS: the backend should send a protocol error when receiving an invalid message.&quot;);
+                    ProtocolTest.expectThat(response.code === errorCodes[expectedError], `the reported error should be &quot;${expectedError}&quot; (${errorCodes[expectedError]})`);
+                    ProtocolTest.log(&quot;Actual error code: &quot; + response.code);
+                    ProtocolTest.log(&quot;Actual error message: &quot; + response.message);
+                    if (response.data)
+                        ProtocolTest.log(&quot;Actual error data: &quot; + response.data);
+
+                    resolve();
+                })
+                .catch(reject);
+            }
+        });
+    }
+
+    addErrorResponseTestCase({
+        name: &quot;ParametersNotAnObject&quot;,
+        description: &quot;The backend should return an error if a message has a non-object 'params'.&quot;,
+        message: {id: 123, method: &quot;Runtime.evaluate&quot;, params: &quot;junk&quot;},
+        expectedError: &quot;InvalidParams&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MissingRequiredParameter&quot;,
+        description: &quot;The backend should return an error if a message is missing a required parameter.&quot;,
+        message: {id: 123, method: &quot;Runtime.evaluate&quot;, params: {stuff: 123}},
+        expectedError: &quot;InvalidParams&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;RequiredParameterWrongType&quot;,
+        description: &quot;The backend should return an error if a message has a required parameter with wrong type.&quot;,
+        message: {id: 123, method: &quot;Runtime.evaluate&quot;, params: {expression: []}},
+        expectedError: &quot;InvalidParams&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;OptionalParameterWrongType&quot;,
+        description: &quot;The backend should return an error if a message has an optional parameter with wrong type.&quot;,
+        message: {id: 123, method: &quot;Runtime.evaluate&quot;, params: {expression: &quot;42&quot;, includeCommandLineAPI: 123}},
+        expectedError: &quot;InvalidParams&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;TestErrorCodeForSyncServerError&quot;,
+        description: &quot;The backend should return a server error with the correct error code.&quot;,
+        message: {id: 123, method: &quot;Database.getDatabaseTableNames&quot;, params: {databaseId: &quot;thisisNotADatabase&quot;}},
+        expectedError: &quot;ServerError&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;TestErrorCodeForAsyncServerError&quot;,
+        description: &quot;The backend should return a server error with the correct error code.&quot;,
+        message: {id: 123, method: &quot;Database.executeSQL&quot;, params: {databaseId: &quot;thisisNotADatabase&quot;, query: &quot;asdf&quot;}},
+        expectedError: &quot;ServerError&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;CommandWithBadArgumentValue&quot;,
+        description: &quot;The backend should return an error if something went wrong when invoking the agent's method.&quot;,
+        message: {id: 123, method: &quot;Runtime.getProperties&quot;, params: {objectId: &quot;thisisNotAnId&quot;}},
+        expectedError: &quot;ServerError&quot;
+    });
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;p&gt;Testing the inspector backend's error handling when sending messages with wrong parameters.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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 &quot;ParseError&quot; (-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 &quot;ParseError&quot; (-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 &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: 'id' property was not found
+
+-- Running test case: MissingIdField
+Sending message: {&quot;lucky&quot;:123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: 'id' property was not found
+
+-- Running test case: IdFieldWithArrayType
+Sending message: {&quot;id&quot;:[]}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: The type of 'id' property must be integer
+
+-- Running test case: IdFieldWithStringType
+Sending message: {&quot;id&quot;:&quot;123&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: The type of 'id' property must be integer
+
+-- Running test case: MissingMethodField
+Sending message: {&quot;id&quot;:123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: 'method' property wasn't found
+
+-- Running test case: MethodFieldWithArrayType
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:[]}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: The type of 'method' property must be string
+
+-- Running test case: MethodFieldWithNumberType
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:123}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-32600)
+Actual error code: -32600
+Actual error message: The type of 'method' property must be string
+
+-- Running test case: MethodFieldWithBadFormatting
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:&quot;ThisIsDefinitelyNotADomainAndMethod&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;ThisIsDefinitelyNotADomainAndMethod.&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;.ThisIsDefinitelyNotADomainAndMethod&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;.&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;.FooBar.&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;Foo.Bar.Baz&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;InvalidRequest&quot; (-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: {&quot;id&quot;:123,&quot;method&quot;:&quot;DummyDomain.DummyMethod&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;MethodNotFound&quot; (-32601)
+Actual error code: -32601
+Actual error message: 'DummyDomain' domain was not found
+
+-- Running test case: MethodFieldWithFakeMethod
+Sending message: {&quot;id&quot;:123,&quot;method&quot;:&quot;Inspector.DummyMethod&quot;}
+PASS: the backend should send a protocol error when receiving for an invalid message.
+PASS: the reported error should be &quot;MethodNotFound&quot; (-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>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/protocol-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function test()
+{
+    let suite = ProtocolTest.createAsyncSuite(&quot;Protocol.MalformedMessageErrors&quot;);
+
+    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) =&gt; {
+                let stringifiedMessage = (typeof message !== &quot;string&quot;) ? JSON.stringify(message) : message;
+                ProtocolTest.log(&quot;Sending message: &quot; + stringifiedMessage);
+                InspectorProtocol.awaitMessage(message)
+                .then(function resolved(response) {
+                    ProtocolTest.log(&quot;FAIL: the backend should send a protocol error when receiving for an invalid message.&quot;);
+                    reject();
+                }, function rejected(response) {
+                    ProtocolTest.log(&quot;PASS: the backend should send a protocol error when receiving for an invalid message.&quot;);
+                    ProtocolTest.expectThat(response.code === errorCodes[expectedError], `the reported error should be &quot;${expectedError}&quot; (${errorCodes[expectedError]})`);
+                    ProtocolTest.log(&quot;Actual error code: &quot; + response.code);
+                    ProtocolTest.log(&quot;Actual error message: &quot; + response.message);
+                    resolve();
+                })
+                .catch(reject);
+            }
+        });
+    }
+
+    addErrorResponseTestCase({
+        name: &quot;UnparseableStringMessage&quot;,
+        description: &quot;The backend should return an error if a message is not valid JSON.&quot;,
+        message: &quot;not-a-json-object&quot;,
+        expectedError: &quot;ParseError&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;JSONObjectWithSyntaxError&quot;,
+        description: &quot;The backend should return an error if a message is not valid JSON.&quot;,
+        message: &quot;{name: 123,}&quot;,
+        expectedError: &quot;ParseError&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;EmptyJSONObject&quot;,
+        description: &quot;The backend should return an error if a message lacks an 'id' field.&quot;,
+        message: {},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MissingIdField&quot;,
+        description: &quot;The backend should return an error if a message lacks an 'id' field.&quot;,
+        message: {lucky: 123},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;IdFieldWithArrayType&quot;,
+        description: &quot;The backend should return an error if a message has a non-numeric 'id' field.&quot;,
+        message: {id: []},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;IdFieldWithStringType&quot;,
+        description: &quot;The backend should return an error if a message has a non-numeric 'id' field.&quot;,
+        message: {id: &quot;123&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MissingMethodField&quot;,
+        description: &quot;The backend should return an error if a message lacks a 'method' field.&quot;,
+        message: {id: 123},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithArrayType&quot;,
+        description: &quot;The backend should return an error if a message has a non-string 'method' field.&quot;,
+        message: {id: 123, method: []},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithNumberType&quot;,
+        description: &quot;The backend should return an error if a message has a non-string 'method' field.&quot;,
+        message: {id: 123, method: 123},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;ThisIsDefinitelyNotADomainAndMethod&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting2&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;ThisIsDefinitelyNotADomainAndMethod.&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting3&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;.ThisIsDefinitelyNotADomainAndMethod&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting4&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;.&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting5&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;.FooBar.&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithBadFormatting6&quot;,
+        description: &quot;The backend should return an error if a message has a 'method' field not formatted as 'Domain.Methodname'.&quot;,
+        message: {id: 123, method: &quot;Foo.Bar.Baz&quot;},
+        expectedError: &quot;InvalidRequest&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithFakeDomain&quot;,
+        description: &quot;The backend should return an error if a message specifies a domain that doesn't exist.&quot;,
+        message: {id: 123, method: &quot;DummyDomain.DummyMethod&quot;},
+        expectedError: &quot;MethodNotFound&quot;
+    });
+
+    addErrorResponseTestCase({
+        name: &quot;MethodFieldWithFakeMethod&quot;,
+        description: &quot;The backend should return an error if a message specifies a method that doesn't exist.&quot;,
+        message: {id: 123, method: &quot;Inspector.DummyMethod&quot;},
+        expectedError: &quot;MethodNotFound&quot;
+    });
+
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;p&gt;Testing the inspector backend's error handling when sending invalid messages.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</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  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r188897. rdar://problem/23221163
+
+    2015-08-24  Brian Burg  &lt;bburg@apple.com&gt;
+
+            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 &quot;method&quot; 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  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r188631. rdar://problem/23221163
</span><span class="cx"> 
</span><span class="cx">     2015-08-18  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</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-&gt;asString(method)) {
</del><ins>+    String methodString;
+    if (!methodValue-&gt;asString(methodString)) {
</ins><span class="cx">         reportProtocolError(&amp;callId, InvalidRequest, ASCIILiteral(&quot;The type of 'method' property must be string&quot;));
</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&lt;String&gt; domainAndMethod;
+    methodString.split('.', true, domainAndMethod);
+    if (domainAndMethod.size() != 2 || !domainAndMethod[0].length() || !domainAndMethod[1].length()) {
</ins><span class="cx">         reportProtocolError(&amp;callId, InvalidRequest, ASCIILiteral(&quot;The 'method' property was formatted incorrectly. It should be 'Domain.method'&quot;));
</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(&amp;callId, MethodNotFound, &quot;'&quot; + domain + &quot;' domain was not found&quot;);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    String domainMethod = method.substring(position + 1);
-    domainDispatcher-&gt;dispatch(callId, domainMethod, messageObject.releaseNonNull());
</del><ins>+    String method = domainAndMethod[1];
+    domainDispatcher-&gt;dispatch(callId, method, messageObject.releaseNonNull());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void BackendDispatcher::sendResponse(long callId, RefPtr&lt;InspectorObject&gt;&amp;&amp; result, const ErrorString&amp; 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  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r188897. rdar://problem/23221163
+
+    2015-08-24  Brian Burg  &lt;bburg@apple.com&gt;
+
+            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  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r188876. rdar://problem/23221163
</span><span class="cx"> 
</span><span class="cx">     2015-08-24  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span></span></pre>
</div>
</div>

</body>
</html>