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

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

Issue 1134393002: Implement ChromeOS mime type extension mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flag guard two test cases for ChromeOS. Created 5 years, 7 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
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 // String: png\0css
19 base::FilePath::StringType containsNullByte;
20 containsNullByte.append(FILE_PATH_LITERAL("png"));
21 containsNullByte.append(1, FILE_PATH_LITERAL('\0'));
22 containsNullByte.append(FILE_PATH_LITERAL("css"));
23
18 const struct { 24 const struct {
19 const base::FilePath::CharType* extension; 25 const base::FilePath::StringType extension;
20 const char* const mime_type; 26 const char* const mime_type;
21 bool valid; 27 bool valid;
22 } tests[] = { 28 } tests[] = {
23 {FILE_PATH_LITERAL("png"), "image/png", true}, 29 {FILE_PATH_LITERAL("png"), "image/png", true},
24 {FILE_PATH_LITERAL("PNG"), "image/png", true}, 30 {FILE_PATH_LITERAL("PNG"), "image/png", true},
25 {FILE_PATH_LITERAL("css"), "text/css", true}, 31 {FILE_PATH_LITERAL("css"), "text/css", true},
26 {FILE_PATH_LITERAL("pjp"), "image/jpeg", true}, 32 {FILE_PATH_LITERAL("pjp"), "image/jpeg", true},
27 {FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true}, 33 {FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true},
34 #if defined(OS_CHROMEOS)
35 // These two are test cases for testing platform mime types on Chrome OS.
36 {FILE_PATH_LITERAL("epub"), "application/epub+zip", true},
37 {FILE_PATH_LITERAL("ics"), "text/calendar", true},
38 #endif
28 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
29 {FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true}, 40 {FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true},
30 #endif 41 #endif
31 {FILE_PATH_LITERAL("not an extension / for sure"), "", false}, 42 {FILE_PATH_LITERAL("not an extension / for sure"), "", false},
43 {containsNullByte, "", false}
32 }; 44 };
33 45
34 std::string mime_type; 46 std::string mime_type;
35 bool rv; 47 bool rv;
36 48
37 for (size_t i = 0; i < arraysize(tests); ++i) { 49 for (size_t i = 0; i < arraysize(tests); ++i) {
38 rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type); 50 rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type);
39 EXPECT_EQ(tests[i].valid, rv); 51 EXPECT_EQ(tests[i].valid, rv);
40 if (rv) 52 if (rv)
41 EXPECT_EQ(tests[i].mime_type, mime_type); 53 EXPECT_EQ(tests[i].mime_type, mime_type);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 std::string post_data; 426 std::string post_data;
415 AddMultipartValueForUpload("value name", "value", "boundary", 427 AddMultipartValueForUpload("value name", "value", "boundary",
416 "content type", &post_data); 428 "content type", &post_data);
417 AddMultipartValueForUpload("value name", "value", "boundary", 429 AddMultipartValueForUpload("value name", "value", "boundary",
418 "", &post_data); 430 "", &post_data);
419 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 431 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
420 EXPECT_STREQ(ref_output, post_data.c_str()); 432 EXPECT_STREQ(ref_output, post_data.c_str());
421 } 433 }
422 434
423 } // namespace net 435 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698