mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-08-01 02:06:17 -04:00
add unit tests for dump
This commit is contained in:
@@ -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
|
||||
// <base> 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(.{},
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><style>.hidden{display:none}</style><link rel="stylesheet" href="data:text/css,"><script>var a=1;</script></head><body><h1>Title</h1><p class="hidden">secret</p><img><svg></svg><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
test "dump: with_base injects a <base> element" {
|
||||
try expectDump(.{ .with_base = true },
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><base base="http://127.0.0.1:9582/src/browser/tests/dump.html"></base><style>.hidden{display:none}</style><link rel="stylesheet" href="data:text/css,"><script>var a=1;</script></head><body><h1>Title</h1><p class="hidden">secret</p><img><svg></svg><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
test "dump: strip.js removes script and noscript" {
|
||||
try expectDump(.{ .strip = .{ .js = true } },
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><style>.hidden{display:none}</style><link rel="stylesheet" href="data:text/css,"></head><body><h1>Title</h1><p class="hidden">secret</p><img><svg></svg><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
test "dump: strip.css removes style and stylesheet links" {
|
||||
try expectDump(.{ .strip = .{ .css = true } },
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><script>var a=1;</script></head><body><h1>Title</h1><p class="hidden">secret</p><img><svg></svg><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
test "dump: strip.ui removes css plus visual elements" {
|
||||
try expectDump(.{ .strip = .{ .ui = true } },
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><script>var a=1;</script></head><body><h1>Title</h1><p class="hidden">secret</p><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
test "dump: strip.invisible removes author display:none elements" {
|
||||
try expectDump(.{ .strip = .{ .invisible = true } },
|
||||
\\<!DOCTYPE html>
|
||||
\\<html><head><style>.hidden{display:none}</style><link rel="stylesheet" href="data:text/css,"><script>var a=1;</script></head><body><h1>Title</h1><img><svg></svg><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
);
|
||||
}
|
||||
|
||||
1
src/browser/tests/dump.html
Normal file
1
src/browser/tests/dump.html
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><style>.hidden{display:none}</style><link rel="stylesheet" href="data:text/css,"><script>var a=1;</script></head><body><h1>Title</h1><p class="hidden">secret</p><img><svg></svg><noscript>nojs</noscript><p>visible & well</p></body></html>
|
||||
Reference in New Issue
Block a user