Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(fetch): separate request ownership from API base URLs

ldm043c72601f3a4
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rs
index 29f5ba3c0..463856acd 100644
--- a/moli-renderer-v8/src/context_bootstrap.rs
+++ b/moli-renderer-v8/src/context_bootstrap.rs
@@ -503,8 +503,8 @@ pub(crate) fn current_child_frame_id_for_runtime_scope(
let owner = self::navigation_window::runtime_window_owner(scope, global);
let handle =
self::navigation_window::child_browsing_context_handle_for_runtime_owner(scope, owner)?;
- host.child_browsing_context_request_scope(handle)
- .map(|(frame_id, _)| frame_id)
+ host.frame_owner_frame_id_for_child_handle(handle)
+ .map(|frame_id| frame_id.0)
}
pub(crate) fn current_child_browsing_context_handle_for_runtime_scope(
diff --git a/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs b/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs
index cd2d6866c..b2899208e 100644
--- a/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs
+++ b/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs
@@ -413,10 +413,7 @@ fn shared_worker_constructor_context(
let host = unsafe { &mut *host_ptr };
let child_handle = current_child_context_handle(scope)
.or_else(|| child_context_handle_from_object_creation_context(scope, receiver))
- .or_else(|| {
- host.active_child_subresource_request_scope()
- .map(|(handle, _, _)| handle)
- });
+ .or_else(|| host.active_child_subresource_request_handle());
let active_popup_referrer_policy = child_handle
.is_none()
.then(|| {
diff --git a/moli-renderer-v8/src/context_bootstrap/websocket/realm.rs b/moli-renderer-v8/src/context_bootstrap/websocket/realm.rs
index 237b28acb..49b839df1 100644
--- a/moli-renderer-v8/src/context_bootstrap/websocket/realm.rs
+++ b/moli-renderer-v8/src/context_bootstrap/websocket/realm.rs
@@ -26,8 +26,9 @@ pub(super) fn effective_websocket_document_scope(
let binding = host.current_runtime_window_execution_context_binding(scope)?;
match binding.dispatch_scope() {
crate::native_bridge::OwnerDispatchScope::Child(handle) => {
- let (frame_id, document_url) = host.child_browsing_context_request_scope(handle)?;
- Some((binding, Some(frame_id), document_url))
+ let frame_id = host.frame_owner_frame_id_for_child_handle(handle)?.0;
+ let base_url = host.child_browsing_context_base_url(handle)?;
+ Some((binding, Some(frame_id), base_url))
}
crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id) => Some((
binding,
diff --git a/moli-renderer-v8/src/context_bootstrap/worker_host/constructor.rs b/moli-renderer-v8/src/context_bootstrap/worker_host/constructor.rs
index 81e5f9ca0..14477d208 100644
--- a/moli-renderer-v8/src/context_bootstrap/worker_host/constructor.rs
+++ b/moli-renderer-v8/src/context_bootstrap/worker_host/constructor.rs
@@ -155,10 +155,7 @@ pub(in crate::context_bootstrap) fn worker_constructor_callback<'s>(
let host = unsafe { &mut *host_ptr };
let child_handle = current_child_context_handle(scope)
.or_else(|| child_context_handle_from_object_creation_context(scope, worker))
- .or_else(|| {
- host.active_child_subresource_request_scope()
- .map(|(handle, _, _)| handle)
- })
+ .or_else(|| host.active_child_subresource_request_handle())
.or_else(|| crate::native_bridge::active_child_window_handle(scope));
let active_popup_base_url = child_handle
.is_none()
@@ -819,8 +816,8 @@ pub(in crate::context_bootstrap) fn document_query_encoding_override(
pub(in crate::context_bootstrap) fn worker_constructor_base_url(
host: &crate::native_bridge::JsContextHost,
) -> Url {
- host.active_child_subresource_request_scope()
- .map(|(_, _, document_url)| document_url)
+ host.active_child_subresource_request_handle()
+ .and_then(|handle| host.child_browsing_context_base_url(handle))
.unwrap_or_else(|| {
host.dom_host()
.document_base_url()
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames/request_scope.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames/request_scope.rs
index db0c9e488..a44c17245 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames/request_scope.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames/request_scope.rs
@@ -142,21 +142,10 @@ impl JsContextHost {
Some(self.document_url().clone())
}
- pub(crate) fn child_browsing_context_request_scope(
- &self,
- handle: DomHandle,
- ) -> Option<(String, Url)> {
- let entry = self.child_browsing_contexts.get(&handle)?;
- let document_url = self.child_browsing_context_base_url(handle)?;
- Some((entry.frame_id().to_owned(), document_url))
- }
-
- pub(crate) fn active_child_subresource_request_scope(
- &self,
- ) -> Option<(DomHandle, String, Url)> {
+ pub(crate) fn active_child_subresource_request_handle(&self) -> Option<DomHandle> {
let handle = *self.active_child_subresource_request_scopes.last()?;
- let (frame_id, document_url) = self.child_browsing_context_request_scope(handle)?;
- Some((handle, frame_id, document_url))
+ self.frame_owner_frame_id_for_child_handle(handle)?;
+ Some(handle)
}
pub(crate) fn child_browsing_context_base_url(&self, handle: DomHandle) -> Option<Url> {
diff --git a/moli-renderer-v8/src/native_bridge/context_host/window_document_tasks.rs b/moli-renderer-v8/src/native_bridge/context_host/window_document_tasks.rs
index 61e49362f..98f4e8608 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/window_document_tasks.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/window_document_tasks.rs
@@ -183,7 +183,7 @@ impl JsContextHost {
RendererWindowDocumentSource::RootFrame
}
(WindowDocumentOwner::Frame(owner), OwnerDispatchScope::Child(handle)) => {
- let (frame_id, _) = self.child_browsing_context_request_scope(handle)?;
+ let frame_id = self.frame_owner_frame_id_for_child_handle(handle)?.0;
RendererWindowDocumentSource::ChildFrame {
frame_id,
local_window_id: owner.local_window_id.0,
diff --git a/moli-renderer-v8/src/network_host.rs b/moli-renderer-v8/src/network_host.rs
index 511c131e6..f2b3d67d6 100644
--- a/moli-renderer-v8/src/network_host.rs
+++ b/moli-renderer-v8/src/network_host.rs
@@ -136,12 +136,14 @@ pub(crate) use self::request::{
pub(crate) use self::request::{
parse_fetch_init, parse_request_redirect_mode_label, request_object_credentials_mode,
};
-pub(crate) use self::request_scope::effective_subresource_policy_context;
pub(in crate::network_host) use self::request_scope::{
XHR_CHILD_CONTEXT_HANDLE_SLOT, active_subresource_network_partition_key,
- effective_subresource_referrer_policy, effective_subresource_request_scope,
+ effective_subresource_referrer_policy, effective_subresource_request_owner,
observe_subresource_request_cookie_report,
};
+pub(crate) use self::request_scope::{
+ effective_subresource_policy_context, subresource_api_base_url,
+};
#[cfg(test)]
pub(crate) use self::response::materialize_response_object;
pub(crate) use self::response::{
diff --git a/moli-renderer-v8/src/network_host/request/input.rs b/moli-renderer-v8/src/network_host/request/input.rs
index 0ff261d34..a5bc9d807 100644
--- a/moli-renderer-v8/src/network_host/request/input.rs
+++ b/moli-renderer-v8/src/network_host/request/input.rs
@@ -351,21 +351,15 @@ pub(crate) fn try_resolve_request_constructor_url_for_scope(
.map_err(RequestUrlError::from);
}
if let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) {
- let host = unsafe { &mut *host_ptr };
- let document_url = child_handle
- .and_then(|handle| {
- host.child_browsing_context_request_scope(handle)
- .map(|(_, url)| url)
- })
+ let host = unsafe { &*host_ptr };
+ let api_base_url = child_handle
+ .and_then(|handle| host.child_browsing_context_base_url(handle))
.unwrap_or_else(|| {
- let (_, base_url, owner) = effective_subresource_request_scope(scope, host, None);
- if matches!(owner, crate::native_bridge::OwnerDispatchScope::Top) {
- host.document_base_url_for_handle(host.document_handle())
- } else {
- base_url
- }
+ let owner = effective_subresource_request_owner(scope, host);
+ subresource_api_base_url(scope, host, owner)
+ .unwrap_or_else(|| host.document_url().clone())
});
- resolve_context_url(&document_url, input, None)
+ resolve_context_url(&api_base_url, input, None)
.map(|url| url.to_string())
.map_err(RequestUrlError::from)
} else if let Some(worker_url) = crate::context_bootstrap::current_worker_script_url(scope) {
@@ -388,22 +382,32 @@ pub(super) fn normalize_request_referrer(scope: &mut v8::PinScope<'_, '_>, input
}
let resolved = resolve_request_constructor_url(scope, input);
- let Some(context_url) = current_request_context_url(scope) else {
+ let Some(context_origin) = current_request_context_origin(scope) else {
return resolved;
};
- if moli_url::parsed_same_origin(&resolved, &context_url) {
+ if moli_url::parsed_same_origin(&resolved, &context_origin) {
resolved
} else {
"about:client".to_owned()
}
}
-fn current_request_context_url(scope: &mut v8::PinScope<'_, '_>) -> Option<String> {
+fn current_request_context_origin(scope: &mut v8::PinScope<'_, '_>) -> Option<String> {
if let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) {
- let host = unsafe { &mut *host_ptr };
- let (_, document_url, _) = effective_subresource_request_scope(scope, host, None);
- Some(document_url.to_string())
+ let host = unsafe { &*host_ptr };
+ match effective_subresource_request_owner(scope, host) {
+ crate::native_bridge::OwnerDispatchScope::Top => {
+ Some(moli_url::origin_ascii_serialization(host.document_url()))
+ }
+ crate::native_bridge::OwnerDispatchScope::Child(handle) => {
+ host.child_browsing_context_target_origin(handle)
+ }
+ crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id) => {
+ host.lightweight_popup_origin(popup_id)
+ }
+ }
} else {
- crate::context_bootstrap::current_worker_script_url(scope).map(|url| url.to_string())
+ crate::context_bootstrap::current_worker_script_url(scope)
+ .map(|url| moli_url::origin_ascii_serialization(&url))
}
}
diff --git a/moli-renderer-v8/src/network_host/request_scope.rs b/moli-renderer-v8/src/network_host/request_scope.rs
index 450129391..047706d07 100644
--- a/moli-renderer-v8/src/network_host/request_scope.rs
+++ b/moli-renderer-v8/src/network_host/request_scope.rs
@@ -1,5 +1,4 @@
use super::*;
-use crate::util::get_private_value;
pub(in crate::network_host) use crate::context_bootstrap::CHILD_BROWSING_CONTEXT_HANDLE_SLOT as XHR_CHILD_CONTEXT_HANDLE_SLOT;
@@ -70,77 +69,45 @@ pub(crate) fn effective_subresource_policy_context(
}
}
-fn child_browsing_context_handle_from_object(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
-) -> Option<crate::document_runtime::DomHandle> {
- let object = local_object_in_scope(scope, object);
- get_private_value(scope, object, XHR_CHILD_CONTEXT_HANDLE_SLOT)
- .and_then(|value| value.number_value(scope))
- .filter(|value| value.is_finite() && *value >= 0.0 && value.fract() == 0.0)
- .map(|value| crate::document_runtime::DomHandle::new(value as usize))
-}
-
-fn lightweight_popup_id_from_object(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
-) -> Option<u64> {
- let object = local_object_in_scope(scope, object);
- crate::native_bridge::lightweight_popup_id_from_window(scope, object)
-}
-
-fn local_object_in_scope<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- object: v8::Local<'_, v8::Object>,
-) -> v8::Local<'s, v8::Object> {
- let global = v8::Global::new(scope, object);
- v8::Local::new(scope, global)
-}
-
-pub(in crate::network_host) fn effective_subresource_request_scope(
+/// Select request attribution without using a document's mutable base URL.
+pub(in crate::network_host) fn effective_subresource_request_owner(
scope: &mut v8::PinScope<'_, '_>,
host: &JsContextHost,
- receiver: Option<v8::Local<'_, v8::Object>>,
-) -> (
- Option<String>,
- url::Url,
- crate::native_bridge::OwnerDispatchScope,
-) {
- let handle = receiver
- .and_then(|receiver| child_browsing_context_handle_from_object(scope, receiver))
- .or_else(|| {
- host.active_child_subresource_request_scope()
- .map(|(handle, _, _)| handle)
- })
- .or_else(|| {
- crate::context_bootstrap::current_child_browsing_context_handle_for_runtime_scope(scope)
- });
+) -> crate::native_bridge::OwnerDispatchScope {
+ let handle = host.active_child_subresource_request_handle().or_else(|| {
+ crate::context_bootstrap::current_child_browsing_context_handle_for_runtime_scope(scope)
+ });
if let Some(handle) = handle
- && let Some((frame_id, document_url)) = host.child_browsing_context_request_scope(handle)
+ && host.frame_owner_frame_id_for_child_handle(handle).is_some()
{
- return (
- Some(frame_id),
- document_url,
- crate::native_bridge::OwnerDispatchScope::Child(handle),
- );
+ return crate::native_bridge::OwnerDispatchScope::Child(handle);
}
- let popup_id = receiver
- .and_then(|receiver| lightweight_popup_id_from_object(scope, receiver))
- .or_else(|| crate::native_bridge::active_lightweight_popup_id(scope));
- if let Some(popup_id) = popup_id
- && let Some(document_url) = host.lightweight_popup_request_base_url(scope, popup_id)
+ if let Some(popup_id) = crate::native_bridge::active_lightweight_popup_id(scope)
+ && host.lightweight_popup_document_url(popup_id).is_some()
{
- return (
- None,
- document_url,
- crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id),
- );
+ return crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id);
+ }
+ crate::native_bridge::OwnerDispatchScope::Top
+}
+
+/// The API base URL resolves relative input; it is neither the document URL
+/// nor the origin used for request security checks. Read it live for every call.
+pub(crate) fn subresource_api_base_url(
+ scope: &mut v8::PinScope<'_, '_>,
+ host: &JsContextHost,
+ owner: crate::native_bridge::OwnerDispatchScope,
+) -> Option<url::Url> {
+ match owner {
+ crate::native_bridge::OwnerDispatchScope::Top => {
+ Some(host.document_base_url_for_handle(host.document_handle()))
+ }
+ crate::native_bridge::OwnerDispatchScope::Child(handle) => {
+ host.child_browsing_context_base_url(handle)
+ }
+ crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id) => {
+ host.lightweight_popup_request_base_url(scope, popup_id)
+ }
}
- (
- None,
- host.document_url().clone(),
- crate::native_bridge::OwnerDispatchScope::Top,
- )
}
pub(in crate::network_host) fn effective_subresource_referrer_policy(
diff --git a/moli-renderer-v8/src/network_host/xhr/bindings/open.rs b/moli-renderer-v8/src/network_host/xhr/bindings/open.rs
index 00f9f526f..a8c88a2ca 100644
--- a/moli-renderer-v8/src/network_host/xhr/bindings/open.rs
+++ b/moli-renderer-v8/src/network_host/xhr/bindings/open.rs
@@ -129,17 +129,7 @@ fn xhr_open_request_url(
);
return None;
};
- match execution_context.dispatch_scope() {
- crate::native_bridge::OwnerDispatchScope::Top => {
- Some(host.document_base_url_for_handle(host.document_handle()))
- }
- crate::native_bridge::OwnerDispatchScope::Child(handle) => {
- host.child_browsing_context_base_url(handle)
- }
- crate::native_bridge::OwnerDispatchScope::LightweightPopup(popup_id) => {
- host.lightweight_popup_request_base_url(scope, popup_id)
- }
- }
+ subresource_api_base_url(scope, host, execution_context.dispatch_scope())
};
let Some(base_url) = base_url else {
xhr_open_throw_invalid_state(
diff --git a/moli-renderer-v8/src/script_vm/child_frame_realm_materialization.rs b/moli-renderer-v8/src/script_vm/child_frame_realm_materialization.rs
index a994b2fee..3f038e4fe 100644
--- a/moli-renderer-v8/src/script_vm/child_frame_realm_materialization.rs
+++ b/moli-renderer-v8/src/script_vm/child_frame_realm_materialization.rs
@@ -657,10 +657,9 @@ impl ScriptVm {
}
let frame_id = {
let host = self._context_host.borrow();
- let (frame_id, _) = host
- .child_browsing_context_request_scope(handle)
- .ok_or_else(|| anyhow::anyhow!("child frame realm scope is unavailable"))?;
- frame_id
+ host.frame_owner_frame_id_for_child_handle(handle)
+ .ok_or_else(|| anyhow::anyhow!("child frame realm scope is unavailable"))?
+ .0
};
let context = self.create_new_child_default_world(&frame_id, handle)?;
let execution_context_id = context.inspector_execution_context_id;
diff --git a/moli-renderer-v8/src/script_vm/subresource_fetch.rs b/moli-renderer-v8/src/script_vm/subresource_fetch.rs
index 0ee8a0942..76667852b 100644
--- a/moli-renderer-v8/src/script_vm/subresource_fetch.rs
+++ b/moli-renderer-v8/src/script_vm/subresource_fetch.rs
@@ -400,7 +400,7 @@ fn enter_subresource_owner_async_scope<'s>(
OwnerDispatchScope::Child(handle) => {
let child_context_exists = context_host
.borrow()
- .child_browsing_context_request_scope(handle)
+ .frame_owner_frame_id_for_child_handle(handle)
.is_some();
child_context_exists.then(|| {
context_host
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc/extracted/document_navigator.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc/extracted/document_navigator.rs
index 4d93354bd..a0b4f05b3 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc/extracted/document_navigator.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc/extracted/document_navigator.rs
@@ -381,3 +381,213 @@ fn request_relative_urls_follow_live_document_base_urls() {
assert_eq!(checks.len(), 16);
assert!(checks.iter().all(|check| *check), "{result}");
}
+
+fn install_request_base_parent_document(vm: &mut ScriptVm) {
+ vm.exec(
+ r#"
+const html = document.documentElement || document.appendChild(document.createElement('html'));
+const head = document.head || html.appendChild(document.createElement('head'));
+if (!document.body) html.appendChild(document.createElement('body'));
+const parentBase = head.appendChild(document.createElement('base'));
+parentBase.href = '/parent-base/';
+globalThis.requestBaseFrame = document.createElement('iframe');
+"#,
+ None,
+ )
+ .expect("parent document with its own base should be installed");
+}
+
+fn assert_request_urls_follow_live_child_base_urls(
+ vm: &mut ScriptVm,
+ document_url: &str,
+ fallback_base_url: &str,
+) {
+ let child_context_id = vm
+ .live_child_default_runtime_realm_inventory()
+ .into_iter()
+ .map(|realm| realm.context_id)
+ .next()
+ .expect("iframe should have its own realm");
+ let fallback_base_url = Url::parse(fallback_base_url).unwrap();
+ let parent_base_url = Url::parse(
+ &vm.eval("document.baseURI")
+ .expect("parent base should be readable"),
+ )
+ .unwrap();
+ let allowed_referrer = fallback_base_url.join("/allowed-referrer").unwrap();
+ let phases = [
+ (
+ Some("/initial/"),
+ fallback_base_url.join("/initial/").unwrap(),
+ ),
+ (
+ Some("../relative/"),
+ fallback_base_url.join("../relative/").unwrap(),
+ ),
+ (
+ Some("https://other-base.test/second/"),
+ Url::parse("https://other-base.test/second/").unwrap(),
+ ),
+ (None, fallback_base_url.clone()),
+ ];
+
+ for (href, expected_base_url) in phases {
+ let mutation = match href {
+ Some(href) => format!(
+ "const base = childDocument.querySelector('base') || \
+ childDocument.head.appendChild(childDocument.createElement('base')); \
+ base.href = {};",
+ serde_json::to_string(href).unwrap()
+ ),
+ None => "childDocument.querySelector('base').remove();".to_owned(),
+ };
+ vm.eval(&format!(
+ "(() => {{ const childDocument = requestBaseFrame.contentDocument; \
+ {mutation} }})()"
+ ))
+ .expect("child base mutation should evaluate");
+
+ let probe = format!(
+ r#"
+(() => {{
+ const child = CHILD_WINDOW;
+ return JSON.stringify({{
+ documentURL: child.document.URL,
+ baseURI: child.document.baseURI,
+ urls: ['item', '../item?q#f', '?q', '#f'].map(input => new child.Request(input).url),
+ absoluteURL: new child.Request('https://absolute.test/path').url,
+ allowedReferrer: new child.Request('item', {{referrer: {allowed_referrer}}}).referrer,
+ relativeReferrer: new child.Request('item', {{referrer: 'referrer'}}).referrer
+ }});
+}})()
+"#,
+ allowed_referrer = serde_json::to_string(allowed_referrer.as_str()).unwrap(),
+ );
+ let parent_result = vm
+ .eval(&probe.replace("CHILD_WINDOW", "requestBaseFrame.contentWindow"))
+ .expect("parent should construct a Request using the child constructor");
+ let child_result = vm
+ .eval_in_child_default_context(
+ child_context_id,
+ &probe.replace("CHILD_WINDOW", "globalThis"),
+ )
+ .expect("child realm should construct a Request using its own constructor");
+ let relative_referrer = expected_base_url.join("referrer").unwrap();
+ let expected_referrer = if relative_referrer.origin() == allowed_referrer.origin() {
+ relative_referrer.as_str()
+ } else {
+ "about:client"
+ };
+ let expected_urls = ["item", "../item?q#f", "?q", "#f"]
+ .map(|input| expected_base_url.join(input).unwrap().to_string());
+ let expected = serde_json::json!({
+ "documentURL": document_url,
+ "baseURI": expected_base_url.as_str(),
+ "urls": expected_urls,
+ "absoluteURL": "https://absolute.test/path",
+ "allowedReferrer": allowed_referrer.as_str(),
+ "relativeReferrer": expected_referrer,
+ });
+ for (realm, result) in [("parent", parent_result), ("child", child_result)] {
+ let actual: serde_json::Value = serde_json::from_str(&result).unwrap();
+ assert_eq!(
+ actual, expected,
+ "{realm} call after base mutation {href:?}"
+ );
+ }
+ assert_eq!(
+ vm.eval("new Request('parent-item').url")
+ .expect("parent Request should retain the parent base"),
+ parent_base_url.join("parent-item").unwrap().as_str(),
+ "child base mutation {href:?} must not affect the parent's API base"
+ );
+ }
+}
+
+#[test]
+fn request_relative_urls_follow_live_initial_about_blank_iframe_base_urls() {
+ let mut vm = new_storage_test_vm("https://request-base.test/dir/page.html");
+ install_request_base_parent_document(&mut vm);
+ vm.eval("document.body.appendChild(requestBaseFrame); requestBaseFrame.contentDocument")
+ .expect("initial about:blank iframe should be created");
+ vm.drain_pending_child_frame_work_for_test();
+ assert_request_urls_follow_live_child_base_urls(
+ &mut vm,
+ "about:blank",
+ "https://request-base.test/parent-base/",
+ );
+}
+
+#[test]
+fn request_relative_urls_follow_live_srcdoc_iframe_base_urls() {
+ let mut vm = new_storage_test_vm("https://request-base.test/dir/page.html");
+ install_request_base_parent_document(&mut vm);
+ vm.exec(
+ "requestBaseFrame.srcdoc = '<!doctype html><html><head></head><body></body></html>'; \
+ document.body.appendChild(requestBaseFrame);",
+ None,
+ )
+ .expect("srcdoc iframe should be created");
+ vm.drain_pending_child_frame_work_for_test();
+ assert_request_urls_follow_live_child_base_urls(
+ &mut vm,
+ "about:srcdoc",
+ "https://request-base.test/parent-base/",
+ );
+}
+
+#[tokio::test]
+async fn request_relative_urls_follow_live_http_iframe_base_urls() {
+ let (server_url, server) = spawn_lightweight_popup_response_html_server(
+ "Request iframe base server",
+ "Request iframe base",
+ "",
+ "<!doctype html><html><head></head><body></body></html>",
+ )
+ .await;
+ let server_url = Url::parse(&server_url).unwrap();
+ let parent_url = server_url.join("/parent/page.html").unwrap();
+ let child_url = server_url.join("/child/page.html").unwrap();
+ let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");
+ let mut vm = new_page_task_executor_test_vm_with_loader(parent_url.as_str(), &loader);
+ install_request_base_parent_document(&mut vm);
+ vm.exec(
+ &format!(
+ "requestBaseFrame.src = {}; document.body.appendChild(requestBaseFrame);",
+ serde_json::to_string(child_url.as_str()).unwrap()
+ ),
+ None,
+ )
+ .expect("HTTP iframe navigation should start");
+ tokio::time::timeout(std::time::Duration::from_secs(30), async {
+ for _ in 0..128 {
+ let current_url = vm
+ .eval("requestBaseFrame.contentDocument && requestBaseFrame.contentDocument.URL")
+ .expect("committed child URL should be readable");
+ if current_url == child_url.as_str()
+ && !vm.live_child_default_runtime_realm_inventory().is_empty()
+ {
+ return;
+ }
+ if !vm
+ .run_one_oldest_ready_page_task_executor_turn(&loader)
+ .await
+ .expect("iframe navigation Page task should execute")
+ {
+ assert!(
+ vm.wait_for_task_executor_work_arrival().await,
+ "iframe navigation should publish its next Page task"
+ );
+ }
+ }
+ panic!("HTTP iframe navigation exceeded its finite Page task budget");
+ })
+ .await
+ .expect("HTTP iframe should commit and materialize its child realm");
+ assert_request_urls_follow_live_child_base_urls(
+ &mut vm,
+ child_url.as_str(),
+ child_url.as_str(),
+ );
+ server.await.expect("iframe response server should finish");
+}