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

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

Issue 2700893003: Various MimeUtil cleanups. (Closed)
Patch Set: Fix default codecs return Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "media/base/mime_util.h" 11 #include "media/base/mime_util.h"
12 #include "media/base/mime_util_internal.h" 12 #include "media/base/mime_util_internal.h"
13 #include "media/media_features.h" 13 #include "media/media_features.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
17 #include "base/android/build_info.h" 17 #include "base/android/build_info.h"
18 #endif 18 #endif
19 19
20 namespace media { 20 namespace media {
21 namespace internal { 21 namespace internal {
22 22
23 // MIME type for use with IsCodecSupportedOnPlatform() test; type is ignored in 23 // MIME type for use with IsCodecSupportedOnAndroid() test; type is ignored in
24 // all cases except for when paired with the Opus codec. 24 // all cases except for when paired with the Opus codec.
25 const char kTestMimeType[] = "foo/foo"; 25 const char kTestMimeType[] = "foo/foo";
26 26
27 // Helper method for creating a multi-value vector of |kTestStates| if 27 // Helper method for creating a multi-value vector of |kTestStates| if
28 // |test_all_values| is true or if false, a single value vector containing 28 // |test_all_values| is true or if false, a single value vector containing
29 // |single_value|. 29 // |single_value|.
30 static std::vector<bool> CreateTestVector(bool test_all_values, 30 static std::vector<bool> CreateTestVector(bool test_all_values,
31 bool single_value) { 31 bool single_value) {
32 const bool kTestStates[] = {true, false}; 32 const bool kTestStates[] = {true, false};
33 if (test_all_values) 33 if (test_all_values)
34 return std::vector<bool>(kTestStates, kTestStates + arraysize(kTestStates)); 34 return std::vector<bool>(kTestStates, kTestStates + arraysize(kTestStates));
35 return std::vector<bool>(1, single_value); 35 return std::vector<bool>(1, single_value);
36 } 36 }
37 37
38 // Helper method for running IsCodecSupportedOnPlatform() tests that will 38 // Helper method for running IsCodecSupportedOnAndroid() tests that will
39 // iterate over all possible field values for a MimeUtil::PlatformInfo struct. 39 // iterate over all possible field values for a MimeUtil::PlatformInfo struct.
40 // 40 //
41 // To request a field be varied, set its value to true in the |states_to_vary| 41 // To request a field be varied, set its value to true in the |states_to_vary|
42 // struct. If false, the only value tested will be the field value from 42 // struct. If false, the only value tested will be the field value from
43 // |test_states|. 43 // |test_states|.
44 // 44 //
45 // |test_func| should have the signature <void(const MimeUtil::PlatformInfo&, 45 // |test_func| should have the signature <void(const MimeUtil::PlatformInfo&,
46 // MimeUtil::Codec)>. 46 // MimeUtil::Codec)>.
47 template <typename TestCallback> 47 template <typename TestCallback>
48 static void RunCodecSupportTest(const MimeUtil::PlatformInfo& states_to_vary, 48 static void RunCodecSupportTest(const MimeUtil::PlatformInfo& states_to_vary,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 #endif // USE_PROPRIETARY_CODECS 172 #endif // USE_PROPRIETARY_CODECS
173 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3")); 173 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3"));
174 174
175 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); 175 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
176 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); 176 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
177 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); 177 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
178 } 178 }
179 179
180 // Note: codecs should only be a list of 2 or fewer; hence the restriction of 180 // Note: codecs should only be a list of 2 or fewer; hence the restriction of
181 // results' length to 2. 181 // results' length to 2.
182 TEST(MimeUtilTest, ParseCodecString) { 182 TEST(MimeUtilTest, SplitCodecsToVector) {
183 const struct { 183 const struct {
184 const char* const original; 184 const char* const original;
185 size_t expected_size; 185 size_t expected_size;
186 const char* const results[2]; 186 const char* const results[2];
187 } tests[] = { 187 } tests[] = {
188 { "\"bogus\"", 1, { "bogus" } }, 188 { "\"bogus\"", 1, { "bogus" } },
189 { "0", 1, { "0" } }, 189 { "0", 1, { "0" } },
190 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, 190 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
191 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, 191 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
192 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, 192 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
193 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, 193 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
194 { "", 0, { } }, 194 { "", 0, { } },
195 { "\"\"", 0, { } }, 195 { "\"\"", 0, { } },
196 { "\" \"", 0, { } }, 196 { "\" \"", 0, { } },
197 { ",", 2, { "", "" } }, 197 { ",", 2, { "", "" } },
198 }; 198 };
199 199
200 for (size_t i = 0; i < arraysize(tests); ++i) { 200 for (size_t i = 0; i < arraysize(tests); ++i) {
201 std::vector<std::string> codecs_out; 201 std::vector<std::string> codecs_out;
202 ParseCodecString(tests[i].original, &codecs_out, true); 202 SplitCodecsToVector(tests[i].original, &codecs_out, true);
203 ASSERT_EQ(tests[i].expected_size, codecs_out.size()); 203 ASSERT_EQ(tests[i].expected_size, codecs_out.size());
204 for (size_t j = 0; j < tests[i].expected_size; ++j) 204 for (size_t j = 0; j < tests[i].expected_size; ++j)
205 EXPECT_EQ(tests[i].results[j], codecs_out[j]); 205 EXPECT_EQ(tests[i].results[j], codecs_out[j]);
206 } 206 }
207 207
208 // Test without stripping the codec type. 208 // Test without stripping the codec type.
209 std::vector<std::string> codecs_out; 209 std::vector<std::string> codecs_out;
210 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); 210 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false);
211 ASSERT_EQ(2u, codecs_out.size()); 211 ASSERT_EQ(2u, codecs_out.size());
212 EXPECT_EQ("avc1.42E01E", codecs_out[0]); 212 EXPECT_EQ("avc1.42E01E", codecs_out[0]);
213 EXPECT_EQ("mp4a.40.2", codecs_out[1]); 213 EXPECT_EQ("mp4a.40.2", codecs_out[1]);
214 } 214 }
215 215
216 TEST(IsCodecSupportedOnPlatformTest, 216 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) {
217 EncryptedCodecsFailWithoutPlatformSupport) {
218 // Vary all parameters except |has_platform_decoders|. 217 // Vary all parameters except |has_platform_decoders|.
219 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); 218 MimeUtil::PlatformInfo states_to_vary = VaryAllFields();
220 states_to_vary.has_platform_decoders = false; 219 states_to_vary.has_platform_decoders = false;
221 220
222 // Disable platform decoders. 221 // Disable platform decoders.
223 MimeUtil::PlatformInfo test_states; 222 MimeUtil::PlatformInfo test_states;
224 test_states.has_platform_decoders = false; 223 test_states.has_platform_decoders = false;
225 224
226 // Every codec should fail since platform support is missing and we've 225 // Every codec should fail since platform support is missing and we've
227 // requested encrypted codecs. 226 // requested encrypted codecs.
228 RunCodecSupportTest( 227 RunCodecSupportTest(
229 states_to_vary, test_states, 228 states_to_vary, test_states,
230 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { 229 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) {
231 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, 230 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid(codec, kTestMimeType,
232 true, info)); 231 true, info));
233 }); 232 });
234 } 233 }
235 234
236 TEST(IsCodecSupportedOnPlatformTest, EncryptedCodecBehavior) { 235 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecBehavior) {
237 // Vary all parameters except |has_platform_decoders|. 236 // Vary all parameters except |has_platform_decoders|.
238 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); 237 MimeUtil::PlatformInfo states_to_vary = VaryAllFields();
239 states_to_vary.has_platform_decoders = false; 238 states_to_vary.has_platform_decoders = false;
240 239
241 // Enable platform decoders. 240 // Enable platform decoders.
242 MimeUtil::PlatformInfo test_states; 241 MimeUtil::PlatformInfo test_states;
243 test_states.has_platform_decoders = true; 242 test_states.has_platform_decoders = true;
244 243
245 RunCodecSupportTest( 244 RunCodecSupportTest(
246 states_to_vary, test_states, 245 states_to_vary, test_states,
247 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { 246 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) {
248 const bool result = MimeUtil::IsCodecSupportedOnPlatform( 247 const bool result = MimeUtil::IsCodecSupportedOnAndroid(
249 codec, kTestMimeType, true, info); 248 codec, kTestMimeType, true, info);
250 switch (codec) { 249 switch (codec) {
251 // These codecs are never supported by the Android platform. 250 // These codecs are never supported by the Android platform.
252 case MimeUtil::INVALID_CODEC: 251 case MimeUtil::INVALID_CODEC:
253 case MimeUtil::AC3: 252 case MimeUtil::AC3:
254 case MimeUtil::EAC3: 253 case MimeUtil::EAC3:
255 case MimeUtil::MPEG2_AAC: 254 case MimeUtil::MPEG2_AAC:
256 case MimeUtil::THEORA: 255 case MimeUtil::THEORA:
257 EXPECT_FALSE(result); 256 EXPECT_FALSE(result);
258 break; 257 break;
(...skipping 22 matching lines...) Expand all
281 EXPECT_EQ(info.has_platform_vp9_decoder, result); 280 EXPECT_EQ(info.has_platform_vp9_decoder, result);
282 break; 281 break;
283 282
284 case MimeUtil::HEVC: 283 case MimeUtil::HEVC:
285 EXPECT_EQ(HasHevcSupport(), result); 284 EXPECT_EQ(HasHevcSupport(), result);
286 break; 285 break;
287 } 286 }
288 }); 287 });
289 } 288 }
290 289
291 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehavior) { 290 TEST(IsCodecSupportedOnAndroidTest, ClearCodecBehavior) {
292 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); 291 MimeUtil::PlatformInfo states_to_vary = VaryAllFields();
293 292
294 MimeUtil::PlatformInfo test_states; 293 MimeUtil::PlatformInfo test_states;
295 294
296 RunCodecSupportTest( 295 RunCodecSupportTest(
297 states_to_vary, test_states, 296 states_to_vary, test_states,
298 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { 297 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) {
299 const bool result = MimeUtil::IsCodecSupportedOnPlatform( 298 const bool result = MimeUtil::IsCodecSupportedOnAndroid(
300 codec, kTestMimeType, false, info); 299 codec, kTestMimeType, false, info);
301 switch (codec) { 300 switch (codec) {
302 // These codecs are never supported by the Android platform. 301 // These codecs are never supported by the Android platform.
303 case MimeUtil::INVALID_CODEC: 302 case MimeUtil::INVALID_CODEC:
304 case MimeUtil::AC3: 303 case MimeUtil::AC3:
305 case MimeUtil::EAC3: 304 case MimeUtil::EAC3:
306 case MimeUtil::THEORA: 305 case MimeUtil::THEORA:
307 EXPECT_FALSE(result); 306 EXPECT_FALSE(result);
308 break; 307 break;
309 308
(...skipping 15 matching lines...) Expand all
325 EXPECT_EQ(info.has_platform_decoders, result); 324 EXPECT_EQ(info.has_platform_decoders, result);
326 break; 325 break;
327 326
328 case MimeUtil::HEVC: 327 case MimeUtil::HEVC:
329 EXPECT_EQ(HasHevcSupport() && info.has_platform_decoders, result); 328 EXPECT_EQ(HasHevcSupport() && info.has_platform_decoders, result);
330 break; 329 break;
331 } 330 }
332 }); 331 });
333 } 332 }
334 333
335 TEST(IsCodecSupportedOnPlatformTest, OpusOggSupport) { 334 TEST(IsCodecSupportedOnAndroidTest, OpusOggSupport) {
336 // Vary all parameters; thus use default initial state. 335 // Vary all parameters; thus use default initial state.
337 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); 336 MimeUtil::PlatformInfo states_to_vary = VaryAllFields();
338 MimeUtil::PlatformInfo test_states; 337 MimeUtil::PlatformInfo test_states;
339 338
340 RunCodecSupportTest( 339 RunCodecSupportTest(
341 states_to_vary, test_states, 340 states_to_vary, test_states,
342 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { 341 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) {
343 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( 342 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnAndroid(
344 MimeUtil::OPUS, "audio/ogg", false, info)); 343 MimeUtil::OPUS, "audio/ogg", false, info));
345 }); 344 });
346 } 345 }
347 346
348 TEST(IsCodecSupportedOnPlatformTest, HLSDoesNotSupportMPEG2AAC) { 347 TEST(IsCodecSupportedOnAndroidTest, HLSDoesNotSupportMPEG2AAC) {
349 // Vary all parameters; thus use default initial state. 348 // Vary all parameters; thus use default initial state.
350 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); 349 MimeUtil::PlatformInfo states_to_vary = VaryAllFields();
351 MimeUtil::PlatformInfo test_states; 350 MimeUtil::PlatformInfo test_states;
352 351
353 RunCodecSupportTest( 352 RunCodecSupportTest(
354 states_to_vary, test_states, 353 states_to_vary, test_states,
355 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { 354 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) {
356 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( 355 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid(
357 MimeUtil::MPEG2_AAC, "application/x-mpegurl", false, info)); 356 MimeUtil::MPEG2_AAC, "application/x-mpegurl", false, info));
358 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( 357 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid(
359 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); 358 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info));
360 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( 359 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid(
361 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); 360 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info));
362 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( 361 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid(
363 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); 362 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info));
364 }); 363 });
365 } 364 }
366 365
367 } // namespace internal 366 } // namespace internal
368 } // namespace media 367 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698