Mark WebGL conformance test 'texture-upload-size' as flaky.
[chromium-blink-merge.git] / media / base / audio_video_metadata_extractor_unittest.cc
blob0af6e165e7baa9f58beca2c346e64aa3d14afcf9
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/sha1.h"
8 #include "build/build_config.h"
9 #include "media/base/audio_video_metadata_extractor.h"
10 #include "media/base/test_data_util.h"
11 #include "media/filters/file_data_source.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace media {
16 scoped_ptr<AudioVideoMetadataExtractor> GetExtractor(
17 const std::string& filename,
18 bool extract_attached_images,
19 bool expected_result,
20 double expected_duration,
21 int expected_width,
22 int expected_height) {
23 FileDataSource source;
24 EXPECT_TRUE(source.Initialize(GetTestDataFilePath(filename)));
26 scoped_ptr<AudioVideoMetadataExtractor> extractor(
27 new AudioVideoMetadataExtractor);
28 bool extracted = extractor->Extract(&source, extract_attached_images);
29 EXPECT_EQ(expected_result, extracted);
31 if (!extracted)
32 return extractor.Pass();
34 EXPECT_EQ(expected_duration, extractor->duration());
36 EXPECT_EQ(expected_width, extractor->width());
37 EXPECT_EQ(expected_height, extractor->height());
39 return extractor.Pass();
42 TEST(AudioVideoMetadataExtractorTest, InvalidFile) {
43 GetExtractor("ten_byte_file", true, false, 0, -1, -1);
46 TEST(AudioVideoMetadataExtractorTest, AudioOGG) {
47 scoped_ptr<AudioVideoMetadataExtractor> extractor =
48 GetExtractor("9ch.ogg", true, true, 0, -1, -1);
49 EXPECT_EQ("Processed by SoX", extractor->comment());
51 EXPECT_EQ("ogg", extractor->stream_infos()[0].type);
52 EXPECT_EQ(2u, extractor->stream_infos().size());
54 EXPECT_EQ(0u, extractor->stream_infos()[0].tags.size());
56 EXPECT_EQ(1u, extractor->stream_infos()[1].tags.size());
57 EXPECT_EQ("vorbis", extractor->stream_infos()[1].type);
58 EXPECT_EQ("Processed by SoX",
59 extractor->stream_infos()[1].tags.find("COMMENT")->second);
61 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
64 TEST(AudioVideoMetadataExtractorTest, AudioWAV) {
65 scoped_ptr<AudioVideoMetadataExtractor> extractor =
66 GetExtractor("sfx_u8.wav", true, true, 0, -1, -1);
67 EXPECT_EQ("Lavf54.37.100", extractor->encoder());
68 EXPECT_EQ("Amadeus Pro", extractor->encoded_by());
70 EXPECT_EQ("wav", extractor->stream_infos()[0].type);
71 EXPECT_EQ(2u, extractor->stream_infos().size());
73 EXPECT_EQ(2u, extractor->stream_infos()[0].tags.size());
74 EXPECT_EQ("Lavf54.37.100",
75 extractor->stream_infos()[0].tags.find("encoder")->second);
76 EXPECT_EQ("Amadeus Pro",
77 extractor->stream_infos()[0].tags.find("encoded_by")->second);
79 EXPECT_EQ("pcm_u8", extractor->stream_infos()[1].type);
80 EXPECT_EQ(0u, extractor->stream_infos()[1].tags.size());
82 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
85 TEST(AudioVideoMetadataExtractorTest, VideoWebM) {
86 scoped_ptr<AudioVideoMetadataExtractor> extractor =
87 GetExtractor("bear-320x240-multitrack.webm", true, true, 2, 320, 240);
88 EXPECT_EQ("Lavf53.9.0", extractor->encoder());
90 EXPECT_EQ(6u, extractor->stream_infos().size());
92 EXPECT_EQ("matroska,webm", extractor->stream_infos()[0].type);
93 EXPECT_EQ(1u, extractor->stream_infos()[0].tags.size());
94 EXPECT_EQ("Lavf53.9.0",
95 extractor->stream_infos()[0].tags.find("ENCODER")->second);
97 EXPECT_EQ("vp8", extractor->stream_infos()[1].type);
98 EXPECT_EQ(0u, extractor->stream_infos()[1].tags.size());
100 EXPECT_EQ("vorbis", extractor->stream_infos()[2].type);
101 EXPECT_EQ(0u, extractor->stream_infos()[2].tags.size());
103 EXPECT_EQ("subrip", extractor->stream_infos()[3].type);
104 EXPECT_EQ(0u, extractor->stream_infos()[3].tags.size());
106 EXPECT_EQ("theora", extractor->stream_infos()[4].type);
107 EXPECT_EQ(0u, extractor->stream_infos()[4].tags.size());
109 EXPECT_EQ("pcm_s16le", extractor->stream_infos()[5].type);
110 EXPECT_EQ(1u, extractor->stream_infos()[5].tags.size());
111 EXPECT_EQ("Lavc52.32.0",
112 extractor->stream_infos()[5].tags.find("ENCODER")->second);
114 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
117 #if defined(USE_PROPRIETARY_CODECS)
118 TEST(AudioVideoMetadataExtractorTest, AndroidRotatedMP4Video) {
119 scoped_ptr<AudioVideoMetadataExtractor> extractor =
120 GetExtractor("90rotation.mp4", true, true, 0, 1920, 1080);
122 EXPECT_EQ(90, extractor->rotation());
124 EXPECT_EQ(3u, extractor->stream_infos().size());
126 EXPECT_EQ("mov,mp4,m4a,3gp,3g2,mj2", extractor->stream_infos()[0].type);
127 EXPECT_EQ(4u, extractor->stream_infos()[0].tags.size());
128 EXPECT_EQ(
129 "isom3gp4",
130 extractor->stream_infos()[0].tags.find("compatible_brands")->second);
131 EXPECT_EQ(
132 "2014-02-11 00:39:25",
133 extractor->stream_infos()[0].tags.find("creation_time")->second);
134 EXPECT_EQ("isom",
135 extractor->stream_infos()[0].tags.find("major_brand")->second);
136 EXPECT_EQ("0",
137 extractor->stream_infos()[0].tags.find("minor_version")->second);
139 EXPECT_EQ("h264", extractor->stream_infos()[1].type);
140 EXPECT_EQ(5u, extractor->stream_infos()[1].tags.size());
141 EXPECT_EQ("2014-02-11 00:39:25",
142 extractor->stream_infos()[1].tags.find("creation_time")->second);
143 EXPECT_EQ("VideoHandle",
144 extractor->stream_infos()[1].tags.find("handler_name")->second);
145 EXPECT_EQ("eng", extractor->stream_infos()[1].tags.find("language")->second);
146 EXPECT_EQ("90", extractor->stream_infos()[1].tags.find("rotate")->second);
148 EXPECT_EQ("aac", extractor->stream_infos()[2].type);
149 EXPECT_EQ(3u, extractor->stream_infos()[2].tags.size());
150 EXPECT_EQ("2014-02-11 00:39:25",
151 extractor->stream_infos()[2].tags.find("creation_time")->second);
152 EXPECT_EQ("SoundHandle",
153 extractor->stream_infos()[2].tags.find("handler_name")->second);
154 EXPECT_EQ("eng", extractor->stream_infos()[2].tags.find("language")->second);
156 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
159 TEST(AudioVideoMetadataExtractorTest, AudioMP3) {
160 scoped_ptr<AudioVideoMetadataExtractor> extractor =
161 GetExtractor("id3_png_test.mp3", true, true, 1, -1, -1);
163 EXPECT_EQ("Airbag", extractor->title());
164 EXPECT_EQ("Radiohead", extractor->artist());
165 EXPECT_EQ("OK Computer", extractor->album());
166 EXPECT_EQ(1, extractor->track());
167 EXPECT_EQ("Alternative", extractor->genre());
168 EXPECT_EQ("1997", extractor->date());
169 EXPECT_EQ("Lavf54.4.100", extractor->encoder());
171 EXPECT_EQ(3u, extractor->stream_infos().size());
173 EXPECT_EQ("mp3", extractor->stream_infos()[0].type);
174 EXPECT_EQ(7u, extractor->stream_infos()[0].tags.size());
175 EXPECT_EQ("OK Computer",
176 extractor->stream_infos()[0].tags.find("album")->second);
177 EXPECT_EQ("Radiohead",
178 extractor->stream_infos()[0].tags.find("artist")->second);
179 EXPECT_EQ("1997", extractor->stream_infos()[0].tags.find("date")->second);
180 EXPECT_EQ("Lavf54.4.100",
181 extractor->stream_infos()[0].tags.find("encoder")->second);
182 EXPECT_EQ("Alternative",
183 extractor->stream_infos()[0].tags.find("genre")->second);
184 EXPECT_EQ("Airbag", extractor->stream_infos()[0].tags.find("title")->second);
185 EXPECT_EQ("1", extractor->stream_infos()[0].tags.find("track")->second);
187 EXPECT_EQ("mp3", extractor->stream_infos()[1].type);
188 EXPECT_EQ(0u, extractor->stream_infos()[1].tags.size());
190 EXPECT_EQ("png", extractor->stream_infos()[2].type);
191 EXPECT_EQ(2u, extractor->stream_infos()[2].tags.size());
192 EXPECT_EQ("Other", extractor->stream_infos()[2].tags.find("comment")->second);
193 EXPECT_EQ("", extractor->stream_infos()[2].tags.find("title")->second);
195 EXPECT_EQ(1u, extractor->attached_images_bytes().size());
196 EXPECT_EQ(155752u, extractor->attached_images_bytes()[0].size());
198 EXPECT_EQ("\x89PNG\r\n\x1a\n",
199 extractor->attached_images_bytes()[0].substr(0, 8));
200 EXPECT_EQ("IEND\xae\x42\x60\x82",
201 extractor->attached_images_bytes()[0].substr(
202 extractor->attached_images_bytes()[0].size() - 8, 8));
203 EXPECT_EQ("\xF3\xED\x8F\xC7\xC7\x98\xB9V|p\xC0u!\xB5\x82\xCF\x95\xF0\xCD\xCE",
204 base::SHA1HashString(extractor->attached_images_bytes()[0]));
206 #endif
208 } // namespace media