mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
LibWeb: Add simple in-tree WebSocket test
This commit is contained in:
parent
fb020a3c8f
commit
6889fa9695
Notes:
github-actions[bot]
2025-02-17 18:54:15 +00:00
Author: https://github.com/devgianlu
Commit: 6889fa9695
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3571
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 42 additions and 0 deletions
7
Tests/LibWeb/Text/expected/WebSocket/echo.txt
Normal file
7
Tests/LibWeb/Text/expected/WebSocket/echo.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
open
|
||||||
|
message WellHelloFriends0
|
||||||
|
message WellHelloFriends1
|
||||||
|
message WellHelloFriends2
|
||||||
|
message WellHelloFriends3
|
||||||
|
message WellHelloFriends4
|
||||||
|
close
|
35
Tests/LibWeb/Text/input/WebSocket/echo.html
Normal file
35
Tests/LibWeb/Text/input/WebSocket/echo.html
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest((done) => {
|
||||||
|
const ws = new WebSocket('wss://echo.websocket.org');
|
||||||
|
|
||||||
|
let messageCount = 0;
|
||||||
|
|
||||||
|
ws.onopen = function (ev) {
|
||||||
|
println(ev.type);
|
||||||
|
|
||||||
|
ws.onclose = function (ev) {
|
||||||
|
println(ev.type);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
ws.onerror = function (ev) {
|
||||||
|
println(ev.type);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onmessage = function (ev) {
|
||||||
|
if (ev.data.startsWith('WellHelloFriends')) {
|
||||||
|
println(`${ev.type} ${ev.data}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.send(`WellHelloFriends${messageCount}`);
|
||||||
|
if (messageCount++ === 5) {
|
||||||
|
ws.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws.onerror = function (ev) {
|
||||||
|
println(ev.type);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue