Lightpanda: the headless browser designed for AI and automation
update tests
Halil Durakef7dc313e6bc
diff --git a/src/browser/tests/element/html/image_fetch.html b/src/browser/tests/element/html/image_fetch.htmlindex d904fbb1a..01a9f7bbd 100644--- a/src/browser/tests/element/html/image_fetch.html+++ b/src/browser/tests/element/html/image_fetch.html@@ -9,7 +9,7 @@complete successfully — that's what makes these a test of the fetch pathand not just of the event plumbing.- /images/ok.png is over Request.HEADERS_ONLY_DRAIN_MAX (abort branch),+ /images/ok.png is over the headers-only drain threshold (abort branch),/images/small.png is under it (drain branch).-->@@ -69,9 +69,8 @@</script><script id="img-many-share-one-connection" type=module>- // A page's worth of small images. They queue at low priority behind- // anything else, and each drained body returns its connection to the- // pool, so this must settle without starving or stalling.+ // A page's worth of small images. Each drained body returns its+ // connection to the pool, so this must settle without stalling.const state = await testing.async();const results = await Promise.all(Array.from({ length: 12 }, (_, i) => new Promise(resolve => {@@ -89,6 +88,24 @@});</script>+<script id="img-chunked-body-loads" type=module>+ // No Content-Length, so the drain/abort decision can't be made up front.+ // Small enough to drain; either way it must report the real status.+ const state = await testing.async();+ const img = document.createElement("img");++ const evt = await new Promise(resolve => {+ img.addEventListener("load", () => resolve("load"));+ img.addEventListener("error", () => resolve("error"));+ img.src = "/images/chunked.png";+ });++ state.resolve();+ await state.done(() => {+ testing.expectEqual("load", evt);+ });+</script>+<script id="img-500-fires-error" type=module>const state = await testing.async();const img = document.createElement("img");@@ -205,6 +222,28 @@});</script>+<script id="img-removing-src-supersedes" type=module>+ // removeAttribute has to invalidate the in-flight fetch the same way a+ // reassignment does, and leave the element complete.+ const state = await testing.async();+ const img = document.createElement("img");++ const events = [];+ img.addEventListener("load", () => events.push("load"));+ img.addEventListener("error", () => events.push("error"));++ img.src = "/images/ok.png";+ img.removeAttribute("src");++ await new Promise(resolve => setTimeout(resolve, 300));++ state.resolve();+ await state.done(() => {+ testing.expectEqual(0, events.length);+ testing.expectEqual(true, img.complete);+ });+</script>+<script id="img-fragment-parse-does-not-fetch">{// Images parsed via innerHTML / DOMParser must not hit the network, fordiff --git a/src/testing.zig b/src/testing.zigindex 2ff0de016..d3e0d8aff 100644--- a/src/testing.zig+++ b/src/testing.zig@@ -973,17 +973,13 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {});}- // Image routes for element/html/image_fetch.html. Every body here is- // non-empty, so libcurl always reaches the write callback — which is- // where `--fetch-images headers` decides what to do. A `load` event off- // any of these proves that decision ended in a successful response.- //- // ok.png is deliberately larger than Request.HEADERS_ONLY_DRAIN_MAX so- // it takes the abort branch; small.png is deliberately under it so it- // takes the drain-and-keep-the-connection branch. Both must behave- // identically as far as the DOM is concerned.+ // Bodies are non-empty so that libcurl always reaches the write callback,+ // which is where a headers_only request decides whether to drain or abort.+ // ok.png takes the abort branch, small.png the drain branch; both must+ // behave identically as far as the DOM is concerned.if (std.mem.eql(u8, path, "/images/ok.png")) {- const body = try arena_allocator.alloc(u8, 64 * 1024);+ // > HttpClient.Request.HEADERS_ONLY_DRAIN_MAX+ const body = try arena_allocator.alloc(u8, 16 * 1024 + 1);@memset(body, 'x');return req.respond(body, .{.extra_headers = &.{@@ -992,8 +988,8 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {});}- // startsWith, not eql: the concurrency test appends ?n= to get distinct- // URLs (and so distinct transfers) off one route.+ // startsWith, not eql: a caller can append a query string to get distinct+ // URLs (and so distinct transfers) off this one route.if (std.mem.startsWith(u8, path, "/images/small.png")) {const body = try arena_allocator.alloc(u8, 1024);@memset(body, 'x');@@ -1004,6 +1000,22 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {});}+ // No Content-Length: whether the body is small enough to drain can only+ // be decided as it arrives.+ if (std.mem.eql(u8, path, "/images/chunked.png")) {+ var send_buffer: [1024]u8 = undefined;+ var res = try req.respondStreaming(&send_buffer, .{+ .respond_options = .{+ .extra_headers = &.{+ .{ .name = "Content-Type", .value = "image/svg+xml" },+ },+ },+ });+ try res.writer.writeAll("<svg xmlns=\"http://www.w3.org/2000/svg\"/>");+ try res.writer.flush();+ return res.end();+ }+if (std.mem.eql(u8, path, "/images/404.png")) {return req.respond("not here", .{.status = .not_found,