diff --git a/moli-renderer-v8/src/runtime/owner/owner_commands.rs b/moli-renderer-v8/src/runtime/owner/owner_commands.rs index 69003edff04..fe3f0b59e20 100644 --- a/moli-renderer-v8/src/runtime/owner/owner_commands.rs +++ b/moli-renderer-v8/src/runtime/owner/owner_commands.rs @@ -1,5 +1,14 @@ use super::*; +impl RendererOwnerLocalContext { + pub(in crate::runtime) fn layout_configuration(&self) -> moli_page_types::LayoutConfiguration { + self.owner_state + .layout_configuration + .lock() + .unwrap_or_default() + } +} + impl RendererOwnerHandle { /// Selects the immutable layout policy for this renderer owner. /// diff --git a/moli-renderer-v8/src/runtime/owner_local_store/auxiliary_pages.rs b/moli-renderer-v8/src/runtime/owner_local_store/auxiliary_pages.rs index cf7cd7eeed8..421fbfc3acf 100644 --- a/moli-renderer-v8/src/runtime/owner_local_store/auxiliary_pages.rs +++ b/moli-renderer-v8/src/runtime/owner_local_store/auxiliary_pages.rs @@ -34,11 +34,13 @@ impl RendererOwnerLocalStore { let RendererRelatedInitialEmptyPageInit { dom_host, loader, - env, + mut env, inherited_origin, inherited_security_token, opener, } = init; + // The initial Window can be used synchronously before protocol adoption. + env.layout_configuration = owner.layout_configuration(); ensure!( Some(pending.popup_id()) == env diff --git a/moli-renderer-v8/src/runtime/tests/auxiliary_pages.rs b/moli-renderer-v8/src/runtime/tests/auxiliary_pages.rs index 7a8d4b5bc2a..6053466d08e 100644 --- a/moli-renderer-v8/src/runtime/tests/auxiliary_pages.rs +++ b/moli-renderer-v8/src/runtime/tests/auxiliary_pages.rs @@ -4,6 +4,75 @@ mod split30_registry_native_owner; use super::*; use crate::RendererPopupActivationSource; +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn related_popup_initial_document_inherits_layout_configuration() { + use moli_page_types::LayoutPolicy; + + let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).unwrap(); + for (policy, scrollbars_hidden, client_size) in [ + (LayoutPolicy::Mock, false, [100, 20]), + (LayoutPolicy::OnDemand, false, [185, 85]), + (LayoutPolicy::OnDemand, true, [200, 100]), + (LayoutPolicy::Realtime, false, [185, 85]), + (LayoutPolicy::Realtime, true, [200, 100]), + ] { + let runtime = JsRuntime::initialize(); + runtime + .browser_context_runtime() + .delegate_auxiliary_document_responses_to_browser(); + runtime + .renderer_owner_handle() + .configure_layout(policy, scrollbars_hidden) + .unwrap(); + let mut page = create_test_html_page_with_navigation_dispatch( + &runtime, + &loader, + url::Url::parse("https://example.test/popup-layout").unwrap(), + "
opener", + RendererTopLevelNavigationDispatch::DelegateToBrowser, + ) + .await; + let (reply, _) = page + .run_async_command(RendererPageCommand::EvaluateExpression { + // Measure the initial document in the turn that opens it. + expression: r#"(() => { + const popup = window.open('about:blank', '_blank'); + try { + const scroller = popup.document.createElement('div'); + scroller.style.cssText = + 'position:absolute;left:0;top:0;width:200px;height:100px;overflow:scroll'; + scroller.innerHTML = ''; + popup.document.body.append(scroller); + const client = [scroller.clientWidth, scroller.clientHeight]; + scroller.style.width = '240px'; + return JSON.stringify([...client, scroller.getBoundingClientRect().width]); + } finally { + popup.close(); + } + })()"# + .to_owned(), + await_promise: false, + }) + .await + .expect("initial popup geometry should be readable"); + page.close_async().await.unwrap(); + + let result = renderer_json_value(reply).expect("popup measurement should return a value"); + let measured: [i64; 3] = serde_json::from_str(result.as_str().unwrap()).unwrap(); + assert_eq!( + measured[..2], + client_size, + "{policy:?}, scrollbars_hidden={scrollbars_hidden}" + ); + if policy == LayoutPolicy::Realtime { + assert_eq!( + measured[2], 240, + "Realtime popup must update the same-turn read" + ); + } + } +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn popup_request_context_keeps_the_accepted_source_url_and_referrer_policy() { let runtime = JsRuntime::initialize();