Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / base / audio_video_metadata_extractor_unittest.cc
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.
4
5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "build/build_config.h"
8 #include "media/base/audio_video_metadata_extractor.h"
9 #include "media/base/test_data_util.h"
10 #include "media/filters/file_data_source.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace media {
14
15 scoped_ptr<AudioVideoMetadataExtractor> GetExtractor(
16     const std::string& filename,
17     bool expected_result,
18     double expected_duration,
19     int expected_width,
20     int expected_height) {
21   FileDataSource source;
22   EXPECT_TRUE(source.Initialize(GetTestDataFilePath(filename)));
23
24   scoped_ptr<AudioVideoMetadataExtractor> extractor(
25       new AudioVideoMetadataExtractor);
26   bool extracted = extractor->Extract(&source);
27   EXPECT_EQ(expected_result, extracted);
28
29   if (!extracted)
30     return extractor.Pass();
31
32   EXPECT_EQ(expected_duration, extractor->duration());
33
34   EXPECT_EQ(expected_width, extractor->width());
35   EXPECT_EQ(expected_height, extractor->height());
36
37   return extractor.Pass();
38 }
39
40 TEST(AudioVideoMetadataExtractorTest, InvalidFile) {
41   GetExtractor("ten_byte_file", false, 0, -1, -1);
42 }
43
44 TEST(AudioVideoMetadataExtractorTest, AudioOGG) {
45   scoped_ptr<AudioVideoMetadataExtractor> extractor =
46       GetExtractor("9ch.ogg", true, 0, -1, -1);
47   EXPECT_EQ("Processed by SoX", extractor->comment());
48 }
49
50 TEST(AudioVideoMetadataExtractorTest, AudioWAV) {
51   scoped_ptr<AudioVideoMetadataExtractor> extractor =
52       GetExtractor("sfx_u8.wav", true, 0, -1, -1);
53   EXPECT_EQ("Lavf54.37.100", extractor->encoder());
54   EXPECT_EQ("Amadeus Pro", extractor->encoded_by());
55 }
56
57 TEST(AudioVideoMetadataExtractorTest, VideoWebM) {
58   scoped_ptr<AudioVideoMetadataExtractor> extractor =
59       GetExtractor("bear-320x240-multitrack.webm", true, 2, 320, 240);
60   EXPECT_EQ("Lavf53.9.0", extractor->encoder());
61 }
62
63 #if defined(USE_PROPRIETARY_CODECS)
64 TEST(AudioVideoMetadataExtractorTest, AndroidRotatedMP4Video) {
65   scoped_ptr<AudioVideoMetadataExtractor> extractor =
66       GetExtractor("90rotation.mp4", true, 0, 1920, 1080);
67
68   EXPECT_EQ(90, extractor->rotation());
69 }
70
71 TEST(AudioVideoMetadataExtractorTest, AudioMP3) {
72   scoped_ptr<AudioVideoMetadataExtractor> extractor =
73       GetExtractor("id3_png_test.mp3", true, 1, -1, -1);
74
75   EXPECT_EQ("Airbag", extractor->title());
76   EXPECT_EQ("Radiohead", extractor->artist());
77   EXPECT_EQ("OK Computer", extractor->album());
78   EXPECT_EQ(1, extractor->track());
79   EXPECT_EQ("Alternative", extractor->genre());
80   EXPECT_EQ("1997", extractor->date());
81   EXPECT_EQ("Lavf54.4.100", extractor->encoder());
82 }
83 #endif
84
85 }  // namespace media