Commit graph

31 commits

Author SHA1 Message Date
Shannon Booth
303e47187e Tests: Configure WPT server substitutions for local hosts
Initialize the imported WPT server with the dynamic test HTTP port and
localhost-backed host aliases so .sub.html files can expand {{host}},
{{ports}}, and {{domains[...]}} during LibWeb text tests.
2026-06-11 17:01:48 +02:00
Shannon Booth
5c69ab992f Tests/LibWeb: Run imported WPT handlers in HTTP test server
Teach the local http-test-server hook to serve non-.py resources through
the vendored wptserve FileHandler instead of SimpleHTTPRequestHandler,
so WPT file features like ?pipe=..., .sub., and WPT .headers processing
work for ordinary resources as well.

Requests ending with .py are also now handled through WPTs python
script handler.
2026-06-06 13:48:43 +02:00
sideshowbarker
aabd3cd5fe Tests: Run a local WebSocket echo server in place of the hosted one
Problem: Our WebSocket tests were connecting to an externally-hosted
echo server — so they depended on network reachability from our CI
runners. Any network hiccups between a runner and that server timed the
tests out — and that’s been a relatively-frequent source of CI flakes.

Fix: Teach our existing in-tree echo server to also speak WebSocket. It
performs the RFC 6455 handshake, and echoes every text or binary frame
back — on the same OS-assigned port already exposed to tests. Updated
our tests to connect to that local server, not the remote one.

Also, updated our WebSocket echo.html to drive the exchange from its
onopen handler — rather than waiting for a server-initiated greeting.
That’s because: A frame the server sends in the moment right after the
handshake — before the client has sent anything — is currently delivered
unreliably by our (curl-backed) WebSocket client. See issue #9776.
2026-05-31 14:08:50 +02:00
Andreas Kling
412a66ad5e LibWeb: Repaint iframe containers after render unblocking
When an embedded document was render-blocked, the parent display list
recording skipped drawing that iframe's compositor surface. Once the
child document later unblocked, only the child surface was repainted, so
the parent could keep replaying a display list that had no surface draw
command until another invalidation, such as resize, forced a recording.

Invalidate the containing iframe when a document's render-blocking set
becomes empty so the parent display list records the child surface. Add
a deterministic reftest that gates a render-blocking stylesheet on a
test-server signal, forcing the parent to paint the blocked iframe
before unblocking it.
2026-05-24 12:24:50 +02:00
Shannon Booth
8a85146e35 Tests/LibWeb: Let .headers override SimpleHTTPRequestHandler headers
The test HTTP server used to append headers from .headers files after
SimpleHTTPRequestHandler had already emitted its own headers.

For headers such as Last-Modified, this produced duplicate response
headers. LibHTTP combines duplicate header values with ", ", which made
Document::lastModified unable to parse the configured Last-Modified
value and fall back to the current time.

Suppress SimpleHTTPServer headers whose names are provided by a .headers
file, while still allowing the explicit .headers values through.
2026-05-20 07:26:23 -04:00
Zaggy1024
33649933bf LibWeb: Avoid looping doubly over echo headers in http-test-server.py
This was iterating keys(), then calling get_all(key), which would
iterate the headers again. Not only that, but it would return all
headers with that key, so we would end up putting the same values
in the dict for every duplicate key. In practice, this shouldn't really
happen, but it's reasonable to avoid regardless.

This also fixes a type mismatch with the dict[str, list[str] | None]
being assigned to a dict[str, list].
2026-05-13 08:13:51 -05:00
Aliaksandr Kalenik
4762c4fa5c LibWeb: Add incremental HTML parsing
Introduce IncrementalDocumentParser, which streams the response body
through a TextCodec::StreamingDecoder into the HTMLTokenizer one chunk
at a time. The tokenizer pauses when it runs out of input and resumes
once the next chunk is appended; when the body closes we close the
tokenizer's input stream so it can finish the parse.

DocumentLoading routes HTML responses through the new parser instead of
buffering the full body before handing it to HTMLParser.
2026-04-29 04:12:44 +02:00
Tim Ledbetter
49834ef782 Tests: Add test server endpoint that records the last request's headers 2026-04-25 08:49:04 +02:00
Timothy Flynn
4ad800b594 RequestServer: Use correct request map for stale-while-revalidate cookie
When we request the HTTP cookie for a SWR request, we were providing the
cookie to the standard request corresponding to the SWR request's ID.
This had two effects:

1. The SWR request would never finish.
2. If the corresponding standard request happened to be a connect-only
   request, this would result in a crash as we were expecting it to have
   gone through the normal fetch process.

This was seen on some articles on news.google.com.
2026-04-13 19:43:13 -04:00
Shannon Booth
ba79535d94 Tests/LibWeb: Support absolute paths for WPT files in HTTP test server
Imported WPT tests often load resources using canonical absolute paths,
for example:

/html/browsers/windows/resources/message-parent.html

