Tests: Add test for MimeType sniffing from filenames
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This commit is contained in:
Rocco Corsi 2025-05-26 12:18:32 -06:00 committed by Andrew Kaster
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 TestLibCoreFileWatcher.cpp
# FIXME: Identify and address the commit that caused this to start failing at runtime # FIXME: Identify and address the commit that caused this to start failing at runtime
#TestLibCoreMappedFile.cpp #TestLibCoreMappedFile.cpp
TestLibCoreMimeType.cpp
TestLibCorePromise.cpp TestLibCorePromise.cpp
TestLibCoreSharedSingleProducerCircularQueue.cpp TestLibCoreSharedSingleProducerCircularQueue.cpp
# FIXME: Identify and address the commit that caused this to start failing at runtime # 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);
}