mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWeb: Make more MimeSniff::MimeType APIs infallible
This commit is contained in:
parent
9a8db40a23
commit
88e7688940
Notes:
github-actions[bot]
2024-10-14 18:48:50 +00:00
Author: https://github.com/awesomekling
Commit: 88e7688940
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1796
14 changed files with 55 additions and 56 deletions
|
@ -15,7 +15,7 @@ TEST_CASE(determine_computed_mime_type_given_no_sniff_is_set)
|
|||
auto mime_type = Web::MimeSniff::MimeType::create("text"_string, "html"_string);
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("\x00"sv.bytes(), Web::MimeSniff::SniffingConfiguration { .supplied_type = mime_type, .no_sniff = true }));
|
||||
|
||||
EXPECT_EQ("text/html"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("text/html"sv, computed_mime_type.serialized());
|
||||
|
||||
// Cover the edge case in the context-specific sniffing algorithm.
|
||||
computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("\x00"sv.bytes(), Web::MimeSniff::SniffingConfiguration {
|
||||
|
@ -24,7 +24,7 @@ TEST_CASE(determine_computed_mime_type_given_no_sniff_is_set)
|
|||
.no_sniff = true,
|
||||
}));
|
||||
|
||||
EXPECT_EQ("text/html"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("text/html"sv, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
TEST_CASE(determine_computed_mime_type_given_no_sniff_is_unset)
|
||||
|
@ -32,7 +32,7 @@ TEST_CASE(determine_computed_mime_type_given_no_sniff_is_unset)
|
|||
auto supplied_type = Web::MimeSniff::MimeType::create("application"_string, "x-this-is-a-test"_string);
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("\x00"sv.bytes(), Web::MimeSniff::SniffingConfiguration { .supplied_type = supplied_type }));
|
||||
|
||||
EXPECT_EQ("application/x-this-is-a-test"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("application/x-this-is-a-test"sv, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
TEST_CASE(determine_computed_mime_type_given_xml_mime_type_as_supplied_type)
|
||||
|
@ -41,7 +41,7 @@ TEST_CASE(determine_computed_mime_type_given_xml_mime_type_as_supplied_type)
|
|||
auto supplied_type = MUST(Web::MimeSniff::MimeType::parse(xml_mime_type)).release_value();
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("\x00"sv.bytes(), Web::MimeSniff::SniffingConfiguration { .supplied_type = supplied_type }));
|
||||
|
||||
EXPECT_EQ(xml_mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(xml_mime_type, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
static void set_image_type_mappings(HashMap<StringView, Vector<StringView>>& mime_type_to_headers_map)
|
||||
|
@ -89,7 +89,7 @@ TEST_CASE(determine_computed_mime_type_given_supplied_type_that_is_an_apache_bug
|
|||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("Hello world!"sv.bytes(),
|
||||
Web::MimeSniff::SniffingConfiguration { .scheme = "http"sv, .supplied_type = supplied_type }));
|
||||
|
||||
EXPECT_EQ("text/plain"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("text/plain"sv, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
// Cover all code paths in "rules for distinguishing if a resource is text or binary".
|
||||
|
@ -106,7 +106,7 @@ TEST_CASE(determine_computed_mime_type_given_supplied_type_that_is_an_apache_bug
|
|||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff(header.bytes(),
|
||||
Web::MimeSniff::SniffingConfiguration { .scheme = "http"sv, .supplied_type = supplied_type }));
|
||||
|
||||
EXPECT_EQ(mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(mime_type, computed_mime_type.serialized());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,12 +116,12 @@ TEST_CASE(determine_computed_mime_type_given_xml_or_html_supplied_type)
|
|||
// With HTML supplied type.
|
||||
auto config = Web::MimeSniff::SniffingConfiguration { .supplied_type = Web::MimeSniff::MimeType::create("text"_string, "html"_string) };
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff(""sv.bytes(), config));
|
||||
EXPECT_EQ("text/html"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("text/html"sv, computed_mime_type.serialized());
|
||||
|
||||
// With XML supplied type.
|
||||
config = Web::MimeSniff::SniffingConfiguration { .supplied_type = Web::MimeSniff::MimeType::create("text"_string, "xml"_string) };
|
||||
computed_mime_type = MUST(Web::MimeSniff::Resource::sniff(""sv.bytes(), config));
|
||||
EXPECT_EQ("text/xml"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("text/xml"sv, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
TEST_CASE(determine_computed_mime_type_in_both_none_and_browsing_sniffing_context)
|
||||
|
@ -198,7 +198,7 @@ TEST_CASE(determine_computed_mime_type_in_image_sniffing_context)
|
|||
auto supplied_type = MUST(Web::MimeSniff::MimeType::parse(mime_type)).release_value();
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff(""sv.bytes(), Web::MimeSniff::SniffingConfiguration { .sniffing_context = Web::MimeSniff::SniffingContext::Image, .supplied_type = supplied_type }));
|
||||
|
||||
EXPECT_EQ(mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(mime_type, computed_mime_type.serialized());
|
||||
|
||||
HashMap<StringView, Vector<StringView>> mime_type_to_headers_map;
|
||||
|
||||
|
@ -234,7 +234,7 @@ TEST_CASE(determine_computed_mime_type_in_audio_or_video_sniffing_context)
|
|||
.supplied_type = supplied_type,
|
||||
}));
|
||||
|
||||
EXPECT_EQ(mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(mime_type, computed_mime_type.serialized());
|
||||
HashMap<StringView, Vector<StringView>> mime_type_to_headers_map;
|
||||
|
||||
set_audio_or_video_type_mappings(mime_type_to_headers_map);
|
||||
|
@ -290,7 +290,7 @@ TEST_CASE(determine_computed_mime_type_when_trying_to_match_mp4_signature)
|
|||
|
||||
for (auto const& header : mime_type_to_headers.value) {
|
||||
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff(header.bytes(), Web::MimeSniff::SniffingConfiguration { .sniffing_context = Web::MimeSniff::SniffingContext::AudioOrVideo }));
|
||||
EXPECT_EQ(mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(mime_type, computed_mime_type.serialized());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ TEST_CASE(determine_computed_mime_type_in_a_font_context)
|
|||
.supplied_type = supplied_type,
|
||||
}));
|
||||
|
||||
EXPECT_EQ(mime_type, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ(mime_type, computed_mime_type.serialized());
|
||||
|
||||
HashMap<StringView, Vector<StringView>> mime_type_to_headers_map;
|
||||
mime_type_to_headers_map.set("application/octet-stream"sv, { "\x00"sv });
|
||||
|
@ -343,7 +343,7 @@ TEST_CASE(determine_computed_mime_type_given_text_or_binary_context)
|
|||
.sniffing_context = Web::MimeSniff::SniffingContext::TextOrBinary,
|
||||
.supplied_type = supplied_type,
|
||||
}));
|
||||
EXPECT_EQ("application/octet-stream"sv, MUST(computed_mime_type.serialized()));
|
||||
EXPECT_EQ("application/octet-stream"sv, computed_mime_type.serialized());
|
||||
}
|
||||
|
||||
TEST_CASE(determine_minimised_mime_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue