test(cdp): arm prepared document.open after parser EOF

Start the held Fetch from interactive readystatechange so the fixture establishes its intended defer-wait boundary. A speculative script request is not an EOF signal. Retain both normal/crashed modes and every history, adoption and result assertion without changing timeouts or retry policy.

Validation (32 build jobs / test threads, zero retries):

- `cargo fmt --all`
- `cargo clippy --workspace --all-targets --all-features -- -D warnings`
- `cargo nextest run --no-fail-fast`: Summary [ 140.487s] 22001 tests run: 22001 passed (9 slow), 19 skipped
This commit is contained in:
ldm0
2026-10-31 18:55:48 +08:00
committed by Donough Liu
parent e340190114
commit dc75f53ea9
@@ -1421,9 +1421,21 @@ async fn websocket_cdp_prepared_document_open_does_not_append_history_on_adoptio
json!({"discover": true}),
)
.await;
// The asynchronous callback runs during a defer wait, outside parser
// script execution where document.open() would otherwise be ignored.
let html = "<!doctype html><title>before-open</title><script>fetch('/arm').then(()=>{document.open();document.write('<title>after-open</title><p>replacement</p>');document.close();});</script><script defer src=/slow.js></script>";
// A speculative script request does not prove parser EOF. Arm the
// callback at interactive so document.open() runs during the intended
// defer wait, outside the parser's script execution scope.
let html = r#"<!doctype html><title>before-open</title>
<script>
document.addEventListener('readystatechange', () => {
if (document.readyState === 'interactive') {
fetch('/arm').then(() => {
document.open();
document.write('<title>after-open</title><p>replacement</p>');
document.close();
});
}
}, {once: true});
</script><script defer src=/slow.js></script>"#;
let mut observed =
begin_document_html(&mut socket, &session.session_id, &fixture, html).await;
tokio::time::timeout(Duration::from_secs(10), fixture.requested.notified())