Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / media / webm / webm_tracks_parser_unittest.cc
blob1ba3111789212f1f4397c7da828b61d548d21981
1 // Copyright (c) 2013 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 "media/webm/tracks_builder.h"
7 #include "media/webm/webm_constants.h"
8 #include "media/webm/webm_tracks_parser.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using ::testing::InSequence;
13 using ::testing::Return;
14 using ::testing::_;
16 namespace media {
18 static const int kTypeSubtitlesOrCaptions = 0x11;
19 static const int kTypeDescriptionsOrMetadata = 0x21;
21 class WebMTracksParserTest : public testing::Test {
22 public:
23 WebMTracksParserTest() {}
26 static void VerifyTextTrackInfo(const uint8* buffer,
27 int buffer_size,
28 TextKind text_kind,
29 const std::string& name,
30 const std::string& language) {
31 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), false));
33 int result = parser->Parse(buffer, buffer_size);
34 EXPECT_GT(result, 0);
35 EXPECT_EQ(result, buffer_size);
37 const WebMTracksParser::TextTracks& text_tracks = parser->text_tracks();
38 EXPECT_EQ(text_tracks.size(), WebMTracksParser::TextTracks::size_type(1));
40 const WebMTracksParser::TextTracks::const_iterator itr = text_tracks.begin();
41 EXPECT_EQ(itr->first, 1); // track num
43 const WebMTracksParser::TextTrackInfo& info = itr->second;
44 EXPECT_EQ(info.kind, text_kind);
45 EXPECT_TRUE(info.name == name);
46 EXPECT_TRUE(info.language == language);
49 TEST_F(WebMTracksParserTest, SubtitleNoNameNoLang) {
50 InSequence s;
52 TracksBuilder tb;
53 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions,
54 kWebMCodecSubtitles, "", "");
56 const std::vector<uint8> buf = tb.Finish();
57 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "");
60 TEST_F(WebMTracksParserTest, SubtitleYesNameNoLang) {
61 InSequence s;
63 TracksBuilder tb;
64 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions,
65 kWebMCodecSubtitles, "Spock", "");
67 const std::vector<uint8> buf = tb.Finish();
68 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Spock", "");
71 TEST_F(WebMTracksParserTest, SubtitleNoNameYesLang) {
72 InSequence s;
74 TracksBuilder tb;
75 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions,
76 kWebMCodecSubtitles, "", "eng");
78 const std::vector<uint8> buf = tb.Finish();
79 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "", "eng");
82 TEST_F(WebMTracksParserTest, SubtitleYesNameYesLang) {
83 InSequence s;
85 TracksBuilder tb;
86 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions,
87 kWebMCodecSubtitles, "Picard", "fre");
89 const std::vector<uint8> buf = tb.Finish();
90 VerifyTextTrackInfo(&buf[0], buf.size(), kTextSubtitles, "Picard", "fre");
93 TEST_F(WebMTracksParserTest, IgnoringTextTracks) {
94 InSequence s;
96 TracksBuilder tb;
97 tb.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions,
98 kWebMCodecSubtitles, "Subtitles", "fre");
99 tb.AddTrack(2, kWebMTrackTypeSubtitlesOrCaptions,
100 kWebMCodecSubtitles, "Commentary", "fre");
102 const std::vector<uint8> buf = tb.Finish();
103 scoped_ptr<WebMTracksParser> parser(new WebMTracksParser(LogCB(), true));
105 int result = parser->Parse(&buf[0], buf.size());
106 EXPECT_GT(result, 0);
107 EXPECT_EQ(result, static_cast<int>(buf.size()));
109 EXPECT_EQ(parser->text_tracks().size(), 0u);
111 const std::set<int64>& ignored_tracks = parser->ignored_tracks();
112 EXPECT_TRUE(ignored_tracks.find(1) != ignored_tracks.end());
113 EXPECT_TRUE(ignored_tracks.find(2) != ignored_tracks.end());
115 // Test again w/o ignoring the test tracks.
116 parser.reset(new WebMTracksParser(LogCB(), false));
118 result = parser->Parse(&buf[0], buf.size());
119 EXPECT_GT(result, 0);
121 EXPECT_EQ(parser->ignored_tracks().size(), 0u);
122 EXPECT_EQ(parser->text_tracks().size(), 2u);
125 } // namespace media