refactor(forms): finish native binding navigation migration

Remove synchronous child request entry points left unused after native form
bindings replaced the detached callbacks. Keep the shared planned-navigation
path and remove its stale event re-export.

Load a same-origin popup document before testing Navigation API cancellation,
then drive each form-navigation task. Preserve asynchronous delivery, source
identity, POST data, cancellation, and closed-document submission assertions.

Validation: cargo fmt --all; workspace all-target/all-feature clippy with
warnings denied; zero-retry nextest (20,653 passed, 16 skipped). DOM WPT
544/544, registry WPT 2,351/2,351; HTTP/HTTPS replacement fixture 772/772.
This commit is contained in:
ldm0
2026-11-24 14:36:21 +08:00
parent bf64fadeea
commit 58223620ff
4 changed files with 72 additions and 83 deletions
@@ -235,6 +235,7 @@ pub(crate) use navigation_cancellation::{
NavigationCancellationReason, inform_about_canceled_navigation_for_window,
stop_navigation_for_window_and_descendants,
};
pub(crate) use navigation_events::dispatch_cross_document_navigation_navigate_event_for_window_with_type_and_form_data;
pub(crate) use navigation_events::{
construct_original_hash_change_event, dispatch_beforeunload_for_runtime_owner,
dispatch_pagehide_for_runtime_owner, dispatch_unload_for_runtime_owner,
@@ -113,29 +113,6 @@ impl PageScriptHost {
self.remember_child_navigation_download_policy(handle, download_policy, queued)
}
pub(crate) fn navigate_child_browsing_context_with_request(
&mut self,
scope: &mut v8::PinScope<'_, '_>,
handle: DomHandle,
request: ChildBrowsingContextNavigationRequest,
) -> bool {
let download_policy = self.capture_child_navigation_download_policy(scope, handle);
if !self.child_browsing_contexts.contains_key(&handle) {
return false;
}
let replace_initial_empty_document = self.child_current_document_is_initial_empty(handle);
if let Some(entry) = self.child_browsing_contexts.get_mut(&handle) {
if replace_initial_empty_document {
entry.replace_navigation_in_entry_seed(&request.url);
} else {
entry.apply_navigation_to_entry_seed(&request.url);
}
}
self.sync_existing_child_browsing_context_runtime_surface_from_seed(scope, handle);
let queued = self.queue_child_browsing_context_navigation_request(handle, request);
self.remember_child_navigation_download_policy(handle, download_policy, queued)
}
pub(crate) fn queue_child_browsing_context_navigation_from_existing_seed(
&mut self,
scope: &mut v8::PinScope<'_, '_>,
@@ -1,6 +1,5 @@
use super::super::{
ChildBrowsingContextBootstrap, ChildBrowsingContextNavigationRequest,
ChildBrowsingContextSnapshot, PageScriptHost,
ChildBrowsingContextBootstrap, ChildBrowsingContextSnapshot, PageScriptHost,
child_documents::{ChildDocumentCommitResult, ChildDocumentCommitState},
};
use crate::native_bridge::context_host::child_documents::ChildDocumentNavigationInitiator;
@@ -265,35 +264,6 @@ impl PageScriptHost {
self.queue_child_browsing_context_navigation_commit(handle)
}
pub(in crate::native_bridge::context_host) fn queue_child_browsing_context_navigation_request(
&mut self,
handle: DomHandle,
request: ChildBrowsingContextNavigationRequest,
) -> bool {
if !self.child_browsing_contexts.contains_key(&handle) {
return false;
}
self.reject_replaced_service_worker_child_client_navigation(
handle,
"The navigation was canceled.".to_owned(),
);
let document_url = request.url.clone();
if self
.set_child_browsing_context_pending_navigation(
handle,
ChildBrowsingContextBootstrap::Request(request),
None,
true,
None,
)
.is_none()
{
return false;
}
self.register_reserved_service_worker_child_client_for_navigation(handle, &document_url);
self.queue_child_browsing_context_navigation_commit(handle)
}
pub(in crate::native_bridge::context_host) fn commit_child_browsing_context_attribute_bootstrap_if_needed(
&mut self,
scope: &mut v8::PinScope<'_, '_>,
@@ -209,16 +209,29 @@ async fn assert_lightweight_popup_form_submission(method: &str) {
}
}
#[tokio::test(flavor = "current_thread")]
#[tokio::test]
async fn form_wrappers_popup_submission_respects_cancellation_and_closed_documents() {
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).unwrap();
let mut vm = new_storage_page_task_executor_test_vm_with_loader(
"https://form-popup-cancellation.test/",
let server = StaticHttpServer::spawn(1).await;
let loader = static_http_loader([]);
let opener_url = server.base_url().join("opener.html").unwrap();
let mut vm = new_storage_page_task_executor_test_vm_with_loader(opener_url.as_str(), &loader);
vm.eval("globalThis.popup = open('/initial');").unwrap();
// Navigation API entries and events are disabled on initial about:blank.
advance_page_task_executor_until_eval_equals(
&mut vm,
&loader,
"String(popup.document.URL.endsWith('/initial') && popup.document.readyState === 'complete')",
"true",
"popup cancellation target must have a committed document",
)
.await;
assert_eq!(
vm.eval("popup.navigation.currentEntry !== null").unwrap(),
"true"
);
vm.eval(r#"(() => {
globalThis.popup = open();
vm.eval(r#"
const original = popup.document;
const originalURL = popup.location.href;
const form = original.body.appendChild(original.createElement('form'));
form.action = '/submit';
form.innerHTML = '<input name="field" value="data">';
@@ -227,36 +240,64 @@ async fn form_wrappers_popup_submission_respects_cancellation_and_closed_documen
events.push([event.sourceElement === form, event.formData && event.formData.get('field')]);
event.preventDefault();
});
for (const method of ['get', 'post']) {
form.method = method;
HTMLFormElement.prototype.submit.call(form);
if (popup.document !== original || popup.location.href !== 'about:blank') throw Error('canceled navigation');
}
globalThis.__submitFromClosedPopup = () => {
for (const method of ['get', 'post']) {
form.method = method;
HTMLFormElement.prototype.submit.call(form);
}
return JSON.stringify(events);
};
popup.close();
})()"#).unwrap();
advance_page_task_executor_until_eval_equals(
&mut vm,
&loader,
"String(popup.closed && popup.opener === null)",
"true",
"popup Document retirement",
"#).unwrap();
let mut previous_events = "[]";
for (method, expected_events) in [
("get", "[[true,null]]"),
("post", "[[true,null],[true,\"data\"]]"),
] {
vm.eval(&format!(
"form.method = '{method}'; HTMLFormElement.prototype.submit.call(form);"
))
.unwrap();
assert_eq!(
vm.eval("JSON.stringify(events)").unwrap(),
previous_events,
"navigate waits for the form's DOM-manipulation task"
);
assert!(
vm.run_one_dom_manipulation_body_for_test(
crate::runtime::PageDomManipulationTestFamily::FormNavigation,
)
.await
.unwrap()
);
assert_eq!(vm.eval("JSON.stringify(events)").unwrap(), expected_events);
assert_eq!(
vm.eval("popup.document === original && popup.location.href === originalURL")
.unwrap(),
"true"
);
assert!(vm.take_pending_location_navigation_with_seed().is_none());
assert!(
!vm._context_host
.borrow()
.has_pending_lightweight_popup_document_loads()
);
previous_events = expected_events;
}
vm.eval(
r#"
popup.close();
for (const method of ['get', 'post']) {
form.method = method;
HTMLFormElement.prototype.submit.call(form);
}
"#,
)
.await;
.unwrap();
assert_eq!(
vm.eval("__submitFromClosedPopup()").unwrap(),
r#"[[true,null],[true,"data"]]"#
vm.eval("JSON.stringify(events)").unwrap(),
"[[true,null],[true,\"data\"]]"
);
assert!(!vm.has_ready_dom_manipulation_family_for_test(
crate::runtime::PageDomManipulationTestFamily::FormNavigation,
));
assert!(vm.take_pending_location_navigation_with_seed().is_none());
assert!(
!vm._context_host
.borrow()
.has_pending_lightweight_popup_document_loads()
);
assert_eq!(server.finish_targets().await, vec!["/initial"]);
}