Our usual strategy is to rewrite such URLs to relative paths during
import so they resolve from the importing test HTML file (which also
allows for loading this HTML as a file://).

That works for same-origin relative loading with the echo server, but it
breaks down when a test constructs a cross-origin URL from an absolute
path, for example:

get_host_info().REMOTE_ORIGIN + "/some/wpt/path.html"

In that case the resource still needs to be fetched at its canonical
absolute path, so rewriting it relative to the importing document is no
longer sufficient.

Update the HTTP test server so /static/ continues to serve from the
general test root, other non-echo requests are served from the imported
WPT tree, and dynamically registered echo responses live under /echo/
to avoid path conflicts.
2026-03-23 22:32:43 +01:00
Shannon Booth
322fc9aff4 Tests/LibWeb: Factor out function to serving static files in echo server
To keep the routing logic as localized as possible.
2026-03-23 22:32:43 +01:00
Shannon Booth
892231ebb2 Tests/LibWeb: Use early return in handle_echo implementation
Reduce some of the nesting by early returning.
2026-03-23 22:32:43 +01:00
Shannon Booth
6db245b1fe Tests/LibWeb: Factor out a function to handle registering echo server
To accomodate for future routing changes without making the handler
too complicated.
2026-03-23 22:32:43 +01:00
Jelle Raaijmakers
f6f7e75ac9 LibWeb: Report actual network error for failed XHRs
Seeing "NetworkError: Network error" when an XHR failed was not that
useful - use the actual error message when available.
2026-03-22 18:58:49 +01:00
Jelle Raaijmakers
61ce8765bc Tests/LibWeb: Support base64-encoded bodies in HTTP test server
This makes it possible to make the HTTP test server respond with images,
for example. We'll need this for a new test we're adding.
2026-03-21 10:29:54 +01:00
Jonathan Gamble
34cecb4643 LibWeb+test-web: Allow identical echo registrations in http-test-server
The http-test-server.py change allows repeated fixed /echo route
registration by Text/input/navigation/iframe-referrer-policy.html.
Before this change, the second registration of the same method+path+def
returned 409, causing include.js to throw and fail the test.

Make /echo registration idempotent for identical definitions and return
success, but keep 409 for conflicting redefinitions of an existing
method+path.
2026-02-25 12:33:35 -06:00
Luke Wilde
84db5d8c1c Meta+test-web: Support per-test .headers files
If a test requires custom response headers, we now serve it via the
http-test-server, which will read the headers file and add them to the
response.
2026-02-19 14:58:09 +01:00
Timothy Flynn
8156531477 LibWeb: Decode Set-Cookie response headers before parsing
It's possible for the cookie value from a Set-Cookie header to contain
invalid UTF-8. We must isomorphic decode this header.

This fixes the /cookies/domain/domain-attribute-idn-host.sub.https.html
WPT test. The test added here is a crash test rather than a text test
because we cannot access the received Set-Cookie header from JS on the
file:// test URL.
2026-02-03 07:20:41 -05:00
CountBleck
bc0cceae1f LibWeb: Add a test checking the referrer of worker script fetches
Also, allow the echo server to reflect headers by substituting it into a
provided template body, enabling them to be read programmatically as
part of a script.
2026-01-31 22:45:08 +01:00
Timothy Flynn
453764d3f0 LibHTTP: Do not respond to Range requests with cached full responses
If we have the response for a non-Range request in the memory cache, we
would previously use it in reply to Range requests. Similar to commit
878b00ae61f998a26aad7f50fae66cf969878ad6, we are just punting on Range
requests in the HTTP caches for now.
2026-01-10 09:02:41 -05:00
Timothy Flynn
9f2ac14521 LibHTTP+RequestServer: Do not flush partial responses to the cache index
If the cURL request completes with anything other than CURLE_OK, we must
not keep the cache entry. For example, if the server's connection closes
while transferring data, we receive CURLE_PARTIAL_FILE. We don't want
this cache entry to be treated as valid in a subsequent request.
2026-01-08 11:59:12 +01:00
Timothy Flynn
4053a5f9d4 Tests/LibWeb: Create a copy of the echoed response headers
Otherwise, updates to the local `response_headers` will update the echo
store, which we do not want in upcoming tests.
2026-01-08 11:59:12 +01:00
Timothy Flynn
a4c8e39b99 test-web: Add basic support for If-Mod-Since requests in our test server
This just lets the test decide on a per-request basis if it wants the
test server to respond with a 304.
2025-11-20 09:33:49 +01:00
Julian Dominguez-Schatz
36bfee7f1b Tests: Add 'reflect' option to http-test-server.py
Add an option to http-test-server.py to return received headers as the
response body. This is useful for checking that outgoing headers are
correct, for example in cookie tests.
2025-09-24 10:12:56 +01:00
Timothy Flynn
18718e0876 Meta: Sort all python imports 2025-06-09 11:25:14 -04:00
rmg-x
0cd4c26ae8 Tests/LibWeb: Fix type for delay_ms property in HTTP echo server
This was mistakenly changed from int -> str in a previous commit:
08b8c88ac3
2024-12-07 15:49:15 +00:00
rmg-x
de595b713d Tests/LibWeb: Allow setting custom reason phrase in HTTP echo server 2024-12-06 06:09:44 +00:00
rmg-x
08b8c88ac3 Tests/LibWeb: Use Optional instead of | None syntax in echo script
The `str | None` syntax is only supported in Python 3.10+ and we can
support more Python versions without compromising readability by
importing the `Optional` type.
2024-12-06 06:09:44 +00:00
rmg-x
e4bc6178b9 Tests/LibWeb: Remove duplicate "headers" property in HTTP echo request 2024-12-06 06:09:44 +00:00
rmg-x
4dd21d0b80 Tests/LibWeb: Refactor HTTP echo server script
This commit makes the following changes:
- Adds a model "Echo" for the request body
- Changes the main endpoint from /create to /echo (more REST-y)
- Sends "400: Bad Request" for invalid params or a reserved path
- Sends "409: Conflict" when trying to use an already registered path
- Prints the server port to stdout
- Removes unnecessary subcommands/options (start, stop, --background)
2024-12-05 17:02:57 -07:00
Cory Virok
97d47a38c9 Meta: Add an HTTP echo server to help with testing Browser JS
This allows us to simulate HTTP responses from Browser JS tests.
Instead of using hacks like data URLs to "load" external data,
we can now generate an actual HTTP response that contains
arbitrary headers, body, and has a defined response delay.
2024-11-09 13:08:31 -07:00