diff --git a/src/browser/dump.zig b/src/browser/dump.zig index 375952ca7..ca7736211 100644 --- a/src/browser/dump.zig +++ b/src/browser/dump.zig @@ -368,3 +368,60 @@ fn writeEscapedByte(input: []const u8, index: usize, writer: *std.Io.Writer) ![] } return input[index + 1 ..]; } + +const testing = @import("../testing.zig"); + +// A fresh page per assertion: `with_base` mutates the document (it inserts a +// element), so reusing one frame across opts would leak that mutation +// into later dumps. +fn expectDump(opts: Opts, expected: []const u8) !void { + var frame = try testing.pageTest("dump.html", .{}); + defer testing.reset(); + defer frame._session.removePage(); + + var aw: std.Io.Writer.Allocating = .init(testing.arena_allocator); + try root(frame.window._document, opts, &aw.writer, frame); + try testing.expectString(expected, aw.written()); +} + +test "dump: default dumps the whole document" { + try expectDump(.{}, + \\ + \\

Title

visible & well

+ ); +} + +test "dump: with_base injects a element" { + try expectDump(.{ .with_base = true }, + \\ + \\

Title

visible & well

+ ); +} + +test "dump: strip.js removes script and noscript" { + try expectDump(.{ .strip = .{ .js = true } }, + \\ + \\

Title

visible & well

+ ); +} + +test "dump: strip.css removes style and stylesheet links" { + try expectDump(.{ .strip = .{ .css = true } }, + \\ + \\

Title

visible & well

+ ); +} + +test "dump: strip.ui removes css plus visual elements" { + try expectDump(.{ .strip = .{ .ui = true } }, + \\ + \\

Title

visible & well

+ ); +} + +test "dump: strip.invisible removes author display:none elements" { + try expectDump(.{ .strip = .{ .invisible = true } }, + \\ + \\

Title

visible & well

+ ); +} diff --git a/src/browser/tests/dump.html b/src/browser/tests/dump.html new file mode 100644 index 000000000..462a2e1f1 --- /dev/null +++ b/src/browser/tests/dump.html @@ -0,0 +1 @@ +

Title

visible & well

\ No newline at end of file