| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" | 
| 6 #include "base/strings/string_split.h" | 6 #include "base/strings/string_split.h" | 
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" | 
| 8 #include "net/base/mime_util.h" | 8 #include "net/base/mime_util.h" | 
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" | 
| 10 | 10 | 
| 11 #if defined(OS_ANDROID) | 11 #if defined(OS_ANDROID) | 
| 12 #include "base/android/build_info.h" | 12 #include "base/android/build_info.h" | 
| 13 #endif | 13 #endif | 
| 14 | 14 | 
| 15 namespace net { | 15 namespace net { | 
| 16 | 16 | 
| 17 TEST(MimeUtilTest, ExtensionTest) { | 17 TEST(MimeUtilTest, ExtensionTest) { | 
| 18   const struct { | 18   const struct { | 
| 19     const base::FilePath::CharType* extension; | 19     const base::FilePath::CharType* extension; | 
| 20     const char* mime_type; | 20     const char* mime_type; | 
| 21     bool valid; | 21     bool valid; | 
| 22   } tests[] = { | 22   } tests[] = { | 
| 23     { FILE_PATH_LITERAL("png"), "image/png", true }, | 23     {FILE_PATH_LITERAL("png"), "image/png", true}, | 
| 24     { FILE_PATH_LITERAL("css"), "text/css", true }, | 24     {FILE_PATH_LITERAL("css"), "text/css", true}, | 
| 25     { FILE_PATH_LITERAL("pjp"), "image/jpeg", true }, | 25     {FILE_PATH_LITERAL("pjp"), "image/jpeg", true}, | 
| 26     { FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true }, | 26     {FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true}, | 
| 27 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) | 
| 28     { FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true }, | 28     {FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true}, | 
| 29 #endif | 29 #endif | 
| 30     { FILE_PATH_LITERAL("not an extension / for sure"), "", false }, | 30     {FILE_PATH_LITERAL("not an extension / for sure"), "", false}, | 
| 31   }; | 31   }; | 
| 32 | 32 | 
| 33   std::string mime_type; | 33   std::string mime_type; | 
| 34   bool rv; | 34   bool rv; | 
| 35 | 35 | 
| 36   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 36   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 
| 37     rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type); | 37     rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type); | 
| 38     EXPECT_EQ(tests[i].valid, rv); | 38     EXPECT_EQ(tests[i].valid, rv); | 
| 39     if (rv) | 39     if (rv) | 
| 40       EXPECT_EQ(tests[i].mime_type, mime_type); | 40       EXPECT_EQ(tests[i].mime_type, mime_type); | 
| 41   } | 41   } | 
| 42 } | 42 } | 
| 43 | 43 | 
| 44 TEST(MimeUtilTest, FileTest) { | 44 TEST(MimeUtilTest, FileTest) { | 
| 45   const struct { | 45   const struct { | 
| 46     const base::FilePath::CharType* file_path; | 46     const base::FilePath::CharType* file_path; | 
| 47     const char* mime_type; | 47     const char* mime_type; | 
| 48     bool valid; | 48     bool valid; | 
| 49   } tests[] = { | 49   } tests[] = { | 
| 50     { FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true }, | 50         {FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true}, | 
| 51     { FILE_PATH_LITERAL("c:\\blah"), "", false }, | 51         {FILE_PATH_LITERAL("c:\\blah"), "", false}, | 
| 52     { FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false }, | 52         {FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false}, | 
| 53     { FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true }, | 53         {FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true}, | 
| 54     { FILE_PATH_LITERAL("/blah."), "", false }, | 54         {FILE_PATH_LITERAL("/blah."), "", false}, | 
| 55     { FILE_PATH_LITERAL("c:\\blah."), "", false }, | 55         {FILE_PATH_LITERAL("c:\\blah."), "", false}, | 
| 56   }; | 56     }; | 
| 57 | 57 | 
| 58   std::string mime_type; | 58   std::string mime_type; | 
| 59   bool rv; | 59   bool rv; | 
| 60 | 60 | 
| 61   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 61   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 
| 62     rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path), | 62     rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path), &mime_type); | 
| 63                                   &mime_type); |  | 
| 64     EXPECT_EQ(tests[i].valid, rv); | 63     EXPECT_EQ(tests[i].valid, rv); | 
| 65     if (rv) | 64     if (rv) | 
| 66       EXPECT_EQ(tests[i].mime_type, mime_type); | 65       EXPECT_EQ(tests[i].mime_type, mime_type); | 
| 67   } | 66   } | 
| 68 } | 67 } | 
| 69 | 68 | 
| 70 TEST(MimeUtilTest, LookupTypes) { | 69 TEST(MimeUtilTest, LookupTypes) { | 
| 71   EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana")); | 70   EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana")); | 
| 72   EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard")); | 71   EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard")); | 
| 73 | 72 | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 128   EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); | 127   EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); | 
| 129   EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); | 128   EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); | 
| 130   EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); | 129   EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); | 
| 131 } | 130 } | 
| 132 | 131 | 
| 133 TEST(MimeUtilTest, MatchesMimeType) { | 132 TEST(MimeUtilTest, MatchesMimeType) { | 
| 134   EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); | 133   EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); | 
| 135   EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); | 134   EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); | 
| 136   EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); | 135   EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); | 
| 137   EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); | 136   EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); | 
| 138   EXPECT_TRUE(MatchesMimeType("application/*+xml", | 137   EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/html+xml")); | 
| 139                                    "application/html+xml")); |  | 
| 140   EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); | 138   EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); | 
| 141   EXPECT_TRUE(MatchesMimeType("application/*+json", | 139   EXPECT_TRUE( | 
| 142                                    "application/x-myformat+json")); | 140       MatchesMimeType("application/*+json", "application/x-myformat+json")); | 
| 143   EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa")); | 141   EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa")); | 
| 144   EXPECT_TRUE(MatchesMimeType("*", std::string())); | 142   EXPECT_TRUE(MatchesMimeType("*", std::string())); | 
| 145   EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg")); | 143   EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg")); | 
| 146   EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg")); | 144   EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg")); | 
| 147   EXPECT_FALSE(MatchesMimeType(std::string(), std::string())); | 145   EXPECT_FALSE(MatchesMimeType(std::string(), std::string())); | 
| 148   EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string())); | 146   EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string())); | 
| 149   EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml")); | 147   EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml")); | 
| 150   EXPECT_FALSE(MatchesMimeType("application/*+xml", | 148   EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/html+xmlz")); | 
| 151                                     "application/html+xmlz")); | 149   EXPECT_FALSE(MatchesMimeType("application/*+xml", "applcation/html+xml")); | 
| 152   EXPECT_FALSE(MatchesMimeType("application/*+xml", |  | 
| 153                                     "applcation/html+xml")); |  | 
| 154   EXPECT_FALSE(MatchesMimeType("aaa*aaa", "aaaaa")); | 150   EXPECT_FALSE(MatchesMimeType("aaa*aaa", "aaaaa")); | 
| 155 | 151 | 
| 156   EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg;param=val")); | 152   EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg;param=val")); | 
| 157   EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg;param=val")); | 153   EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg;param=val")); | 
| 158   EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg")); | 154   EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg")); | 
| 159   EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg;param=other")); | 155   EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg;param=other")); | 
| 160   EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/mpeg;param=val")); | 156   EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/mpeg;param=val")); | 
| 161   EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg;param=val")); | 157   EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg;param=val")); | 
| 162   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val", | 158   EXPECT_TRUE( | 
| 163                               "video/x-mpeg;param=val")); | 159       MatchesMimeType("video/x-mpeg;param=val", "video/x-mpeg;param=val")); | 
| 164   EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2", | 160   EXPECT_FALSE( | 
| 165                                "video/x-mpeg;param=val")); | 161       MatchesMimeType("video/x-mpeg;param2=val2", "video/x-mpeg;param=val")); | 
| 166   EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2", | 162   EXPECT_FALSE( | 
| 167                                "video/x-mpeg;param2=val")); | 163       MatchesMimeType("video/x-mpeg;param2=val2", "video/x-mpeg;param2=val")); | 
| 168   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val", | 164   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val", | 
| 169                               "video/x-mpeg;param=val;param2=val2")); | 165                               "video/x-mpeg;param=val;param2=val2")); | 
| 170   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val;param2=val2", | 166   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val;param2=val2", | 
| 171                               "video/x-mpeg;param=val;param2=val2")); | 167                               "video/x-mpeg;param=val;param2=val2")); | 
| 172   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param2=val2;param=val", | 168   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param2=val2;param=val", | 
| 173                               "video/x-mpeg;param=val;param2=val2")); | 169                               "video/x-mpeg;param=val;param2=val2")); | 
| 174   EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param3=val3;param=val", | 170   EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param3=val3;param=val", | 
| 175                                "video/x-mpeg;param=val;param2=val2")); | 171                                "video/x-mpeg;param=val;param2=val2")); | 
| 176   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val ;param2=val2 ", | 172   EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val ;param2=val2 ", | 
| 177                               "video/x-mpeg;param=val;param2=val2")); | 173                               "video/x-mpeg;param=val;param2=val2")); | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 255 } | 251 } | 
| 256 | 252 | 
| 257 // Note: codecs should only be a list of 2 or fewer; hence the restriction of | 253 // Note: codecs should only be a list of 2 or fewer; hence the restriction of | 
| 258 // results' length to 2. | 254 // results' length to 2. | 
| 259 TEST(MimeUtilTest, ParseCodecString) { | 255 TEST(MimeUtilTest, ParseCodecString) { | 
| 260   const struct { | 256   const struct { | 
| 261     const char* original; | 257     const char* original; | 
| 262     size_t expected_size; | 258     size_t expected_size; | 
| 263     const char* results[2]; | 259     const char* results[2]; | 
| 264   } tests[] = { | 260   } tests[] = { | 
| 265     { "\"bogus\"",                  1, { "bogus" }            }, | 261         {"\"bogus\"", 1, {"bogus"}}, | 
| 266     { "0",                          1, { "0" }                }, | 262         {"0", 1, {"0"}}, | 
| 267     { "avc1.42E01E, mp4a.40.2",     2, { "avc1",   "mp4a" }   }, | 263         {"avc1.42E01E, mp4a.40.2", 2, {"avc1", "mp4a"}}, | 
| 268     { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v",   "mp4a" }   }, | 264         {"\"mp4v.20.240, mp4a.40.2\"", 2, {"mp4v", "mp4a"}}, | 
| 269     { "mp4v.20.8, samr",            2, { "mp4v",   "samr" }   }, | 265         {"mp4v.20.8, samr", 2, {"mp4v", "samr"}}, | 
| 270     { "\"theora, vorbis\"",         2, { "theora", "vorbis" } }, | 266         {"\"theora, vorbis\"", 2, {"theora", "vorbis"}}, | 
| 271     { "",                           0, { }                    }, | 267         {"", 0, {}}, | 
| 272     { "\"\"",                       0, { }                    }, | 268         {"\"\"", 0, {}}, | 
| 273     { "\"   \"",                    0, { }                    }, | 269         {"\"   \"", 0, {}}, | 
| 274     { ",",                          2, { "", "" }             }, | 270         {",", 2, {"", ""}}, | 
| 275   }; | 271     }; | 
| 276 | 272 | 
| 277   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 273   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 
| 278     std::vector<std::string> codecs_out; | 274     std::vector<std::string> codecs_out; | 
| 279     ParseCodecString(tests[i].original, &codecs_out, true); | 275     ParseCodecString(tests[i].original, &codecs_out, true); | 
| 280     ASSERT_EQ(tests[i].expected_size, codecs_out.size()); | 276     ASSERT_EQ(tests[i].expected_size, codecs_out.size()); | 
| 281     for (size_t j = 0; j < tests[i].expected_size; ++j) | 277     for (size_t j = 0; j < tests[i].expected_size; ++j) | 
| 282       EXPECT_EQ(tests[i].results[j], codecs_out[j]); | 278       EXPECT_EQ(tests[i].results[j], codecs_out[j]); | 
| 283   } | 279   } | 
| 284 | 280 | 
| 285   // Test without stripping the codec type. | 281   // Test without stripping the codec type. | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 327   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL)); | 323   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL)); | 
| 328   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL)); | 324   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL)); | 
| 329   EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL)); | 325   EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL)); | 
| 330   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL)); | 326   EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL)); | 
| 331 | 327 | 
| 332   EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL)); | 328   EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL)); | 
| 333   EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL)); | 329   EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL)); | 
| 334 | 330 | 
| 335   EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL)); | 331   EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL)); | 
| 336 | 332 | 
| 337   //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter")); | 333   // EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter")); | 
| 338 } | 334 } | 
| 339 | 335 | 
| 340 TEST(MimeUtilTest, TestIsValidTopLevelMimeType) { | 336 TEST(MimeUtilTest, TestIsValidTopLevelMimeType) { | 
| 341   EXPECT_TRUE(IsValidTopLevelMimeType("application")); | 337   EXPECT_TRUE(IsValidTopLevelMimeType("application")); | 
| 342   EXPECT_TRUE(IsValidTopLevelMimeType("audio")); | 338   EXPECT_TRUE(IsValidTopLevelMimeType("audio")); | 
| 343   EXPECT_TRUE(IsValidTopLevelMimeType("example")); | 339   EXPECT_TRUE(IsValidTopLevelMimeType("example")); | 
| 344   EXPECT_TRUE(IsValidTopLevelMimeType("image")); | 340   EXPECT_TRUE(IsValidTopLevelMimeType("image")); | 
| 345   EXPECT_TRUE(IsValidTopLevelMimeType("message")); | 341   EXPECT_TRUE(IsValidTopLevelMimeType("message")); | 
| 346   EXPECT_TRUE(IsValidTopLevelMimeType("model")); | 342   EXPECT_TRUE(IsValidTopLevelMimeType("model")); | 
| 347   EXPECT_TRUE(IsValidTopLevelMimeType("multipart")); | 343   EXPECT_TRUE(IsValidTopLevelMimeType("multipart")); | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 379   EXPECT_EQ("text", GetIANAMediaType("text/plain")); | 375   EXPECT_EQ("text", GetIANAMediaType("text/plain")); | 
| 380   EXPECT_EQ("video", GetIANAMediaType("video/H261")); | 376   EXPECT_EQ("video", GetIANAMediaType("video/H261")); | 
| 381 } | 377 } | 
| 382 | 378 | 
| 383 TEST(MimeUtilTest, TestGetExtensionsForMimeType) { | 379 TEST(MimeUtilTest, TestGetExtensionsForMimeType) { | 
| 384   const struct { | 380   const struct { | 
| 385     const char* mime_type; | 381     const char* mime_type; | 
| 386     size_t min_expected_size; | 382     size_t min_expected_size; | 
| 387     const char* contained_result; | 383     const char* contained_result; | 
| 388   } tests[] = { | 384   } tests[] = { | 
| 389     { "text/plain", 2, "txt" }, | 385     {"text/plain", 2, "txt"}, | 
| 390     { "*",          0, NULL  }, | 386     {"*", 0, NULL}, | 
| 391     { "message/*",  1, "eml" }, | 387     {"message/*", 1, "eml"}, | 
| 392     { "MeSsAge/*",  1, "eml" }, | 388     {"MeSsAge/*", 1, "eml"}, | 
| 393     { "image/bmp",  1, "bmp" }, | 389     {"image/bmp", 1, "bmp"}, | 
| 394     { "video/*",    6, "mp4" }, | 390     {"video/*", 6, "mp4"}, | 
| 395 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS) | 391 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS) | 
| 396     { "video/*",    6, "mpg" }, | 392     {"video/*", 6, "mpg"}, | 
| 397 #else | 393 #else | 
| 398     { "video/*",    6, "mpeg" }, | 394     {"video/*", 6, "mpeg"}, | 
| 399 #endif | 395 #endif | 
| 400     { "audio/*",    6, "oga" }, | 396     {"audio/*", 6, "oga"}, | 
| 401     { "aUDIo/*",    6, "wav" }, | 397     {"aUDIo/*", 6, "wav"}, | 
| 402   }; | 398   }; | 
| 403 | 399 | 
| 404   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 400   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 
| 405     std::vector<base::FilePath::StringType> extensions; | 401     std::vector<base::FilePath::StringType> extensions; | 
| 406     GetExtensionsForMimeType(tests[i].mime_type, &extensions); | 402     GetExtensionsForMimeType(tests[i].mime_type, &extensions); | 
| 407     ASSERT_TRUE(tests[i].min_expected_size <= extensions.size()); | 403     ASSERT_TRUE(tests[i].min_expected_size <= extensions.size()); | 
| 408 | 404 | 
| 409     if (!tests[i].contained_result) | 405     if (!tests[i].contained_result) | 
| 410       continue; | 406       continue; | 
| 411 | 407 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 437   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 433   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 
| 438             GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert")); | 434             GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert")); | 
| 439   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 435   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 
| 440             GetCertificateMimeTypeForMimeType("application/x-pkcs12")); | 436             GetCertificateMimeTypeForMimeType("application/x-pkcs12")); | 
| 441 #endif | 437 #endif | 
| 442   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 438   EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, | 
| 443             GetCertificateMimeTypeForMimeType("text/plain")); | 439             GetCertificateMimeTypeForMimeType("text/plain")); | 
| 444 } | 440 } | 
| 445 | 441 | 
| 446 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { | 442 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { | 
| 447   const char* ref_output = "--boundary\r\nContent-Disposition: form-data;" | 443   const char* ref_output = | 
| 448                            " name=\"value name\"\r\nContent-Type: content type" | 444       "--boundary\r\nContent-Disposition: form-data;" | 
| 449                            "\r\n\r\nvalue\r\n" | 445       " name=\"value name\"\r\nContent-Type: content type" | 
| 450                            "--boundary\r\nContent-Disposition: form-data;" | 446       "\r\n\r\nvalue\r\n" | 
| 451                            " name=\"value name\"\r\n\r\nvalue\r\n" | 447       "--boundary\r\nContent-Disposition: form-data;" | 
| 452                            "--boundary--\r\n"; | 448       " name=\"value name\"\r\n\r\nvalue\r\n" | 
|  | 449       "--boundary--\r\n"; | 
| 453   std::string post_data; | 450   std::string post_data; | 
| 454   AddMultipartValueForUpload("value name", "value", "boundary", | 451   AddMultipartValueForUpload( | 
| 455                              "content type", &post_data); | 452       "value name", "value", "boundary", "content type", &post_data); | 
| 456   AddMultipartValueForUpload("value name", "value", "boundary", | 453   AddMultipartValueForUpload("value name", "value", "boundary", "", &post_data); | 
| 457                              "", &post_data); |  | 
| 458   AddMultipartFinalDelimiterForUpload("boundary", &post_data); | 454   AddMultipartFinalDelimiterForUpload("boundary", &post_data); | 
| 459   EXPECT_STREQ(ref_output, post_data.c_str()); | 455   EXPECT_STREQ(ref_output, post_data.c_str()); | 
| 460 } | 456 } | 
| 461 | 457 | 
| 462 }  // namespace net | 458 }  // namespace net | 
| OLD | NEW | 
|---|