diff --git a/moli-renderer-v8/src/native_bridge/context_host/popups.rs b/moli-renderer-v8/src/native_bridge/context_host/popups.rs index 28433b30f96..1f8e0feb144 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/popups.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/popups.rs @@ -1145,7 +1145,7 @@ impl PageScriptHost { crate::dom_parser::parse_browsing_context_document_projection_from_source( scope, initial_url.clone(), - "", + "", Some("text/html"), None, crate::parser::HtmlParser::with_scripting_enabled( @@ -2640,6 +2640,9 @@ impl PageScriptHost { ) { clear_lightweight_popup_window_document_event_state(scope, window); self.clear_lightweight_popup_document_projection(popup_id); + // Blank navigations bypass the fetched-response path. Publish their + // committed Location before linking the new Document to that object. + sync_window_location_runtime_state(scope, window, document_url.as_str()); let base_url = self .lightweight_popup_base_url(scope, popup_id) .unwrap_or_else(|| document_url.clone()); @@ -2654,7 +2657,7 @@ impl PageScriptHost { crate::dom_parser::parse_browsing_context_document_projection_from_source( scope, document_url, - "", + "", Some("text/html"), None, crate::parser::HtmlParser::with_scripting_enabled( diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/popup_live_document_stream.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/popup_live_document_stream.rs index 4c9d45844c2..fc18c4979fb 100644 --- a/moli-renderer-v8/src/script_vm/tests/browser_api/popup_live_document_stream.rs +++ b/moli-renderer-v8/src/script_vm/tests/browser_api/popup_live_document_stream.rs @@ -9,6 +9,7 @@ fn popup_live_document_open_replaces_the_tree_and_close_finishes_the_parser() { (() => { const w = open(), d = w.document, root = d.documentElement, old = [...d.childNodes]; try { + const initial = [d.compatMode, d.doctype, old.map(n => n.nodeName)]; const observer = new MutationObserver(() => {}); observer.observe(d, {childList:true}); const same = d.open() === d; @@ -18,7 +19,7 @@ fn popup_live_document_open_replaces_the_tree_and_close_finishes_the_parser() { removals.length, removals[0].removedNodes.length === old.length]; d.close(); const closed = [d.readyState, d.body.localName, d.body.textContent]; - return JSON.stringify({opened, closed}); + return JSON.stringify({initial, opened, closed}); } finally { w.close(); } })() "#, @@ -26,10 +27,40 @@ fn popup_live_document_open_replaces_the_tree_and_close_finishes_the_parser() { .unwrap(); assert_eq!( result, - r#"{"opened":[true,true,0,null,null,null,false,"loading","CSS1Compat",1,true],"closed":["complete","body",""]}"# + r#"{"initial":["BackCompat",null,["HTML"]],"opened":[true,true,0,null,null,null,false,"loading","CSS1Compat",1,true],"closed":["complete","body",""]}"# ); } +#[test] +fn popup_blank_navigation_restores_quirks_mode_without_a_doctype() { + let mut vm = new_storage_test_vm("https://popup-blank-mode.test/"); + assert_eq!( + vm.eval( + r#" +document.open(); +document.write('standards opener'); +document.close(); +globalThis.modePopup = open('about:blank', 'mode-popup'); +globalThis.oldModeDocument = modePopup.document; +oldModeDocument.open(); +oldModeDocument.write('standards popup'); +oldModeDocument.close(); +oldModeDocument.compatMode; +"#, + ) + .unwrap(), + "CSS1Compat" + ); + vm.eval("open('about:blank?replacement', 'mode-popup')") + .unwrap(); + assert_eq!( + vm.eval("JSON.stringify([modePopup.document !== oldModeDocument, modePopup.document.URL, modePopup.document.compatMode, modePopup.document.doctype, Array.from(modePopup.document.childNodes, n => n.nodeName), modePopup.document.body.textContent, document.compatMode])") + .unwrap(), + r#"[true,"about:blank?replacement","BackCompat",null,["HTML"],"","CSS1Compat"]"# + ); + vm.eval("modePopup.close()").unwrap(); +} + #[test] fn popup_live_document_write_preserves_split_tokens_and_native_node_identity() { let mut vm = new_storage_test_vm("https://popup-live-token.test/"); diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/document_write.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/document_write.rs index ed2726894f7..3b214f44530 100644 --- a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/document_write.rs +++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/document_write.rs @@ -394,6 +394,101 @@ fn document_open_resets_compat_mode_and_parser_updates_it_incrementally() { ); } +#[test] +fn child_document_open_resets_compat_mode_before_doctype_or_eof() { + let mut vm = new_parsed_test_vm( + "https://child-document-open-quirks.test/", + "parent", + ); + let result = vm + .eval( + r#" +(() => { + const f = document.body.appendChild(document.createElement('iframe')); + const d = f.contentDocument; + d.open(); + d.write('initial quirks document'); + d.close(); + const rows = []; + for (const chunks of [ + [], + [''], + [''], + ['', 'quirks'], + [''] + ]) { + const modes = [d.compatMode]; + d.open(); + modes.push(d.compatMode); + for (const chunk of chunks) { + d.write(chunk); + modes.push(d.compatMode); + } + d.close(); + modes.push(d.compatMode); + rows.push(modes.join('|')); + } + f.remove(); + return rows.join('\n'); +})() +"#, + ) + .unwrap(); + assert_eq!( + result, + [ + "BackCompat|CSS1Compat|BackCompat", + "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat|BackCompat|BackCompat", + "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat|CSS1Compat", + "CSS1Compat|CSS1Compat|CSS1Compat|BackCompat|BackCompat", + "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat", + ] + .join("\n") + ); + assert_eq!(vm.eval("document.compatMode").unwrap(), "CSS1Compat"); +} + +#[test] +fn child_document_open_initializes_native_no_quirks_mode() { + for open in ["d.open()", "d.write('quirks parent", + ); + vm.eval(&format!( + r#" +const f = document.body.appendChild(document.createElement('iframe')); +f.id = 'mode-frame'; +const d = f.contentDocument; +{open}; +const html = d.appendChild(d.createElement('html')); +html.appendChild(d.createElement('body')); +d.body.innerHTML = '

child

'; +"# + )) + .unwrap(); + assert_eq!( + vm.eval("JSON.stringify([d.compatMode, d.querySelectorAll('.upper').length, document.compatMode])") + .unwrap(), + r#"["CSS1Compat",0,"BackCompat"]"#, + "{open}" + ); + let host = vm._context_host.borrow(); + let frame = host.dom_host().element_handle_by_id("mode-frame").unwrap(); + let document = host.child_browsing_context_document_handle(frame).unwrap(); + assert_eq!( + host.dom_host() + .node(document) + .unwrap() + .as_document() + .unwrap() + .quirks_mode(), + selectors::matching::QuirksMode::NoQuirks, + "{open}: native mode must not be limited-quirks" + ); + } +} + // Ported from WPT opening-the-input-stream/custom-element.window.js. The // dynamic-markup counter is a parser construction guard, not a blanket custom // element construction guard. @@ -645,98 +740,3 @@ fn inline_style_has_not_any_link_invalidates_on_plain_child_insertion() { assert_eq!(result, "rgb(0, 0, 255)|rgb(128, 128, 128)|rgb(0, 0, 255)"); } - -#[test] -fn child_document_open_resets_compat_mode_before_doctype_or_eof() { - let mut vm = new_parsed_test_vm( - "https://child-document-open-quirks.test/", - "parent", - ); - let result = vm - .eval( - r#" -(() => { - const f = document.body.appendChild(document.createElement('iframe')); - const d = f.contentDocument; - d.open(); - d.write('initial quirks document'); - d.close(); - const rows = []; - for (const chunks of [ - [], - [''], - [''], - ['', 'quirks'], - [''] - ]) { - const modes = [d.compatMode]; - d.open(); - modes.push(d.compatMode); - for (const chunk of chunks) { - d.write(chunk); - modes.push(d.compatMode); - } - d.close(); - modes.push(d.compatMode); - rows.push(modes.join('|')); - } - f.remove(); - return rows.join('\n'); -})() -"#, - ) - .unwrap(); - assert_eq!( - result, - [ - "BackCompat|CSS1Compat|BackCompat", - "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat|BackCompat|BackCompat", - "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat|CSS1Compat", - "CSS1Compat|CSS1Compat|CSS1Compat|BackCompat|BackCompat", - "BackCompat|CSS1Compat|CSS1Compat|CSS1Compat", - ] - .join("\n") - ); - assert_eq!(vm.eval("document.compatMode").unwrap(), "CSS1Compat"); -} - -#[test] -fn child_document_open_initializes_native_no_quirks_mode() { - for open in ["d.open()", "d.write('quirks parent", - ); - vm.eval(&format!( - r#" -const f = document.body.appendChild(document.createElement('iframe')); -f.id = 'mode-frame'; -const d = f.contentDocument; -{open}; -const html = d.appendChild(d.createElement('html')); -html.appendChild(d.createElement('body')); -d.body.innerHTML = '

child

'; -"# - )) - .unwrap(); - assert_eq!( - vm.eval("JSON.stringify([d.compatMode, d.querySelectorAll('.upper').length, document.compatMode])") - .unwrap(), - r#"["CSS1Compat",0,"BackCompat"]"#, - "{open}" - ); - let host = vm._context_host.borrow(); - let frame = host.dom_host().element_handle_by_id("mode-frame").unwrap(); - let document = host.child_browsing_context_document_handle(frame).unwrap(); - assert_eq!( - host.dom_host() - .node(document) - .unwrap() - .as_document() - .unwrap() - .quirks_mode(), - selectors::matching::QuirksMode::NoQuirks, - "{open}: native mode must not be limited-quirks" - ); - } -}