copy history test from legacy

This commit is contained in:
Karl Seguin
2026-01-05 10:12:41 +08:00
parent 5a974f0d77
commit 7b0e256408
5 changed files with 49 additions and 8 deletions

View File

@@ -827,13 +827,6 @@ pub const Script = struct {
return;
}
// @ZIGDOM
// if (page.delayed_navigation) {
// // If we're navigating to another page, an error is expected
// // since we probably terminated the script forcefully.
// return;
// }
const msg = try_catch.err(page.arena) catch |err| @errorName(err) orelse "unknown";
log.warn(.js, "eval script", .{
.url = url,

View File

@@ -0,0 +1,37 @@
<!DOCTYPE html>
<script src="testing.js"></script>
<script id=history>
testing.expectEqual('auto', history.scrollRestoration);
history.scrollRestoration = 'manual';
testing.expectEqual('manual', history.scrollRestoration);
history.scrollRestoration = 'auto';
testing.expectEqual('auto', history.scrollRestoration);
testing.expectEqual(null, history.state)
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9582/src/browser/tests/history_after_nav.skip.html');
testing.expectEqual({ testInProgress: true }, history.state);
history.pushState({ testInProgress: false }, null, 'http://127.0.0.1:9582/xhr/json');
history.replaceState({ "new": "field", testComplete: true }, null);
let state = { "new": "field", testComplete: true };
testing.expectEqual(state, history.state);
let popstateEventFired = false;
let popstateEventState = null;
window.addEventListener('popstate', (event) => {
popstateEventFired = true;
popstateEventState = event.state;
});
testing.eventually(() => {
testing.expectEqual(true, popstateEventFired);
testing.expectEqual(state, popstateEventState);
})
history.back();
</script>

View File

@@ -0,0 +1,6 @@
<!DOCTYPE html>
<script src="testing.js"></script>
<script id=history-after-nav>
testing.expectEqual(true, history.state && history.state.testInProgress);
</script>

View File

@@ -123,3 +123,8 @@ pub const JsApi = struct {
pub const forward = bridge.function(History.forward, .{});
pub const go = bridge.function(History.go, .{});
};
const testing = @import("../../testing.zig");
test "WebApi: History" {
try testing.htmlRunner("history.html", .{});
}

View File

@@ -405,7 +405,7 @@ fn runWebApiTest(test_file: [:0]const u8) !void {
try page.navigate(url, .{});
_ = test_session.wait(2000);
page._session.browser.runMicrotasks();
test_browser.runMicrotasks();
js_context.eval("testing.assertOk()", "testing.assertOk()") catch |err| {
const msg = try_catch.err(arena_allocator) catch @errorName(err) orelse "unknown";