/* * Copyright (c) 2023, Kemal Zebari . * * SPDX-License-Identifier: BSD-2-Clause */ #include #include TEST_CASE(determine_computed_mime_type_given_no_sniff_is_set) { auto mime_type = MUST(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())); } TEST_CASE(determine_computed_mime_type_given_no_sniff_is_unset) { auto supplied_type = MUST(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 = supplied_type })); EXPECT_EQ("application/octet-stream"sv, MUST(computed_mime_type.serialized())); // Make sure we cover the XML code path in the mime type sniffing algorithm. auto xml_mime_type = "application/rss+xml"sv; supplied_type = MUST(Web::MimeSniff::MimeType::parse(xml_mime_type)).release_value(); 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())); } TEST_CASE(determine_computed_mime_type_in_both_none_and_browsing_sniffing_context) { HashMap> mime_type_to_headers_map; mime_type_to_headers_map.set("application/octet-stream"sv, { "\x00"sv }); mime_type_to_headers_map.set("text/html"sv, { "\x09\x09"sv, "\x20