<!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>[217912] trunk</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/217912">217912</a></dd>
<dt>Author</dt> <dd>drousso@apple.com</dd>
<dt>Date</dt> <dd>2017-06-07 17:05:55 -0700 (Wed, 07 Jun 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Add ContextMenu item to log WebSocket object to console
https://bugs.webkit.org/show_bug.cgi?id=172878

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* inspector/protocol/Network.json:
Add resolveWebSocket command.

Source/WebCore:

Test: http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html

* inspector/InspectorNetworkAgent.h:
* inspector/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::InspectorNetworkAgent):
(WebCore::InspectorNetworkAgent::webSocketForRequestId):
(WebCore::webSocketAsScriptValue):
(WebCore::InspectorNetworkAgent::resolveWebSocket):
Loops over the static allActiveWebSockets to find one with the given requestId. If found, it
will create a RemoteObject wrapper for it and send it back to the inspector.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:

* UserInterface/Protocol/RemoteObject.js:
(WebInspector.RemoteObject.resolveWebSocket):

* UserInterface/Views/ResourceTreeElement.js:
(WebInspector.ResourceTreeElement.prototype.populateContextMenu):

LayoutTests:

* http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt: Added.
* http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html: Added.

* http/tests/websocket/tests/hybi/inspector/before-load-expected.txt:
* http/tests/websocket/tests/hybi/inspector/before-load.html:
* http/tests/websocket/tests/hybi/inspector/before-load_wsh.py: Removed.
* http/tests/websocket/tests/hybi/inspector/client-close.html:
* http/tests/websocket/tests/hybi/inspector/client-close_wsh.py: Removed.
* http/tests/websocket/tests/hybi/inspector/send-and-receive.html:
* http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py: Removed.
* http/tests/websocket/tests/hybi/inspector/echo.py: Added.
(web_socket_do_extra_handshake):
(web_socket_transfer_data):
Unified common configurations for Inspector WebSocket tests.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeloadexpectedtxt">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeloadhtml">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorclientclosehtml">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close.html</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorsendandreceivehtml">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive.html</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorprotocolNetworkjson">trunk/Source/JavaScriptCore/inspector/protocol/Network.json</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorNetworkAgentcpp">trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorNetworkAgenth">trunk/Source/WebCore/inspector/InspectorNetworkAgent.h</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs">trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceProtocolRemoteObjectjs">trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsResourceTreeElementjs">trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorecho_wshpy">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/echo_wsh.py</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorresolveWebSocketexpectedtxt">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorresolveWebSockethtml">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeload_wshpy">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load_wsh.py</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorclientclose_wshpy">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close_wsh.py</a></li>
<li><a href="#trunkLayoutTestshttptestswebsockettestshybiinspectorsendandreceive_wshpy">trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/ChangeLog 2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2017-06-07  Devin Rousso  <drousso@apple.com>
</span><span class="cx"> 
</span><ins>+        Web Inspector: Add ContextMenu item to log WebSocket object to console
+        https://bugs.webkit.org/show_bug.cgi?id=172878
+
+        Reviewed by Joseph Pecoraro.
+
+        * http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html: Added.
+
+        * http/tests/websocket/tests/hybi/inspector/before-load-expected.txt:
+        * http/tests/websocket/tests/hybi/inspector/before-load.html:
+        * http/tests/websocket/tests/hybi/inspector/before-load_wsh.py: Removed.
+        * http/tests/websocket/tests/hybi/inspector/client-close.html:
+        * http/tests/websocket/tests/hybi/inspector/client-close_wsh.py: Removed.
+        * http/tests/websocket/tests/hybi/inspector/send-and-receive.html:
+        * http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py: Removed.
+        * http/tests/websocket/tests/hybi/inspector/echo.py: Added.
+        (web_socket_do_extra_handshake):
+        (web_socket_transfer_data):
+        Unified common configurations for Inspector WebSocket tests.
+
+2017-06-07  Devin Rousso  <drousso@apple.com>
+
</ins><span class="cx">         Web Inspector: Allow user to choose stylesheet when creating new rules
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=172487
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeloadexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt     2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt        2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx"> -- Running test case: WebSocket.BeforeLoad
</span><span class="cx"> PASS: Should have 1 WebSocketResource
</span><span class="cx"> PASS: Resource should be a WebSocket.
</span><del>-PASS: Resource URL should be "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/before-load".
</del><ins>+PASS: Resource URL should be "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo".
</ins><span class="cx"> PASS: Resource should have request headers.
</span><span class="cx"> PASS: Resource should have response headers.
</span><span class="cx"> Resource readyState should be Symbol(open).
</span></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeloadhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html     2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html        2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx"> {
</span><span class="cx">     testRunner.waitUntilDone();
</span><span class="cx"> 
</span><del>-    const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/before-load";
</del><ins>+    const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo";
</ins><span class="cx">     let webSocket = new WebSocket(url);
</span><span class="cx">     webSocket.addEventListener("open", (event) => {
</span><span class="cx">         // Only run the tests once the websocket has connected.
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx">         name: "WebSocket.BeforeLoad",
</span><span class="cx">         description: "Test that the existing websocket is sent to the frontend when it is first opened.",
</span><span class="cx">         test(resolve, reject) {
</span><del>-            const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/before-load";
</del><ins>+            const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo";
</ins><span class="cx">             let webSocketResources = WebInspector.frameResourceManager.mainFrame.resourceCollectionForType(WebInspector.Resource.Type.WebSocket);
</span><span class="cx">             InspectorTest.expectEqual(webSocketResources.items.size, 1, "Should have 1 WebSocketResource");
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorbeforeload_wshpy"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load_wsh.py (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load_wsh.py   2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load_wsh.py      2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,11 +0,0 @@
</span><del>-from mod_pywebsocket import msgutil
-
-
-def web_socket_do_extra_handshake(request):
-    pass # Always accept.
-
-
-def web_socket_transfer_data(request):
-    # Echo message back
-    message = msgutil.receive_message(request)
-    msgutil.send_message(request, message)
</del></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorclientclosehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close.html (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close.html    2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close.html       2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx"> <script>
</span><span class="cx"> function createWebSocketConnection()
</span><span class="cx"> {
</span><del>-    let webSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/inspector/client-close");
</del><ins>+    let webSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo");
</ins><span class="cx"> 
</span><span class="cx">     webSocket.onopen = function()
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorclientclose_wshpy"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close_wsh.py (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close_wsh.py  2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/client-close_wsh.py     2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,11 +0,0 @@
</span><del>-from mod_pywebsocket import msgutil
-
-
-def web_socket_do_extra_handshake(request):
-    pass # Always accept.
-
-
-def web_socket_transfer_data(request):
-    # Echo message back
-    message = msgutil.receive_message(request)
-    msgutil.send_message(request, message)
</del></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorecho_wshpyfromrev217911trunkLayoutTestshttptestswebsockettestshybiinspectorsendandreceive_wshpy"></a>
<div class="copfile"><h4>Copied: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/echo_wsh.py (from rev 217911, trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py) (0 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/echo_wsh.py                          (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/echo_wsh.py     2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+from mod_pywebsocket import msgutil
+
+
+def web_socket_do_extra_handshake(request):
+    pass # Always accept.
+
+
+def web_socket_transfer_data(request):
+    # Echo message back
+    message = msgutil.receive_message(request)
+    msgutil.send_message(request, message)
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorresolveWebSocketexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt (0 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt                                (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket-expected.txt   2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+Tests for the Network.resolveWebSocket command.
+
+
+== Running test suite: Network.resolveWebSocket
+-- Running test case: Network.resolveWebSocket.validRequestIdentifier
+PASS: Payload should have type "object".
+PASS: Payload should have className "WebSocket".
+PASS: Payload should have description "WebSocket".
+
+-- Running test case: Network.resolveWebSocket.invalidRequestIdentifier
+PASS: Should produce an error.
+Error: WebSocket not found
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorresolveWebSockethtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html (0 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html                                (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html   2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -0,0 +1,71 @@
</span><ins>+<!doctype html>
+<html>
+<head>
+<script src="../../../../inspector/resources/inspector-test.js"></script>
+<script>
+function load()
+{
+    testRunner.waitUntilDone();
+
+    const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo";
+    let webSocket = new WebSocket(url);
+    webSocket.addEventListener("open", (event) => {
+        // Only run the tests once the websocket has connected.
+        runTest();
+    });
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("Network.resolveWebSocket");
+
+    suite.addTestCase({
+        name: "Network.resolveWebSocket.validRequestIdentifier",
+        description: "Should return a valid response for the given request identifier.",
+        test(resolve, reject) {
+            const url = "ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo";
+            let webSocketResource = WebInspector.frameResourceManager.resourceForURL(url);
+            if (!webSocketResource) {
+                reject("Missing WebSocket resource.");
+                return;
+            }
+
+            const objectGroup = "test";
+            NetworkAgent.resolveWebSocket(webSocketResource.requestIdentifier, objectGroup, (error, object) => {
+                if (error) {
+                    reject(error);
+                    return;
+                }
+
+                InspectorTest.expectEqual(object.type, "object", "Payload should have type \"object\".");
+                InspectorTest.expectEqual(object.className, "WebSocket", "Payload should have className \"WebSocket\".");
+                InspectorTest.expectEqual(object.description, "WebSocket", "Payload should have description \"WebSocket\".");
+                resolve();
+            });
+        }
+    });
+
+    // ------
+
+    suite.addTestCase({
+        name: "Network.resolveWebSocket.invalidRequestIdentifier",
+        description: "Invalid request identifiers should cause an error.",
+        test(resolve, reject) {
+            const requestIdentifier = "DOES_NOT_EXIST";
+            const objectGroup = "test";
+            NetworkAgent.resolveWebSocket(requestIdentifier, objectGroup, (error) => {
+                InspectorTest.expectThat(error, "Should produce an error.");
+                InspectorTest.log("Error: " + error);
+                resolve();
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="load()">
+<p>Tests for the Network.resolveWebSocket command.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorsendandreceivehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive.html (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive.html        2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive.html   2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -9,7 +9,7 @@
</span><span class="cx"> 
</span><span class="cx"> function createWebSocketConnection()
</span><span class="cx"> {
</span><del>-    webSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/inspector/send-and-receive");
</del><ins>+    webSocket = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/inspector/echo");
</ins><span class="cx"> 
</span><span class="cx">     webSocket.onopen = function()
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkLayoutTestshttptestswebsockettestshybiinspectorsendandreceive_wshpy"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py      2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/send-and-receive_wsh.py 2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,11 +0,0 @@
</span><del>-from mod_pywebsocket import msgutil
-
-
-def web_socket_do_extra_handshake(request):
-    pass # Always accept.
-
-
-def web_socket_transfer_data(request):
-    # Echo message back
-    message = msgutil.receive_message(request)
-    msgutil.send_message(request, message)
</del></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/JavaScriptCore/ChangeLog       2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-06-07  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Add ContextMenu item to log WebSocket object to console
+        https://bugs.webkit.org/show_bug.cgi?id=172878
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/protocol/Network.json:
+        Add resolveWebSocket command.
+
</ins><span class="cx"> 2017-06-07  Jon Davis  <jond@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Update feature status for features Supported In Preview
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorprotocolNetworkjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/protocol/Network.json (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/protocol/Network.json      2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/JavaScriptCore/inspector/protocol/Network.json 2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -193,6 +193,17 @@
</span><span class="cx">                 { "name": "status", "type": "number", "description": "HTTP response status code." }
</span><span class="cx">             ],
</span><span class="cx">             "description": "Loads a resource in the context of a frame on the inspected page without cross origin checks."
</span><ins>+        },
+        {
+            "name": "resolveWebSocket",
+            "description": "Resolves JavaScript WebSocket object for given request id.",
+            "parameters": [
+                { "name": "requestId", "$ref": "RequestId", "description": "Identifier of the WebSocket resource to resolve." },
+                { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
+            ],
+            "returns": [
+                { "name": "object", "$ref": "Runtime.RemoteObject", "description": "JavaScript object wrapper for given node." }
+            ]
</ins><span class="cx">         }
</span><span class="cx">     ],
</span><span class="cx">     "events": [
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebCore/ChangeLog      2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2017-06-07  Devin Rousso  <drousso@apple.com>
</span><span class="cx"> 
</span><ins>+        Web Inspector: Add ContextMenu item to log WebSocket object to console
+        https://bugs.webkit.org/show_bug.cgi?id=172878
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: http/tests/websocket/tests/hybi/inspector/resolveWebSocket.html
+
+        * inspector/InspectorNetworkAgent.h:
+        * inspector/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::InspectorNetworkAgent):
+        (WebCore::InspectorNetworkAgent::webSocketForRequestId):
+        (WebCore::webSocketAsScriptValue):
+        (WebCore::InspectorNetworkAgent::resolveWebSocket):
+        Loops over the static allActiveWebSockets to find one with the given requestId. If found, it
+        will create a RemoteObject wrapper for it and send it back to the inspector.
+
+2017-06-07  Devin Rousso  <drousso@apple.com>
+
</ins><span class="cx">         Web Inspector: Allow user to choose stylesheet when creating new rules
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=172487
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorNetworkAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp 2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebCore/inspector/InspectorNetworkAgent.cpp    2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> #include "InspectorTimelineAgent.h"
</span><span class="cx"> #include "InstrumentingAgents.h"
</span><span class="cx"> #include "JSMainThreadExecState.h"
</span><ins>+#include "JSWebSocket.h"
</ins><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "NetworkResourcesData.h"
</span><span class="cx"> #include "Page.h"
</span><span class="lines">@@ -56,6 +57,7 @@
</span><span class="cx"> #include "ResourceLoader.h"
</span><span class="cx"> #include "ResourceRequest.h"
</span><span class="cx"> #include "ResourceResponse.h"
</span><ins>+#include "ScriptState.h"
</ins><span class="cx"> #include "ScriptableDocumentParser.h"
</span><span class="cx"> #include "SubresourceLoader.h"
</span><span class="cx"> #include "ThreadableLoaderClient.h"
</span><span class="lines">@@ -65,10 +67,13 @@
</span><span class="cx"> #include "WebSocketFrame.h"
</span><span class="cx"> #include <inspector/ContentSearchUtilities.h>
</span><span class="cx"> #include <inspector/IdentifiersFactory.h>
</span><ins>+#include <inspector/InjectedScript.h>
+#include <inspector/InjectedScriptManager.h>
</ins><span class="cx"> #include <inspector/InspectorFrontendRouter.h>
</span><span class="cx"> #include <inspector/InspectorValues.h>
</span><span class="cx"> #include <inspector/ScriptCallStack.h>
</span><span class="cx"> #include <inspector/ScriptCallStackFactory.h>
</span><ins>+#include <runtime/JSCInlines.h>
</ins><span class="cx"> #include <wtf/Lock.h>
</span><span class="cx"> #include <wtf/RefPtr.h>
</span><span class="cx"> #include <wtf/Stopwatch.h>
</span><span class="lines">@@ -158,6 +163,7 @@
</span><span class="cx">     : InspectorAgentBase(ASCIILiteral("Network"), context)
</span><span class="cx">     , m_frontendDispatcher(std::make_unique<Inspector::NetworkFrontendDispatcher>(context.frontendRouter))
</span><span class="cx">     , m_backendDispatcher(Inspector::NetworkBackendDispatcher::create(context.backendDispatcher, this))
</span><ins>+    , m_injectedScriptManager(context.injectedScriptManager)
</ins><span class="cx">     , m_pageAgent(pageAgent)
</span><span class="cx">     , m_resourcesData(std::make_unique<NetworkResourcesData>())
</span><span class="cx"> {
</span><span class="lines">@@ -779,6 +785,69 @@
</span><span class="cx">     inspectorThreadableLoaderClient->setLoader(WTFMove(loader));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(WEB_SOCKETS)
+
+WebSocket* InspectorNetworkAgent::webSocketForRequestId(const String& requestId)
+{
+    LockHolder lock(WebSocket::allActiveWebSocketsMutex());
+
+    for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
+        if (!is<WebSocketChannel>(webSocket->channel().get()))
+            continue;
+
+        WebSocketChannel* channel = downcast<WebSocketChannel>(webSocket->channel().get());
+        if (!channel)
+            continue;
+
+        if (IdentifiersFactory::requestId(channel->identifier()) != requestId)
+            continue;
+
+        // FIXME: <webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
+        if (!is<Document>(webSocket->scriptExecutionContext()))
+            continue;
+
+        Document* document = downcast<Document>(webSocket->scriptExecutionContext());
+        if (document->page() != &m_pageAgent->page())
+            continue;
+
+        return webSocket;
+    }
+
+    return nullptr;
+}
+
+static JSC::JSValue webSocketAsScriptValue(JSC::ExecState& state, WebSocket* webSocket)
+{
+    JSC::JSLockHolder lock(&state);
+    return toJS(&state, deprecatedGlobalObjectForPrototype(&state), webSocket);
+}
+
+void InspectorNetworkAgent::resolveWebSocket(ErrorString& errorString, const String& requestId, const String* const objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
+{
+    WebSocket* webSocket = webSocketForRequestId(requestId);
+    if (!webSocket) {
+        errorString = ASCIILiteral("WebSocket not found");
+        return;
+    }
+
+    // FIXME: <webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
+    Document* document = downcast<Document>(webSocket->scriptExecutionContext());
+    Frame* frame = document->frame();
+    if (!frame) {
+        errorString = ASCIILiteral("WebSocket belongs to document without a frame");
+        return;
+    }
+
+    auto& state = *mainWorldExecState(frame);
+    auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
+    ASSERT(!injectedScript.hasNoValue());
+
+    String objectGroupName = objectGroup ? *objectGroup : String();
+    result = injectedScript.wrapObject(webSocketAsScriptValue(state, webSocket), objectGroupName);
+}
+
+#endif // ENABLE(WEB_SOCKETS)
+
</ins><span class="cx"> static Ref<Inspector::Protocol::Page::SearchResult> buildObjectForSearchResult(const String& requestId, const String& frameId, const String& url, int matchesCount)
</span><span class="cx"> {
</span><span class="cx">     auto searchResult = Inspector::Protocol::Page::SearchResult::create()
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorNetworkAgenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorNetworkAgent.h (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorNetworkAgent.h   2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebCore/inspector/InspectorNetworkAgent.h      2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace Inspector {
</span><span class="cx"> class InspectorObject;
</span><ins>+class InjectedScriptManager;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -58,6 +59,7 @@
</span><span class="cx"> class URL;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WEB_SOCKETS)
</span><ins>+class WebSocket;
</ins><span class="cx"> struct WebSocketFrame;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -112,10 +114,17 @@
</span><span class="cx">     void getResponseBody(ErrorString&, const String& requestId, String* content, bool* base64Encoded) override;
</span><span class="cx">     void setResourceCachingDisabled(ErrorString&, bool disabled) override;
</span><span class="cx">     void loadResource(ErrorString&, const String& frameId, const String& url, Ref<LoadResourceCallback>&&) override;
</span><ins>+#if ENABLE(WEB_SOCKETS)
+    void resolveWebSocket(ErrorString&, const String& requestId, const String* const objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>&) override;
+#endif
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void enable();
</span><span class="cx"> 
</span><ins>+#if ENABLE(WEB_SOCKETS)
+    WebSocket* webSocketForRequestId(const String& requestId);
+#endif
+
</ins><span class="cx">     Ref<Inspector::Protocol::Network::ResourceTiming> buildObjectForTiming(const NetworkLoadMetrics&, ResourceLoader&);
</span><span class="cx">     Ref<Inspector::Protocol::Network::Metrics> buildObjectForMetrics(const NetworkLoadMetrics&);
</span><span class="cx">     RefPtr<Inspector::Protocol::Network::Response> buildObjectForResourceResponse(const ResourceResponse&, ResourceLoader*);
</span><span class="lines">@@ -125,6 +134,7 @@
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr<Inspector::NetworkFrontendDispatcher> m_frontendDispatcher;
</span><span class="cx">     RefPtr<Inspector::NetworkBackendDispatcher> m_backendDispatcher;
</span><ins>+    Inspector::InjectedScriptManager& m_injectedScriptManager;
</ins><span class="cx">     InspectorPageAgent* m_pageAgent { nullptr };
</span><span class="cx"> 
</span><span class="cx">     // FIXME: InspectorNetworkAgent should not be aware of style recalculation.
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog    2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebInspectorUI/ChangeLog       2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -1,5 +1,20 @@
</span><span class="cx"> 2017-06-07  Devin Rousso  <drousso@apple.com>
</span><span class="cx"> 
</span><ins>+        Web Inspector: Add ContextMenu item to log WebSocket object to console
+        https://bugs.webkit.org/show_bug.cgi?id=172878
+
+        Reviewed by Joseph Pecoraro.
+
+        * Localizations/en.lproj/localizedStrings.js:
+
+        * UserInterface/Protocol/RemoteObject.js:
+        (WebInspector.RemoteObject.resolveWebSocket):
+
+        * UserInterface/Views/ResourceTreeElement.js:
+        (WebInspector.ResourceTreeElement.prototype.populateContextMenu):
+
+2017-06-07  Devin Rousso  <drousso@apple.com>
+
</ins><span class="cx">         Web Inspector: Allow user to choose stylesheet when creating new rules
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=172487
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js   2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js      2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -510,6 +510,7 @@
</span><span class="cx"> localizedStrings["Log Message"] = "Log Message";
</span><span class="cx"> localizedStrings["Log Symbol"] = "Log Symbol";
</span><span class="cx"> localizedStrings["Log Value"] = "Log Value";
</span><ins>+localizedStrings["Log WebSocket"] = "Log WebSocket";
</ins><span class="cx"> localizedStrings["Log: "] = "Log: ";
</span><span class="cx"> localizedStrings["Logs"] = "Logs";
</span><span class="cx"> localizedStrings["Low"] = "Low";
</span><span class="lines">@@ -728,6 +729,7 @@
</span><span class="cx"> localizedStrings["Selected Items"] = "Selected Items";
</span><span class="cx"> localizedStrings["Selected Symbol"] = "Selected Symbol";
</span><span class="cx"> localizedStrings["Selected Value"] = "Selected Value";
</span><ins>+localizedStrings["Selected WebSocket"] = "Selected WebSocket";
</ins><span class="cx"> localizedStrings["Self"] = "Self";
</span><span class="cx"> localizedStrings["Self Size"] = "Self Size";
</span><span class="cx"> localizedStrings["Self Time"] = "Self Time";
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceProtocolRemoteObjectjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js       2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js  2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -138,6 +138,18 @@
</span><span class="cx">         });
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    static resolveWebSocket(webSocketResource, objectGroup, callback)
+    {
+        console.assert(typeof callback === "function");
+
+        NetworkAgent.resolveWebSocket(webSocketResource.requestIdentifier, objectGroup, (error, object) => {
+            if (error || !object)
+                callback(null);
+            else
+                callback(WebInspector.RemoteObject.fromPayload(object, webSocketResource.target));
+        });
+    }
+
</ins><span class="cx">     static type(remoteObject)
</span><span class="cx">     {
</span><span class="cx">         if (remoteObject === null)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsResourceTreeElementjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js (217911 => 217912)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js   2017-06-07 23:53:10 UTC (rev 217911)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceTreeElement.js      2017-06-08 00:05:55 UTC (rev 217912)
</span><span class="lines">@@ -161,6 +161,21 @@
</span><span class="cx"> 
</span><span class="cx">     populateContextMenu(contextMenu, event)
</span><span class="cx">     {
</span><ins>+        if (this._resource.type === WebInspector.Resource.Type.WebSocket) {
+            contextMenu.appendItem(WebInspector.UIString("Log WebSocket"), () => {
+                WebInspector.RemoteObject.resolveWebSocket(this._resource, WebInspector.RuntimeManager.ConsoleObjectGroup, (remoteObject) => {
+                    if (!remoteObject)
+                        return;
+
+                    const text = WebInspector.UIString("Selected WebSocket");
+                    const addSpecialUserLogClass = true;
+                    WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, remoteObject, addSpecialUserLogClass);
+                });
+            });
+
+            contextMenu.appendSeparator();
+        }
+
</ins><span class="cx">         WebInspector.appendContextMenuItemsForSourceCode(contextMenu, this._resource);
</span><span class="cx"> 
</span><span class="cx">         super.populateContextMenu(contextMenu, event);
</span></span></pre>
</div>
</div>

</body>
</html>