mirror of
https://github.com/lexmount/moli.git
synced 2026-11-22 00:02:21 +00:00
fix(cssom): publish parser style imports before scripts
This commit is contained in:
@@ -1279,18 +1279,32 @@ fn parser_owner_style_import_handoff_is_stylesheet_gated_on_live_page_vm() {
|
||||
input_closed: &state.input_closed,
|
||||
};
|
||||
|
||||
let outcome = driver
|
||||
.advance_parser_step(
|
||||
&mut page_vm,
|
||||
"<!doctype html><html><head><style>@import url('/style.css');</style><script>window.afterStyle = true;</script></head></html>",
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("parser step should complete");
|
||||
let outcome = driver
|
||||
.advance_parser_step(
|
||||
&mut page_vm,
|
||||
"<!doctype html><html><head><style id='blocking-style'>@import url('/style.css');</style><script>window.afterStyle = true;</script></head></html>",
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("parser step should complete");
|
||||
|
||||
assert!(
|
||||
matches!(outcome, ParserStepAdvanceOutcome::BlockedOnStylesheet(_)),
|
||||
"parser-created style import should gate parser-blocking script on live PageVm"
|
||||
);
|
||||
}));
|
||||
assert!(
|
||||
matches!(outcome, ParserStepAdvanceOutcome::BlockedOnStylesheet(_)),
|
||||
"parser-created style import should gate parser-blocking script on live PageVm"
|
||||
);
|
||||
let style = page_vm
|
||||
.vm()
|
||||
.document_runtime
|
||||
.dom_host()
|
||||
.element_handle_by_id("blocking-style")
|
||||
.expect("parser-created style owner");
|
||||
assert_eq!(
|
||||
page_vm
|
||||
.vm()
|
||||
.document_runtime
|
||||
.pending_style_import_binding_for_test(style),
|
||||
Some((1, true)),
|
||||
"the parser-discovered import must bind its live stylesheet root before the script gate is released"
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -625,6 +625,21 @@ impl DocumentRuntime {
|
||||
self.connected_style_load_is_queued(handle)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn pending_style_import_binding_for_test(
|
||||
&self,
|
||||
handle: DomHandle,
|
||||
) -> Option<(usize, bool)> {
|
||||
let operation = self
|
||||
.stylesheet_lifecycle
|
||||
.owner_states
|
||||
.pending_operation(handle)?;
|
||||
let ConnectedLoadParameters::StyleImports { roots, .. } = &operation.parameters else {
|
||||
return None;
|
||||
};
|
||||
Some((roots.len(), operation.blocking_operation.is_some()))
|
||||
}
|
||||
|
||||
pub(super) fn push_ready_connected_style_load(&mut self, ready: ReadyConnectedStyleLoad) {
|
||||
let producer = self
|
||||
.stylesheet_lifecycle
|
||||
@@ -716,11 +731,17 @@ impl DocumentRuntime {
|
||||
if !node.flags().parser_created() || !node.is_html_element_named("style") {
|
||||
return false;
|
||||
}
|
||||
document_owned_blocking_stylesheet_candidate_for_node(
|
||||
let Some(candidate) = document_owned_blocking_stylesheet_candidate_for_node(
|
||||
&self.dom_host,
|
||||
NodeId::new(handle.index()),
|
||||
)
|
||||
.is_some()
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
let signature = DocumentBlockingStylesheetSignature::from_candidate(&candidate);
|
||||
self.stylesheet_lifecycle
|
||||
.fetches
|
||||
.blocking_operation(NodeId::new(handle.index()), &signature)
|
||||
.is_none()
|
||||
}
|
||||
|
||||
pub(crate) fn has_pending_style_loads(&self) -> bool {
|
||||
|
||||
@@ -734,9 +734,7 @@ fn parser_created_style_import_urls(
|
||||
if !element.is_html_element("style") || !element.parser_blocking_eligible {
|
||||
return None;
|
||||
}
|
||||
if element.disabled
|
||||
|| !moli_web_mime::is_css_style_element_type_attribute(element.type_attr.as_deref())
|
||||
{
|
||||
if !moli_web_mime::is_css_style_element_type_attribute(element.type_attr.as_deref()) {
|
||||
return None;
|
||||
}
|
||||
let css_text = document.text_content(native_node_id)?;
|
||||
@@ -873,6 +871,37 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn style_disabled_content_attribute_does_not_suppress_parser_import_blocking() {
|
||||
let document_url = url::Url::parse("https://example.com/path/page.html").unwrap();
|
||||
let mut host = DomHost::from_dom(NativeDom::new_html(document_url));
|
||||
let style = host.create_parser_element_without_attributes(
|
||||
"style".to_owned(),
|
||||
"http://www.w3.org/1999/xhtml".to_owned(),
|
||||
None,
|
||||
);
|
||||
let text = host.create_text_node("@import url('theme.css');");
|
||||
assert!(host.set_attribute(style, "disabled", ""));
|
||||
assert!(host.append_child(style, text));
|
||||
assert!(host.append_child(host.document_handle(), style));
|
||||
|
||||
let candidate = document_owned_blocking_stylesheet_candidate_for_node(
|
||||
&host,
|
||||
moli_dom::NodeId::new(style.index()),
|
||||
)
|
||||
.expect("the unsupported style content attribute must not disable import blocking");
|
||||
let super::DocumentOwnedBlockingStylesheetCandidate::ParserCreatedStyleImport {
|
||||
urls, ..
|
||||
} = candidate
|
||||
else {
|
||||
panic!("expected a parser-created style import candidate");
|
||||
};
|
||||
assert_eq!(
|
||||
urls,
|
||||
[url::Url::parse("https://example.com/path/theme.css").unwrap()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_nonce_remains_part_of_stylesheet_request_identity() {
|
||||
let document_url = url::Url::parse("https://example.com/page.html").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user