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
;
18 class WebMTracksParserTest
: public testing::Test
{
20 WebMTracksParserTest() {}
23 static void VerifyTextTrackInfo(const uint8
* buffer
,
26 const std::string
& name
,
27 const std::string
& language
) {
28 scoped_ptr
<WebMTracksParser
> parser(new WebMTracksParser(LogCB(), false));
30 int result
= parser
->Parse(buffer
, buffer_size
);
32 EXPECT_EQ(result
, buffer_size
);
34 const WebMTracksParser::TextTracks
& text_tracks
= parser
->text_tracks();
35 EXPECT_EQ(text_tracks
.size(), WebMTracksParser::TextTracks::size_type(1));
37 const WebMTracksParser::TextTracks::const_iterator itr
= text_tracks
.begin();
38 EXPECT_EQ(itr
->first
, 1); // track num
40 const WebMTracksParser::TextTrackInfo
& info
= itr
->second
;
41 EXPECT_EQ(info
.kind
, text_kind
);
42 EXPECT_TRUE(info
.name
== name
);
43 EXPECT_TRUE(info
.language
== language
);
46 TEST_F(WebMTracksParserTest
, SubtitleNoNameNoLang
) {
50 tb
.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions
,
51 kWebMCodecSubtitles
, "", "");
53 const std::vector
<uint8
> buf
= tb
.Finish();
54 VerifyTextTrackInfo(&buf
[0], buf
.size(), kTextSubtitles
, "", "");
57 TEST_F(WebMTracksParserTest
, SubtitleYesNameNoLang
) {
61 tb
.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions
,
62 kWebMCodecSubtitles
, "Spock", "");
64 const std::vector
<uint8
> buf
= tb
.Finish();
65 VerifyTextTrackInfo(&buf
[0], buf
.size(), kTextSubtitles
, "Spock", "");
68 TEST_F(WebMTracksParserTest
, SubtitleNoNameYesLang
) {
72 tb
.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions
,
73 kWebMCodecSubtitles
, "", "eng");
75 const std::vector
<uint8
> buf
= tb
.Finish();
76 VerifyTextTrackInfo(&buf
[0], buf
.size(), kTextSubtitles
, "", "eng");
79 TEST_F(WebMTracksParserTest
, SubtitleYesNameYesLang
) {
83 tb
.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions
,
84 kWebMCodecSubtitles
, "Picard", "fre");
86 const std::vector
<uint8
> buf
= tb
.Finish();
87 VerifyTextTrackInfo(&buf
[0], buf
.size(), kTextSubtitles
, "Picard", "fre");
90 TEST_F(WebMTracksParserTest
, IgnoringTextTracks
) {
94 tb
.AddTrack(1, kWebMTrackTypeSubtitlesOrCaptions
,
95 kWebMCodecSubtitles
, "Subtitles", "fre");
96 tb
.AddTrack(2, kWebMTrackTypeSubtitlesOrCaptions
,
97 kWebMCodecSubtitles
, "Commentary", "fre");
99 const std::vector
<uint8
> buf
= tb
.Finish();
100 scoped_ptr
<WebMTracksParser
> parser(new WebMTracksParser(LogCB(), true));
102 int result
= parser
->Parse(&buf
[0], buf
.size());
103 EXPECT_GT(result
, 0);
104 EXPECT_EQ(result
, static_cast<int>(buf
.size()));
106 EXPECT_EQ(parser
->text_tracks().size(), 0u);
108 const std::set
<int64
>& ignored_tracks
= parser
->ignored_tracks();
109 EXPECT_TRUE(ignored_tracks
.find(1) != ignored_tracks
.end());
110 EXPECT_TRUE(ignored_tracks
.find(2) != ignored_tracks
.end());
112 // Test again w/o ignoring the test tracks.
113 parser
.reset(new WebMTracksParser(LogCB(), false));
115 result
= parser
->Parse(&buf
[0], buf
.size());
116 EXPECT_GT(result
, 0);
118 EXPECT_EQ(parser
->ignored_tracks().size(), 0u);
119 EXPECT_EQ(parser
->text_tracks().size(), 2u);