Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / formats / webm / webm_webvtt_parser_unittest.cc
blobecdabd4297543fc7af62584e2033f2aab541f91b
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 "media/formats/webm/webm_webvtt_parser.h"
6 #include "testing/gmock/include/gmock/gmock.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using ::testing::InSequence;
11 namespace media {
13 typedef std::vector<uint8> Cue;
15 static Cue EncodeCue(const std::string& id,
16 const std::string& settings,
17 const std::string& content) {
18 const std::string result = id + '\n' + settings + '\n' + content;
19 const uint8* const buf = reinterpret_cast<const uint8*>(result.data());
20 return Cue(buf, buf + result.length());
23 static void DecodeCue(const Cue& cue,
24 std::string* id,
25 std::string* settings,
26 std::string* content) {
27 WebMWebVTTParser::Parse(&cue[0], static_cast<int>(cue.size()),
28 id, settings, content);
31 class WebMWebVTTParserTest : public testing::Test {
32 public:
33 WebMWebVTTParserTest() {}
36 TEST_F(WebMWebVTTParserTest, Blank) {
37 InSequence s;
39 const Cue cue = EncodeCue("", "", "Subtitle");
40 std::string id, settings, content;
42 DecodeCue(cue, &id, &settings, &content);
43 EXPECT_EQ(id, "");
44 EXPECT_EQ(settings, "");
45 EXPECT_EQ(content, "Subtitle");
48 TEST_F(WebMWebVTTParserTest, Id) {
49 InSequence s;
51 for (int i = 1; i <= 9; ++i) {
52 const std::string idsrc(1, '0'+i);
53 const Cue cue = EncodeCue(idsrc, "", "Subtitle");
54 std::string id, settings, content;
56 DecodeCue(cue, &id, &settings, &content);
57 EXPECT_EQ(id, idsrc);
58 EXPECT_EQ(settings, "");
59 EXPECT_EQ(content, "Subtitle");
63 TEST_F(WebMWebVTTParserTest, Settings) {
64 InSequence s;
66 enum { kSettingsCount = 4 };
67 const char* const settings_str[kSettingsCount] = {
68 "vertical:lr",
69 "line:50%",
70 "position:42%",
71 "vertical:rl line:42% position:100%" };
73 for (int i = 0; i < kSettingsCount; ++i) {
74 const Cue cue = EncodeCue("", settings_str[i], "Subtitle");
75 std::string id, settings, content;
77 DecodeCue(cue, &id, &settings, &content);
78 EXPECT_EQ(id, "");
79 EXPECT_EQ(settings, settings_str[i]);
80 EXPECT_EQ(content, "Subtitle");
84 TEST_F(WebMWebVTTParserTest, Content) {
85 InSequence s;
87 enum { kContentCount = 4 };
88 const char* const content_str[kContentCount] = {
89 "Subtitle",
90 "Another Subtitle",
91 "Yet Another Subtitle",
92 "Another Subtitle\nSplit Across Two Lines" };
94 for (int i = 0; i < kContentCount; ++i) {
95 const Cue cue = EncodeCue("", "", content_str[i]);
96 std::string id, settings, content;
98 DecodeCue(cue, &id, &settings, &content);
99 EXPECT_EQ(id, "");
100 EXPECT_EQ(settings, "");
101 EXPECT_EQ(content, content_str[i]);
105 } // namespace media