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

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

Issue 401523002: Move media related mimetype functionality out of net/ and into media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and add content/common/mime_util.h for realz Created 6 years, 5 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 | Annotate | Revision Log
« content/common/mime_util.cc ('K') | « net/base/mime_util.cc ('k') | no next file » | 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
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard")); 77 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard"));
78 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); 78 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus"));
79 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert")); 79 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert"));
80 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json")); 80 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json"));
81 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json")); 81 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json"));
82 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json")); 82 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json"));
83 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2")); 83 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2"));
84 #if defined(OS_ANDROID) 84 #if defined(OS_ANDROID)
85 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert")); 85 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert"));
86 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12")); 86 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12"));
87 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
88 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl"));
89 #endif 87 #endif
90 88
91 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); 89 EXPECT_TRUE(IsSupportedMimeType("image/jpeg"));
92 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); 90 EXPECT_FALSE(IsSupportedMimeType("image/lolcat"));
93 EXPECT_TRUE(IsSupportedMimeType("text/html")); 91 EXPECT_TRUE(IsSupportedMimeType("text/html"));
94 EXPECT_TRUE(IsSupportedMimeType("text/banana")); 92 EXPECT_TRUE(IsSupportedMimeType("text/banana"));
95 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); 93 EXPECT_FALSE(IsSupportedMimeType("text/vcard"));
96 EXPECT_FALSE(IsSupportedMimeType("application/virus")); 94 EXPECT_FALSE(IsSupportedMimeType("application/virus"));
97 EXPECT_FALSE(IsSupportedMimeType("application/x-json")); 95 EXPECT_FALSE(IsSupportedMimeType("application/x-json"));
98 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); 96 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json"));
99 } 97 }
100 98
101 TEST(MimeUtilTest, StrictMediaMimeType) {
102 EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
103 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
104
105 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
106 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
107
108 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg"));
109 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg"));
110 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg"));
111
112 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg"));
113 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3"));
114 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3"));
115
116 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4"));
117 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v"));
118 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4"));
119 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a"));
120
121 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl"));
122 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl"));
123
124 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown"));
125 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown"));
126 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown"));
127 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown"));
128 }
129
130 TEST(MimeUtilTest, MatchesMimeType) { 99 TEST(MimeUtilTest, MatchesMimeType) {
131 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); 100 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg"));
132 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); 101 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg"));
133 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); 102 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
134 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); 103 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg"));
135 EXPECT_TRUE(MatchesMimeType("application/*+xml", 104 EXPECT_TRUE(MatchesMimeType("application/*+xml",
136 "application/html+xml")); 105 "application/html+xml"));
137 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); 106 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml"));
138 EXPECT_TRUE(MatchesMimeType("application/*+json", 107 EXPECT_TRUE(MatchesMimeType("application/*+json",
139 "application/x-myformat+json")); 108 "application/x-myformat+json"));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 EXPECT_FALSE(MatchesMimeType("video/*", "*/*")); 153 EXPECT_FALSE(MatchesMimeType("video/*", "*/*"));
185 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*")); 154 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*"));
186 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val")); 155 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val"));
187 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2")); 156 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2"));
188 157
189 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd")); 158 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd"));
190 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd")); 159 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd"));
191 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd")); 160 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd"));
192 } 161 }
193 162
194 TEST(MimeUtilTest, CommonMediaMimeType) {
195 #if defined(OS_ANDROID)
196 bool HLSSupported;
197 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14)
198 HLSSupported = false;
199 else
200 HLSSupported = true;
201 #endif
202
203 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm"));
204 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm"));
205
206 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav"));
207 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav"));
208
209 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg"));
210 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg"));
211 #if defined(OS_ANDROID)
212 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg"));
213 EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl"));
214 EXPECT_EQ(HLSSupported,
215 IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
216 #else
217 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg"));
218 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl"));
219 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
220 #endif // OS_ANDROID
221
222 #if defined(USE_PROPRIETARY_CODECS)
223 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4"));
224 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a"));
225 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4"));
226 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v"));
227
228 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3"));
229 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3"));
230 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg"));
231 #else
232 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4"));
233 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a"));
234 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4"));
235 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v"));
236
237 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3"));
238 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3"));
239 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg"));
240 #endif // USE_PROPRIETARY_CODECS
241 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3"));
242
243 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
244 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
245 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
246 }
247
248 // Note: codecs should only be a list of 2 or fewer; hence the restriction of
249 // results' length to 2.
250 TEST(MimeUtilTest, ParseCodecString) {
251 const struct {
252 const char* original;
253 size_t expected_size;
254 const char* results[2];
255 } tests[] = {
256 { "\"bogus\"", 1, { "bogus" } },
257 { "0", 1, { "0" } },
258 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
259 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
260 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
261 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
262 { "", 0, { } },
263 { "\"\"", 0, { } },
264 { "\" \"", 0, { } },
265 { ",", 2, { "", "" } },
266 };
267
268 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
269 std::vector<std::string> codecs_out;
270 ParseCodecString(tests[i].original, &codecs_out, true);
271 ASSERT_EQ(tests[i].expected_size, codecs_out.size());
272 for (size_t j = 0; j < tests[i].expected_size; ++j)
273 EXPECT_EQ(tests[i].results[j], codecs_out[j]);
274 }
275
276 // Test without stripping the codec type.
277 std::vector<std::string> codecs_out;
278 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
279 ASSERT_EQ(2u, codecs_out.size());
280 EXPECT_EQ("avc1.42E01E", codecs_out[0]);
281 EXPECT_EQ("mp4a.40.2", codecs_out[1]);
282 }
283 163
284 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) { 164 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) {
285 std::string nonAscii("application/nonutf8"); 165 std::string nonAscii("application/nonutf8");
286 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); 166 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
287 #if defined(OS_WIN) 167 #if defined(OS_WIN)
288 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603"))); 168 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603")));
289 #else 169 #else
290 nonAscii.append("\u2603"); // unicode snowman 170 nonAscii.append("\u2603"); // unicode snowman
291 #endif 171 #endif
292 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); 172 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 std::string post_data; 324 std::string post_data;
445 AddMultipartValueForUpload("value name", "value", "boundary", 325 AddMultipartValueForUpload("value name", "value", "boundary",
446 "content type", &post_data); 326 "content type", &post_data);
447 AddMultipartValueForUpload("value name", "value", "boundary", 327 AddMultipartValueForUpload("value name", "value", "boundary",
448 "", &post_data); 328 "", &post_data);
449 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 329 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
450 EXPECT_STREQ(ref_output, post_data.c_str()); 330 EXPECT_STREQ(ref_output, post_data.c_str());
451 } 331 }
452 332
453 } // namespace net 333 } // namespace net
OLDNEW
« content/common/mime_util.cc ('K') | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698