Commit 5a964245 authored by Asanka Herath's avatar Asanka Herath Committed by Commit Bot

[net/base] Add tests for GetPreferredExtensionForMimeType

Bug: None
Change-Id: Ibe0e4bd1fb1264bc15fb323273566e72e5b273b2
Reviewed-on: https://chromium-review.googlesource.com/c/1315958Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Asanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605142}
parent 3e88b8ba
...@@ -30,6 +30,8 @@ TEST(MimeUtilTest, ExtensionTest) { ...@@ -30,6 +30,8 @@ TEST(MimeUtilTest, ExtensionTest) {
{FILE_PATH_LITERAL("pjp"), "image/jpeg", true}, {FILE_PATH_LITERAL("pjp"), "image/jpeg", true},
{FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true}, {FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true},
{FILE_PATH_LITERAL("json"), "application/json", true}, {FILE_PATH_LITERAL("json"), "application/json", true},
{FILE_PATH_LITERAL("js"), "text/javascript", true},
{FILE_PATH_LITERAL("webm"), "video/webm", true},
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// These are test cases for testing platform mime types on Chrome OS. // These are test cases for testing platform mime types on Chrome OS.
{FILE_PATH_LITERAL("epub"), "application/epub+zip", true}, {FILE_PATH_LITERAL("epub"), "application/epub+zip", true},
...@@ -55,6 +57,31 @@ TEST(MimeUtilTest, ExtensionTest) { ...@@ -55,6 +57,31 @@ TEST(MimeUtilTest, ExtensionTest) {
} }
} }
// Behavior of GetPreferredExtensionForMimeType() is dependent on the host
// platform since the latter can override the mapping from file extensions to
// MIME types. The tests below would only work if the platform MIME mappings
// don't have mappings for or has an agreeing mapping for each MIME type
// mentioned.
TEST(MimeUtilTest, GetPreferredExtensionForMimeType) {
const struct {
const std::string mime_type;
const base::FilePath::StringType expected_extension;
} kTestCases[] = {
{"application/wasm", FILE_PATH_LITERAL("wasm")}, // Primary
{"application/javascript", FILE_PATH_LITERAL("js")}, // Secondary
{"text/javascript", FILE_PATH_LITERAL("js")}, // Primary
{"audio/webm", FILE_PATH_LITERAL("webm")}, // Primary
{"video/webm", FILE_PATH_LITERAL("webm")}, // Primary
};
for (const auto& test : kTestCases) {
base::FilePath::StringType extension;
auto rv = GetPreferredExtensionForMimeType(test.mime_type, &extension);
EXPECT_TRUE(rv);
EXPECT_EQ(test.expected_extension, extension);
}
}
TEST(MimeUtilTest, FileTest) { TEST(MimeUtilTest, FileTest) {
const struct { const struct {
const base::FilePath::CharType* file_path; const base::FilePath::CharType* file_path;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment