diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rs index 263eb601bea..ed203028ded 100644 --- a/moli-renderer-v8/src/context_bootstrap.rs +++ b/moli-renderer-v8/src/context_bootstrap.rs @@ -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, diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs index 208e4969ec3..6868cef0733 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs @@ -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<'_, '_>, diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs index 3a2f3073b42..3965b23152a 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs @@ -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<'_, '_>, diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs index 5d366cfcdb7..5dbd5e5eefe 100644 --- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs +++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs @@ -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 = ''; @@ -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"]); }