Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: net/base/mime_util_unittest.cc

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/mime_util.cc ('k') | net/base/net_string_util_icu_alternatives_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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* const 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(tests); ++i) { 36 for (size_t i = 0; i < arraysize(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* const 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
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); 252 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
253 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); 253 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
254 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); 254 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
255 } 255 }
256 256
257 // Note: codecs should only be a list of 2 or fewer; hence the restriction of 257 // Note: codecs should only be a list of 2 or fewer; hence the restriction of
258 // results' length to 2. 258 // results' length to 2.
259 TEST(MimeUtilTest, ParseCodecString) { 259 TEST(MimeUtilTest, ParseCodecString) {
260 const struct { 260 const struct {
261 const char* original; 261 const char* const original;
262 size_t expected_size; 262 size_t expected_size;
263 const char* results[2]; 263 const char* const results[2];
264 } tests[] = { 264 } tests[] = {
265 { "\"bogus\"", 1, { "bogus" } }, 265 { "\"bogus\"", 1, { "bogus" } },
266 { "0", 1, { "0" } }, 266 { "0", 1, { "0" } },
267 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, 267 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
268 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, 268 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
269 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, 269 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
270 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, 270 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
271 { "", 0, { } }, 271 { "", 0, { } },
272 { "\"\"", 0, { } }, 272 { "\"\"", 0, { } },
273 { "\" \"", 0, { } }, 273 { "\" \"", 0, { } },
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 EXPECT_FALSE(IsValidTopLevelMimeType(" ")); 358 EXPECT_FALSE(IsValidTopLevelMimeType(" "));
359 359
360 EXPECT_TRUE(IsValidTopLevelMimeType("x-video")); 360 EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
361 EXPECT_TRUE(IsValidTopLevelMimeType("X-video")); 361 EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
362 362
363 EXPECT_FALSE(IsValidTopLevelMimeType("x-")); 363 EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
364 } 364 }
365 365
366 TEST(MimeUtilTest, TestGetExtensionsForMimeType) { 366 TEST(MimeUtilTest, TestGetExtensionsForMimeType) {
367 const struct { 367 const struct {
368 const char* mime_type; 368 const char* const mime_type;
369 size_t min_expected_size; 369 size_t min_expected_size;
370 const char* contained_result; 370 const char* const contained_result;
371 } tests[] = { 371 } tests[] = {
372 { "text/plain", 2, "txt" }, 372 { "text/plain", 2, "txt" },
373 { "*", 0, NULL }, 373 { "*", 0, NULL },
374 { "message/*", 1, "eml" }, 374 { "message/*", 1, "eml" },
375 { "MeSsAge/*", 1, "eml" }, 375 { "MeSsAge/*", 1, "eml" },
376 { "image/bmp", 1, "bmp" }, 376 { "image/bmp", 1, "bmp" },
377 { "video/*", 6, "mp4" }, 377 { "video/*", 6, "mp4" },
378 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS) 378 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS)
379 { "video/*", 6, "mpg" }, 379 { "video/*", 6, "mpg" },
380 #else 380 #else
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, 420 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
421 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert")); 421 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert"));
422 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, 422 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
423 GetCertificateMimeTypeForMimeType("application/x-pkcs12")); 423 GetCertificateMimeTypeForMimeType("application/x-pkcs12"));
424 #endif 424 #endif
425 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN, 425 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
426 GetCertificateMimeTypeForMimeType("text/plain")); 426 GetCertificateMimeTypeForMimeType("text/plain"));
427 } 427 }
428 428
429 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { 429 TEST(MimeUtilTest, TestAddMultipartValueForUpload) {
430 const char* ref_output = "--boundary\r\nContent-Disposition: form-data;" 430 const char ref_output[] =
431 " name=\"value name\"\r\nContent-Type: content type" 431 "--boundary\r\nContent-Disposition: form-data;"
432 "\r\n\r\nvalue\r\n" 432 " name=\"value name\"\r\nContent-Type: content type"
433 "--boundary\r\nContent-Disposition: form-data;" 433 "\r\n\r\nvalue\r\n"
434 " name=\"value name\"\r\n\r\nvalue\r\n" 434 "--boundary\r\nContent-Disposition: form-data;"
435 "--boundary--\r\n"; 435 " name=\"value name\"\r\n\r\nvalue\r\n"
436 "--boundary--\r\n";
436 std::string post_data; 437 std::string post_data;
437 AddMultipartValueForUpload("value name", "value", "boundary", 438 AddMultipartValueForUpload("value name", "value", "boundary",
438 "content type", &post_data); 439 "content type", &post_data);
439 AddMultipartValueForUpload("value name", "value", "boundary", 440 AddMultipartValueForUpload("value name", "value", "boundary",
440 "", &post_data); 441 "", &post_data);
441 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 442 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
442 EXPECT_STREQ(ref_output, post_data.c_str()); 443 EXPECT_STREQ(ref_output, post_data.c_str());
443 } 444 }
444 445
445 } // namespace net 446 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_util.cc ('k') | net/base/net_string_util_icu_alternatives_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698