1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

Tests: Add test for MimeType sniffing from filenames

This commit is contained in:
Rocco Corsi 2025-05-26 12:18:32 -06:00 committed by Andrew Kaster
parent 9281baffd8
commit 70abe99bfd
Notes: github-actions[bot] 2025-05-26 20:24:53 +00:00
2 changed files with 56 additions and 0 deletions

View file

@ -5,6 +5,7 @@ set(TEST_SOURCES
TestLibCoreFileWatcher.cpp
# FIXME: Identify and address the commit that caused this to start failing at runtime
#TestLibCoreMappedFile.cpp
TestLibCoreMimeType.cpp
TestLibCorePromise.cpp
TestLibCoreSharedSingleProducerCircularQueue.cpp
# FIXME: Identify and address the commit that caused this to start failing at runtime

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2025, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Vector.h>
#include <LibCore/MimeData.h>
#include <LibTest/TestCase.h>
static void check_filename_mimetype(Vector<StringView> const& filepaths, StringView expected_mime_type)
{
for (auto const& filename : filepaths) {
dbgln(filename, "\n");
auto const& guessed_mime_type = Core::guess_mime_type_based_on_filename(filename);
EXPECT_EQ(guessed_mime_type, expected_mime_type);
}
}
auto text_plain_filenames = Vector {
"main.c"sv,
"hello.txt"sv,
".history"sv,
".shellrc"sv,
"CMakeList.txt"sv,
};
// FIXME: fails because .xht extension is in MimeType text/html and application/xhtml+xml
// auto html_filenames = Vector {"about.html"sv, "send-data-blob.htm"sv, "content.xht"sv, "dir/settings.html"sv,};
auto xhtml_filenames = Vector {
"about.xhtml"sv,
"content.xht"sv,
};
auto gzip_filenames = Vector {
"download.iso.gz"sv,
"backup.gzip"sv,
"hello.html.gz"sv,
};
auto markdown_filenames = Vector {
"README.md"sv,
"changelog.md"sv,
};
auto shell_filenames = Vector {
"script.sh"sv,
};
TEST_CASE(various_types_guessed)
{
check_filename_mimetype(text_plain_filenames, "text/plain"sv);
// FIXME: fails because .xht extension is in MimeType text/html and application/xhtml+xml
// check_filename_mimetype(html_filenames, "text/html"sv);
check_filename_mimetype(xhtml_filenames, "application/xhtml+xml"sv);
check_filename_mimetype(gzip_filenames, "application/gzip"sv);
check_filename_mimetype(markdown_filenames, "text/markdown"sv);
check_filename_mimetype(shell_filenames, "text/x-shellscript"sv);
}