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) | |
12 #define EXPECT_TRUE_NON_ANDROID EXPECT_FALSE | |
scherkus (not reviewing)
2014/04/02 16:26:46
considering this is only used in one place I don't
amogh.bihani
2014/04/03 03:57:13
Done.
| |
13 #else | |
14 #define EXPECT_TRUE_NON_ANDROID EXPECT_TRUE | |
15 #endif // OS_ANDROID | |
16 | |
11 namespace net { | 17 namespace net { |
12 | 18 |
13 TEST(MimeUtilTest, ExtensionTest) { | 19 TEST(MimeUtilTest, ExtensionTest) { |
14 const struct { | 20 const struct { |
15 const base::FilePath::CharType* extension; | 21 const base::FilePath::CharType* extension; |
16 const char* mime_type; | 22 const char* mime_type; |
17 bool valid; | 23 bool valid; |
18 } tests[] = { | 24 } tests[] = { |
19 { FILE_PATH_LITERAL("png"), "image/png", true }, | 25 { FILE_PATH_LITERAL("png"), "image/png", true }, |
20 { FILE_PATH_LITERAL("css"), "text/css", true }, | 26 { FILE_PATH_LITERAL("css"), "text/css", true }, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); | 93 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); |
88 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); | 94 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); |
89 EXPECT_TRUE(IsSupportedMimeType("text/html")); | 95 EXPECT_TRUE(IsSupportedMimeType("text/html")); |
90 EXPECT_TRUE(IsSupportedMimeType("text/banana")); | 96 EXPECT_TRUE(IsSupportedMimeType("text/banana")); |
91 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); | 97 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); |
92 EXPECT_FALSE(IsSupportedMimeType("application/virus")); | 98 EXPECT_FALSE(IsSupportedMimeType("application/virus")); |
93 EXPECT_FALSE(IsSupportedMimeType("application/x-json")); | 99 EXPECT_FALSE(IsSupportedMimeType("application/x-json")); |
94 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); | 100 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); |
95 } | 101 } |
96 | 102 |
103 TEST(MimeUtilTest, StrictMediaMimeType) { | |
104 EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); | |
105 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); | |
106 | |
107 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); | |
108 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); | |
109 | |
110 EXPECT_TRUE_NON_ANDROID(IsStrictMediaMimeType("video/ogg")); | |
111 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg")); | |
112 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg")); | |
113 | |
114 // TODO(amogh.bihani): Fix these test when bug 53193 is fixed. | |
115 // http://crbug.com/53193 ---------------------------------------------------- | |
116 EXPECT_FALSE(IsStrictMediaMimeType("audio/mpeg")); | |
117 EXPECT_FALSE(IsStrictMediaMimeType("audio/mp3")); | |
118 EXPECT_FALSE(IsStrictMediaMimeType("audio/x-mp3")); | |
119 | |
120 EXPECT_FALSE(IsStrictMediaMimeType("video/mp4")); | |
121 EXPECT_FALSE(IsStrictMediaMimeType("video/x-mp4v")); | |
122 EXPECT_FALSE(IsStrictMediaMimeType("audio/mp4")); | |
123 EXPECT_FALSE(IsStrictMediaMimeType("audio/x-mp4a")); | |
124 | |
125 EXPECT_FALSE(IsStrictMediaMimeType("application/x-mpegurl")); | |
126 EXPECT_FALSE(IsStrictMediaMimeType("application/vnd.apple.mpegurl")); | |
127 // --------------------------------------------------------------------------- | |
128 | |
129 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown")); | |
130 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); | |
131 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); | |
132 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); | |
133 } | |
134 | |
97 TEST(MimeUtilTest, MatchesMimeType) { | 135 TEST(MimeUtilTest, MatchesMimeType) { |
98 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); | 136 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); |
99 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); | 137 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); |
100 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); | 138 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); |
101 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); | 139 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); |
102 EXPECT_TRUE(MatchesMimeType("application/*+xml", | 140 EXPECT_TRUE(MatchesMimeType("application/*+xml", |
103 "application/html+xml")); | 141 "application/html+xml")); |
104 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); | 142 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); |
105 EXPECT_TRUE(MatchesMimeType("application/*+json", | 143 EXPECT_TRUE(MatchesMimeType("application/*+json", |
106 "application/x-myformat+json")); | 144 "application/x-myformat+json")); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 std::string post_data; | 359 std::string post_data; |
322 AddMultipartValueForUpload("value name", "value", "boundary", | 360 AddMultipartValueForUpload("value name", "value", "boundary", |
323 "content type", &post_data); | 361 "content type", &post_data); |
324 AddMultipartValueForUpload("value name", "value", "boundary", | 362 AddMultipartValueForUpload("value name", "value", "boundary", |
325 "", &post_data); | 363 "", &post_data); |
326 AddMultipartFinalDelimiterForUpload("boundary", &post_data); | 364 AddMultipartFinalDelimiterForUpload("boundary", &post_data); |
327 EXPECT_STREQ(ref_output, post_data.c_str()); | 365 EXPECT_STREQ(ref_output, post_data.c_str()); |
328 } | 366 } |
329 | 367 |
330 } // namespace net | 368 } // namespace net |
OLD | NEW |