Lightpanda: the headless browser designed for AI and automation
testing interface should respect `--load-resources`
Halil Durak24019ef1a73c
diff --git a/src/testing.zig b/src/testing.zigindex b0867994b..2ff0de016 100644--- a/src/testing.zig+++ b/src/testing.zig@@ -342,6 +342,7 @@ const HtmlRunnerOpts = struct {timeout_ms: u32 = 2000,inject_script: ?[]const u8 = null,load_external_stylesheets: bool = false,+ load_resources: Config.LoadResources = .{},};// Create a fresh page on `test_session` and return its root frame — for tests@@ -370,6 +371,9 @@ pub fn htmlRunner(comptime path: []const u8, opts: HtmlRunnerOpts) !void {test_session.load_external_stylesheets = opts.load_external_stylesheets;defer test_session.load_external_stylesheets = false;+ test_session.load_resources = opts.load_resources;+ defer test_session.load_resources = .{};+const root = try std.fs.path.joinZ(arena_allocator, &.{ WEB_API_TEST_ROOT, path });const stat = std.Io.Dir.cwd().statFile(io, root, .{}) catch |err| {std.debug.print("Failed to stat file: '{s}'", .{root});@@ -969,6 +973,64 @@ 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.+ if (std.mem.eql(u8, path, "/images/ok.png")) {+ const body = try arena_allocator.alloc(u8, 64 * 1024);+ @memset(body, 'x');+ return req.respond(body, .{+ .extra_headers = &.{+ .{ .name = "Content-Type", .value = "image/png" },+ },+ });+ }++ // startsWith, not eql: the concurrency test appends ?n= to get distinct+ // URLs (and so distinct transfers) off one route.+ if (std.mem.startsWith(u8, path, "/images/small.png")) {+ const body = try arena_allocator.alloc(u8, 1024);+ @memset(body, 'x');+ return req.respond(body, .{+ .extra_headers = &.{+ .{ .name = "Content-Type", .value = "image/png" },+ },+ });+ }++ if (std.mem.eql(u8, path, "/images/404.png")) {+ return req.respond("not here", .{+ .status = .not_found,+ .extra_headers = &.{+ .{ .name = "Content-Type", .value = "text/plain" },+ },+ });+ }++ if (std.mem.eql(u8, path, "/images/500.png")) {+ return req.respond("boom", .{+ .status = .internal_server_error,+ .extra_headers = &.{+ .{ .name = "Content-Type", .value = "text/plain" },+ },+ });+ }++ if (std.mem.eql(u8, path, "/images/redirect.png")) {+ return req.respond("", .{+ .status = .found,+ .extra_headers = &.{+ .{ .name = "Location", .value = "/images/ok.png" },+ },+ });+ }+if (std.mem.eql(u8, path, "/echo_referer")) {// Echo the request's Referer header back as HTML so tests can assert// what Referer the navigation sent. Used by the cross-page Referer test.