Title: [294374] trunk
Revision
294374
Author
yu...@chromium.org
Date
2022-05-17 18:17:36 -0700 (Tue, 17 May 2022)

Log Message

Web Inspector: support EventSource resource type in Network Panel
https://bugs.webkit.org/show_bug.cgi?id=240326

Reviewed by Devin Rousso.

* http/tests/inspector/network/eventsource-type-expected.txt: Added.
* http/tests/inspector/network/eventsource-type.html: Added.
* http/tests/inspector/network/resources/event-source.py: Added.
Web Inspector: support EventSource resource type in Network Panel
https://bugs.webkit.org/show_bug.cgi?id=240326

* inspector/protocol/Page.json: added EventSource resource type.
Web Inspector: support EventSource resource type in Network Panel
https://bugs.webkit.org/show_bug.cgi?id=240326

Network requests initiated by EventSource now have their own requester
type which allows to distinguish them from other requests.

Test: http/tests/inspector/network/eventsource-type.html

* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::resourceTypeJSON):
(WebCore::InspectorPageAgent::inspectorResourceType):
* inspector/agents/InspectorPageAgent.h:
* page/EventSource.cpp:
(WebCore::EventSource::connect):
* platform/network/ResourceRequestBase.h:
Web Inspector: support EventSource resource type in Network Panel
https://bugs.webkit.org/show_bug.cgi?id=240326

EventSource initiated requests are now displayed with their own type
in the network panel.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Controllers/NetworkManager.js:
(WI.NetworkManager.prototype.canBeOverridden):
* UserInterface/Models/Resource.js:
(WI.Resource.displayNameForType):
* UserInterface/Views/NetworkTableContentView.js:
(WI.NetworkTableContentView.displayNameForResource):

Canonical link: https://commits.webkit.org/250668@main

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/http/tests/inspector/network/eventsource-type-expected.txt (0 => 294374)


--- trunk/LayoutTests/http/tests/inspector/network/eventsource-type-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/eventsource-type-expected.txt	2022-05-18 01:17:36 UTC (rev 294374)
@@ -0,0 +1,20 @@
+Tests for Resource.Type.EventSource.
+
+
+== Running test suite: Resource.Type.EventSource
+-- Running test case: Resource.Type.EventSource.1.Event
+PASS: Resource should be EventSource type.
+PASS: Resource should be a GET request.
+EventSource events: onmessage: the end.
+PASS: Resource should have a 200 response.
+PASS: Resource should receive 'Success' in the response.
+PASS: Response should not be base64 encoded.
+
+-- Running test case: Resource.Type.EventSource.3.Events
+PASS: Resource should be EventSource type.
+PASS: Resource should be a GET request.
+EventSource events: user: alice,user: bill,onmessage: the end.
+PASS: Resource should have a 200 response.
+PASS: Resource should receive 'Success' in the response.
+PASS: Response should not be base64 encoded.
+

Added: trunk/LayoutTests/http/tests/inspector/network/eventsource-type.html (0 => 294374)


