Fix for browser_plugin_host_browsertest when embedder is not yet available.
[chromium-blink-merge.git] / media / webm / webm_tracks_parser_unittest.cc
blobad001abb9389f8f5cf2e869cfe9b6ef9168ab96e
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 class WebMTracksParserTest : public testing::Test {
19 public:
20 WebMTracksParserTest() {}
23 static void VerifyTextTrackInfo(const uint8* buffer,
24 int buffer_size,
25 TextKind text_kind,
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);
31 EXPECT_GT(result, 0);
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) {
47 InSequence s;
49 TracksBuilder tb;
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) {
58 InSequence s;
60 TracksBuilder tb;
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) {
69 InSequence s;
71 TracksBuilder tb;
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) {
80 InSequence s;
82 TracksBuilder tb;
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) {
91 InSequence s;
93 TracksBuilder tb;
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);
122 } // namespace media