Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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/250672@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
12 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
LayoutTests/http/tests/inspector/network/eventsource-type-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
74 changes: 74 additions & 0 deletions
74
LayoutTests/http/tests/inspector/network/eventsource-type.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../resources/inspector-test.js"></script> | ||
<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> |
30 changes: 30 additions & 0 deletions
30
LayoutTests/http/tests/inspector/network/resources/event-source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters