Fix crash when opening Web Inspector after a WebSocket was blocked by content extensions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:23:28 +0000 (19:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:23:28 +0000 (19:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194819

Patch by Loïc Yhuel <loic.yhuel@softathome.com> on 2019-02-20
Reviewed by Joseph Pecoraro.

Source/WebCore:

Test: http/tests/inspector/network/contentextensions/blocked-websocket-crash.html

* Modules/websockets/WebSocketChannel.h:
(WebCore::WebSocketChannel::hasCreatedHandshake):
* inspector/agents/page/PageNetworkAgent.cpp:
Ignore WebSocketChannel without an WebSocketHandshake, which would crash in InspectorNetworkAgent::enable.

LayoutTests:

* TestExpectations: Skip the test by default, like http/tests/contentextensions
* http/tests/inspector/network/contentextensions/blocked-websocket-crash-expected.txt: Added.
* http/tests/inspector/network/contentextensions/blocked-websocket-crash.html: Added.
* http/tests/inspector/network/contentextensions/blocked-websocket-crash.html.json: Added.
* platform/gtk/TestExpectations: Unskip the test
* platform/mac-wk2/TestExpectations: Ditto
* platform/wpe/TestExpectations: Ditto

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241824 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html.json [new file with mode: 0644]
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/wpe/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocketChannel.h
Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp

index f44a29a..e7aab60 100644 (file)
@@ -1,3 +1,18 @@
+2019-02-20  Loïc Yhuel  <loic.yhuel@softathome.com>
+
+        Fix crash when opening Web Inspector after a WebSocket was blocked by content extensions
+        https://bugs.webkit.org/show_bug.cgi?id=194819
+
+        Reviewed by Joseph Pecoraro.
+
+        * TestExpectations: Skip the test by default, like http/tests/contentextensions
+        * http/tests/inspector/network/contentextensions/blocked-websocket-crash-expected.txt: Added.
+        * http/tests/inspector/network/contentextensions/blocked-websocket-crash.html: Added.
+        * http/tests/inspector/network/contentextensions/blocked-websocket-crash.html.json: Added.
+        * platform/gtk/TestExpectations: Unskip the test
+        * platform/mac-wk2/TestExpectations: Ditto
+        * platform/wpe/TestExpectations: Ditto
+
 2019-02-20  Shawn Roberts  <sroberts@apple.com>
 
         REGRESSION (r240727) [ Mac iOS ] Layout Test http/tests/workers/service/basic-register-exceptions.html is flaky
index c2c19fb..878faae 100644 (file)
@@ -1179,6 +1179,7 @@ webkit.org/b/141695 [ Debug ] fast/selectors/nth-last-child-of-register-requirem
 
 # Content extensions are Mac-WK2-only for now
 http/tests/contentextensions [ Skip ]
+http/tests/inspector/network/contentextensions [ Skip ]
 http/tests/websocket/tests/hybi/contentextensions [ Skip ]
 http/wpt/beacon/contentextensions [ Skip ]
 
diff --git a/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash-expected.txt b/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash-expected.txt
new file mode 100644 (file)
index 0000000..2343bca
--- /dev/null
@@ -0,0 +1,8 @@
+CONSOLE MESSAGE: line 9: Content blocker prevented frame displaying http://127.0.0.1:8000/inspector/network/contentextensions/blocked-websocket-crash.html from loading a resource from ws://127.0.0.1/
+Test opening inspector after a blocked WebSocket connection.
+
+
+== Running test suite: Network.BlockedRequests
+-- Running test case: Network.BlockedRequests.WebSocket
+PASS: Web Inspector initialized.
+
diff --git a/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html b/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html
new file mode 100644 (file)
index 0000000..7b04e2a
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../../resources/inspector-test.js"></script>
+<script>
+// Create a WebSocket before opening the inspector
+// url doesn't matter : it will be blocked by the content extension
+let ws = new WebSocket("ws://127.0.0.1");
+
+function test() {
+    let suite = InspectorTest.createAsyncSuite("Network.BlockedRequests");
+    suite.addTestCase({
+        name: "Network.BlockedRequests.WebSocket",
+        description: "Ensure Web Inspector works even after a blocked WebSocket connection",
+        test(resolve, reject) {
+            InspectorTest.pass("Web Inspector initialized.");
+            resolve();
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Test opening inspector after a blocked WebSocket connection.</p>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html.json b/LayoutTests/http/tests/inspector/network/contentextensions/blocked-websocket-crash.html.json
new file mode 100644 (file)
index 0000000..902a369
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "trigger": {
+            "url-filter": "^ws://"
+        },
+        "action": {
+            "type": "block"
+        }
+    }
+]
index 5212d68..30b1d67 100644 (file)
@@ -3858,6 +3858,7 @@ fast/text/emoji-gender-fe0f-8.html [ Pass ]
 fast/text/emoji-gender-fe0f-9.html [ Pass ]
 
 http/tests/contentextensions [ Pass ]
+http/tests/inspector/network/contentextensions [ Pass ]
 
 imported/w3c/web-platform-tests/css/css-scoping/stylesheet-title-001.html [ Pass ]
 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-026.html [ Pass ]
index 51ec749..f9bf4c7 100644 (file)
@@ -518,6 +518,7 @@ webkit.org/b/141085 http/tests/media/video-query-url.html [ Pass Timeout ]
 
 # Content Extensions tests must be enabled explicitly on mac-wk2.
 http/tests/contentextensions [ Pass ]
+http/tests/inspector/network/contentextensions [ Pass ]
 http/tests/websocket/tests/hybi/contentextensions [ Pass ]
 [ Sierra+ ] http/wpt/beacon/contentextensions [ Pass ]
 
index 79f1535..1cc9d67 100644 (file)
@@ -613,6 +613,7 @@ fast/text/variations [ Pass ]
 
 # Content Extensions
 http/tests/contentextensions [ Pass ]
+http/tests/inspector/network/contentextensions [ Pass ]
 
 #////////////////////////////////////////////////////////////////////////////////////////
 # 5. TESTS CRASHING
index b72ab5f..fdc54ed 100644 (file)
@@ -1,3 +1,17 @@
+2019-02-20  Loïc Yhuel  <loic.yhuel@softathome.com>
+
+        Fix crash when opening Web Inspector after a WebSocket was blocked by content extensions
+        https://bugs.webkit.org/show_bug.cgi?id=194819
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: http/tests/inspector/network/contentextensions/blocked-websocket-crash.html
+
+        * Modules/websockets/WebSocketChannel.h:
+        (WebCore::WebSocketChannel::hasCreatedHandshake):
+        * inspector/agents/page/PageNetworkAgent.cpp:
+        Ignore WebSocketChannel without an WebSocketHandshake, which would crash in InspectorNetworkAgent::enable.
+
 2019-02-20  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][Floats] Make FloatAvoider::resetPosition implicit
index 68ce533..aae66b4 100644 (file)
@@ -116,6 +116,7 @@ public:
     void didFail(int errorCode) override;
 
     unsigned identifier() const { return m_identifier; }
+    bool hasCreatedHandshake() { return !!m_handshake; }
     ResourceRequest clientHandshakeRequest();
     const ResourceResponse& serverHandshakeResponse() const;
     WebSocketHandshake::Mode handshakeMode() const;
index 92980dc..c5d926a 100644 (file)
@@ -69,6 +69,9 @@ Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
         if (!channel)
             continue;
 
+        if (!channel->hasCreatedHandshake())
+            continue;
+
         if (!is<Document>(webSocket->scriptExecutionContext()))
             continue;