From 0d7284dc341f4f852a6edf75811225b3055ec7f5 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 12 Jan 2023 20:05:58 +0100 Subject: [PATCH] Allow displaying content with "application/json" mime type For me this allows the WPT test performance-timeline/tentative/include-frames-one-remote-child.sub.html to match expected results. The wptserver is sending a 404 JSON response because the URL that the test requests is not found. --- components/script/dom/servoparser/mod.rs | 46 ++++++++++--------- .../schemeful-navigation.tentative.html.ini | 7 +-- .../schemeful-subresource.tentative.html.ini | 7 +-- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index 481b39e25d3..9967da64556 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -829,13 +829,24 @@ impl FetchResponseListener for ParserContext { } parser.document.set_csp_list(csp_list); - self.parser = Some(Trusted::new(&*parser)); - self.submit_resource_timing(); - match content_type { - Some(ref mime) if mime.type_() == mime::IMAGE => { + let content_type = match content_type { + Some(ref content_type) => content_type, + None => { + // No content-type header. + // Merge with #4212 when fixed. + return; + }, + }; + + match ( + content_type.type_(), + content_type.subtype(), + content_type.suffix(), + ) { + (mime::IMAGE, _, _) => { self.is_synthesized_document = true; let page = "".into(); parser.push_string_input_chunk(page); @@ -849,15 +860,14 @@ impl FetchResponseListener for ParserContext { .AppendChild(&DomRoot::upcast::(img)) .expect("Appending failed"); }, - Some(ref mime) if mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN => { + (mime::TEXT, mime::PLAIN, _) => { // https://html.spec.whatwg.org/multipage/#read-text let page = "
\n".into();
                 parser.push_string_input_chunk(page);
                 parser.parse_sync();
                 parser.tokenizer.borrow_mut().set_plaintext_state();
             },
-            Some(ref mime) if mime.type_() == mime::TEXT && mime.subtype() == mime::HTML => {
-                // Handle text/html
+            (mime::TEXT, mime::HTML, _) => {
                 if let Some((reason, bytes)) = ssl_error {
                     self.is_synthesized_document = true;
                     let page = resources::read_string(Resource::BadCertHTML);
@@ -877,29 +887,21 @@ impl FetchResponseListener for ParserContext {
                     parser.parse_sync();
                 }
             },
-            // Handle text/xml, application/xml
-            Some(ref mime)
-                if (mime.type_() == mime::TEXT && mime.subtype() == mime::XML) ||
-                    (mime.type_() == mime::APPLICATION && mime.subtype() == mime::XML) => {},
-            Some(ref mime)
-                if mime.type_() == mime::APPLICATION &&
-                    mime.subtype().as_str() == "xhtml" &&
-                    mime.suffix() == Some(mime::XML) => {}, // Handle xhtml (application/xhtml+xml)
-            Some(ref mime) => {
+            (mime::TEXT, mime::XML, _) |
+            (mime::APPLICATION, mime::XML, _) |
+            (mime::APPLICATION, mime::JSON, _) => {},
+            (mime::APPLICATION, subtype, Some(mime::XML)) if subtype == "xhtml" => {},
+            (mime_type, subtype, _) => {
                 // Show warning page for unknown mime types.
                 let page = format!(
                     "

Unknown content type ({}/{}).

", - mime.type_().as_str(), - mime.subtype().as_str() + mime_type.as_str(), + subtype.as_str() ); self.is_synthesized_document = true; parser.push_string_input_chunk(page); parser.parse_sync(); }, - None => { - // No content-type header. - // Merge with #4212 when fixed. - }, } } diff --git a/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-navigation.tentative.html.ini b/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-navigation.tentative.html.ini index f2b0051bd90..6fa2ef39c51 100644 --- a/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-navigation.tentative.html.ini +++ b/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-navigation.tentative.html.ini @@ -1,8 +1,3 @@ [schemeful-navigation.tentative.html] - expected: TIMEOUT [Navigate cross-scheme] - expected: NOTRUN - - [Navigate same-scheme] - expected: TIMEOUT - + expected: FAIL diff --git a/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-subresource.tentative.html.ini b/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-subresource.tentative.html.ini index 84db651b6ad..fabea5e46c9 100644 --- a/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-subresource.tentative.html.ini +++ b/tests/wpt/metadata/cookies/schemeful-same-site/schemeful-subresource.tentative.html.ini @@ -1,8 +1,3 @@ [schemeful-subresource.tentative.html] - expected: TIMEOUT [Cross-scheme subresources cannot sent lax/strict cookies] - expected: NOTRUN - - [Same-scheme subresources can send lax/strict cookies] - expected: TIMEOUT - + expected: FAIL