--- trunk/LayoutTests/http/tests/inspector/network/eventsource-type.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/eventsource-type.html	2022-05-18 01:17:36 UTC (rev 294374)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script>
+function triggerEventSourceRequest(users) {
+    const eventSource = new EventSource(`resources/event-source.py?users=${users}`);
+    const messages = [];
+    eventSource.addEventListener('user', e => {
+        messages.push('user: ' + e.data);
+    });
+    eventSource._onmessage_ = e => {
+        messages.push("onmessage: " + e.data);
+        TestPage.dispatchEventToFrontend("Completed", messages);
+    }
+}
+
+// ----
+
+function test()
+{
+    const suite = InspectorTest.createAsyncSuite("Resource.Type.EventSource");
+
+    function addTestCase({name, description, _expression_, resourceHandler}) {
+        suite.addTestCase({
+            name, description,
+            async test() {
+                const completeEvent = InspectorTest.awaitEvent("Completed");
+                InspectorTest.evaluateInPage(_expression_);
+                const event = await WI.Frame.awaitEvent(WI.Frame.Event.ResourceWasAdded);
+                const resource = event.data.resource;
+                InspectorTest.assert(resource.url.includes('event-source.py'), `Resource should be "event-source.py"`);
+                InspectorTest.expectEqual(resource.type, WI.Resource.Type.EventSource, "Resource should be EventSource type.");
+                InspectorTest.expectEqual(resource.requestMethod, "GET", "Resource should be a GET request.");
+                await resource.awaitEvent(WI.Resource.Event.LoadingDidFinish);
+                const content = await resource.requestContentFromBackend()
+                InspectorTest.log('EventSource events: ' + (await completeEvent).data);
+                resourceHandler(resource, content);
+            }
+        });
+    }
+
+    addTestCase({
+        name: "Resource.Type.EventSource.1.Event",
+        description: "Event source that receives 1 event.",
+        _expression_: "triggerEventSourceRequest('')",
+        resourceHandler(resource, content) {
+            InspectorTest.expectEqual(resource.statusCode, 200, "Resource should have a 200 response.");
+            InspectorTest.expectEqual(content.body, "data: the end.\n\n", "Resource should receive 'Success' in the response.");
+            InspectorTest.expectEqual(content.base64Encoded, false, "Response should not be base64 encoded.");
+        }
+    });
+
+    addTestCase({
+        name: "Resource.Type.EventSource.3.Events",
+        description: "Event source that receives 3 events.",
+        _expression_: "triggerEventSourceRequest('alice,bill')",
+        resourceHandler(resource, content) {
+            InspectorTest.expectEqual(resource.statusCode, 200, "Resource should have a 200 response.");
+            InspectorTest.expectEqual(content.body, "event: user\ndata: alice\n\nevent: user\ndata: bill\n\ndata: the end.\n\n", "Resource should receive 'Success' in the response.");
+            InspectorTest.expectEqual(content.base64Encoded, false, "Response should not be base64 encoded.");
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests for Resource.Type.EventSource.</p>
+<div id="log"></div>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/inspector/network/resources/event-source.py (0 => 294374)


--- trunk/LayoutTests/http/tests/inspector/network/resources/event-source.py	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/event-source.py	2022-05-18 01:17:36 UTC (rev 294374)
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+from urllib.parse import parse_qs
+
+sys.stdout.write('Content-Type: text/html\r\n')
+
+users = parse_qs(os.environ.get('QUERY_STRING', '')).get('users', [''])[0].split(',')
+users = filter(lambda s: len(s), users)
+
+sys.stdout.write(
+    'Content-Type: text/event-stream\r\n'
+    'Connection: keep-alive\r\n'
+    'Cache-Control: no-cache\r\n'
+    'status: 200\r\n'
+    '\r\n'
+)
+
+for user in users:
+    sys.stdout.write(
+        'event: user\n'
+        'data: {}\n'
+        '\n'.format(user)
+    )
+
+sys.stdout.write(
+    'data: the end.\n'
+    '\n'
+)
Property changes on: trunk/LayoutTests/http/tests/inspector/network/resources/event-source.py
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property

Modified: trunk/Source/_javascript_Core/inspector/protocol/Page.json (294373 => 294374)


--- trunk/Source/_javascript_Core/inspector/protocol/Page.json	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/_javascript_Core/inspector/protocol/Page.json	2022-05-18 01:17:36 UTC (rev 294374)
@@ -27,7 +27,7 @@
         {
             "id": "ResourceType",
             "type": "string",
-            "enum": ["Document", "StyleSheet", "Image", "Font", "Script", "XHR", "Fetch", "Ping", "Beacon", "WebSocket", "Other"],
+            "enum": ["Document", "StyleSheet", "Image", "Font", "Script", "XHR", "Fetch", "Ping", "Beacon", "WebSocket", "EventSource", "Other"],
             "description": "Resource type as it was perceived by the rendering engine."
         },
         {

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp (294373 => 294374)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2022-05-18 01:17:36 UTC (rev 294374)
@@ -235,6 +235,8 @@
         return Protocol::Page::ResourceType::Beacon;
     case WebSocketResource:
         return Protocol::Page::ResourceType::WebSocket;
+    case EventSourceResource:
+        return Protocol::Page::ResourceType::EventSource;
     case OtherResource:
         return Protocol::Page::ResourceType::Other;
 #if ENABLE(APPLICATION_MANIFEST)
@@ -286,6 +288,8 @@
             return InspectorPageAgent::FetchResource;
         case ResourceRequest::Requester::Main:
             return InspectorPageAgent::DocumentResource;
+        case ResourceRequest::Requester::EventSource:
+            return InspectorPageAgent::EventSourceResource;
         default:
             return InspectorPageAgent::XHRResource;
         }

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h (294373 => 294374)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h	2022-05-18 01:17:36 UTC (rev 294374)
@@ -72,6 +72,7 @@
 #if ENABLE(APPLICATION_MANIFEST)
         ApplicationManifestResource,
 #endif
+        EventSourceResource,
         OtherResource,
     };
 

Modified: trunk/Source/WebCore/page/EventSource.cpp (294373 => 294374)


--- trunk/Source/WebCore/page/EventSource.cpp	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebCore/page/EventSource.cpp	2022-05-18 01:17:36 UTC (rev 294374)
@@ -95,6 +95,7 @@
     ASSERT(!m_requestInFlight);
 
     ResourceRequest request { m_url };
+    request.setRequester(ResourceRequest::Requester::EventSource);
     request.setHTTPMethod("GET"_s);
     request.setHTTPHeaderField(HTTPHeaderName::Accept, "text/event-stream"_s);
     request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "no-cache"_s);

Modified: trunk/Source/WebCore/platform/network/ResourceRequestBase.h (294373 => 294374)


--- trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebCore/platform/network/ResourceRequestBase.h	2022-05-18 01:17:36 UTC (rev 294374)
@@ -167,7 +167,7 @@
     bool hiddenFromInspector() const { return m_hiddenFromInspector; }
     void setHiddenFromInspector(bool hiddenFromInspector) { m_hiddenFromInspector = hiddenFromInspector; }
 
-    enum class Requester : uint8_t { Unspecified, Main, XHR, Fetch, Media, Model, ImportScripts, Ping, Beacon };
+    enum class Requester : uint8_t { Unspecified, Main, XHR, Fetch, Media, Model, ImportScripts, Ping, Beacon, EventSource };
     Requester requester() const { return m_requester; }
     void setRequester(Requester requester) { m_requester = requester; }
 
@@ -432,7 +432,8 @@
         WebCore::ResourceRequestBase::Requester::Media,
         WebCore::ResourceRequestBase::Requester::ImportScripts,
         WebCore::ResourceRequestBase::Requester::Ping,
-        WebCore::ResourceRequestBase::Requester::Beacon
+        WebCore::ResourceRequestBase::Requester::Beacon,
+        WebCore::ResourceRequestBase::Requester::EventSource
     >;
 };
 

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (294373 => 294374)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2022-05-18 01:17:36 UTC (rev 294374)
@@ -643,6 +643,10 @@
 localizedStrings["Event Dispatched"] = "Event Dispatched";
 localizedStrings["Event Handlers:"] = "Event Handlers:";
 localizedStrings["Event Listeners"] = "Event Listeners";
+/* Display name for the type of network requests sent via EventSource API (https://developer.mozilla.org/en-US/docs/Web/API/EventSource) */
+localizedStrings["EventSource"] = "EventSource";
+/* Display name for the type of network requests sent via EventSource(s) API (https://developer.mozilla.org/en-US/docs/Web/API/EventSource) */
+localizedStrings["EventSources"] = "EventSources";
 localizedStrings["Events"] = "Events";
 localizedStrings["Events:"] = "Events:";
 localizedStrings["Exception with thrown value: %s"] = "Exception with thrown value: %s";
@@ -1798,6 +1802,8 @@
 /* Shown in the 'Type' column of the Network Table for document resources. */
 localizedStrings["document @ Network Tab Resource Type Column Value"] = "document";
 localizedStrings["ensuring that common debugging functions are available on every page via the Console"] = "ensuring that common debugging functions are available on every page via the Console";
+/* Shown in the 'Type' column of the Network Table for EventSource resources. */
+localizedStrings["eventsource @ Network Tab Resource Type Column Value"] = "eventsource";
 /* Shown in the 'Type' column of the Network Table for resources loaded via the 'fetch' method. */
 localizedStrings["fetch @ Network Tab Resource Type Column Value"] = "fetch";
 /* Shown in the 'Type' column of the Network Table for font resources. */

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/NetworkManager.js (294373 => 294374)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/NetworkManager.js	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/NetworkManager.js	2022-05-18 01:17:36 UTC (rev 294374)
@@ -468,6 +468,7 @@
         case WI.Resource.Type.Fetch:
         case WI.Resource.Type.Image:
         case WI.Resource.Type.Font:
+        case WI.Resource.Type.EventSource:
         case WI.Resource.Type.Other:
             break;
         case WI.Resource.Type.Ping:

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (294373 => 294374)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2022-05-18 01:17:36 UTC (rev 294374)
@@ -172,6 +172,10 @@
             if (plural)
                 return WI.UIString("Sockets");
             return WI.UIString("Socket");
+        case WI.Resource.Type.EventSource:
+            if (plural)
+                return WI.UIString("EventSources", "Display name for the type of network requests sent via EventSource(s) API (https://developer.mozilla.org/en-US/docs/Web/API/EventSource)");
+            return WI.UIString("EventSource", "Display name for the type of network requests sent via EventSource API (https://developer.mozilla.org/en-US/docs/Web/API/EventSource)");
         case WI.Resource.Type.Other:
             return WI.UIString("Other");
         default:
@@ -1285,6 +1289,7 @@
     Ping: "resource-type-ping",
     Beacon: "resource-type-beacon",
     WebSocket: "resource-type-websocket",
+    EventSource: "resource-type-eventsource",
     Other: "resource-type-other",
 };
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js (294373 => 294374)


--- trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js	2022-05-18 01:09:07 UTC (rev 294373)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/NetworkTableContentView.js	2022-05-18 01:17:36 UTC (rev 294374)
@@ -224,6 +224,9 @@
         case WI.Resource.Type.WebSocket:
             return WI.UIString("socket", "socket @ Network Tab Resource Type Column Value", "Shown in the 'Type' column of the Network Table for WebSocket resources.");
 
+        case WI.Resource.Type.EventSource:
+            return WI.UIString("eventsource", "eventsource @ Network Tab Resource Type Column Value", "Shown in the 'Type' column of the Network Table for resources loaded via the EventSource API.");
+
         case WI.Resource.Type.Other:
             return WI.UIString("other", "other @ Network Tab Resource Type Column Value", "Shown in the 'Type' column of the Network Table for resources that don't fall into any of the other known types/categories.");
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to