Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: media/webm/webm_webvtt_parser_unittest.cc

Issue 13419002: Media Source dispatches inband text tracks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/webm/webm_webvtt_parser.cc ('k') | webkit/media/android/media_source_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/webm/webm_webvtt_parser_unittest.cc
diff --git a/media/webm/webm_webvtt_parser_unittest.cc b/media/webm/webm_webvtt_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ef744eba5c9e467714f2d4bc4523c04d4b3ccf4
--- /dev/null
+++ b/media/webm/webm_webvtt_parser_unittest.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/webm/webm_webvtt_parser.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::InSequence;
+
+namespace media {
+
+typedef std::vector<uint8> Cue;
+
+static Cue EncodeCue(const std::string& id,
+ const std::string& settings,
+ const std::string& content) {
+ const std::string result = id + '\n' + settings + '\n' + content;
+ const uint8* const buf = reinterpret_cast<const uint8*>(result.data());
+ return Cue(buf, buf + result.length());
+}
+
+static void DecodeCue(const Cue& cue,
+ std::string* id,
+ std::string* settings,
+ std::string* content) {
+ WebMWebVTTParser::Parse(&cue[0], static_cast<int>(cue.size()),
+ id, settings, content);
+}
+
+class WebMWebVTTParserTest : public testing::Test {
+ public:
+ WebMWebVTTParserTest() {}
+};
+
+TEST_F(WebMWebVTTParserTest, TestBlank) {
+ InSequence s;
+
+ const Cue cue = EncodeCue("", "", "Subtitle");
+ std::string id, settings, content;
+
+ DecodeCue(cue, &id, &settings, &content);
+ EXPECT_EQ(id, "");
+ EXPECT_EQ(settings, "");
+ EXPECT_EQ(content, "Subtitle");
+}
+
+TEST_F(WebMWebVTTParserTest, TestId) {
+ InSequence s;
+
+ for (int i = 1; i <= 9; ++i) {
+ const std::string idsrc(1, '0'+i);
+ const Cue cue = EncodeCue(idsrc, "", "Subtitle");
+ std::string id, settings, content;
+
+ DecodeCue(cue, &id, &settings, &content);
+ EXPECT_EQ(id, idsrc);
+ EXPECT_EQ(settings, "");
+ EXPECT_EQ(content, "Subtitle");
+ }
+}
+
+TEST_F(WebMWebVTTParserTest, TestSettings) {
+ InSequence s;
+
+ enum { kSettingsCount = 4 };
+ const char* const settings_str[kSettingsCount] = {
+ "vertical:lr",
+ "line:50%",
+ "position:42%",
+ "vertical:rl line:42% position:100%" };
+
+ for (int i = 0; i < kSettingsCount; ++i) {
+ const Cue cue = EncodeCue("", settings_str[i], "Subtitle");
+ std::string id, settings, content;
+
+ DecodeCue(cue, &id, &settings, &content);
+ EXPECT_EQ(id, "");
+ EXPECT_EQ(settings, settings_str[i]);
+ EXPECT_EQ(content, "Subtitle");
+ }
+}
+
+TEST_F(WebMWebVTTParserTest, TestContent) {
+ InSequence s;
+
+ enum { kContentCount = 4 };
+ const char* const content_str[kContentCount] = {
+ "Subtitle",
+ "Another Subtitle",
+ "Yet Another Subtitle",
+ "Another Subtitle\nSplit Across Two Lines" };
+
+ for (int i = 0; i < kContentCount; ++i) {
+ const Cue cue = EncodeCue("", "", content_str[i]);
+ std::string id, settings, content;
+
+ DecodeCue(cue, &id, &settings, &content);
+ EXPECT_EQ(id, "");
+ EXPECT_EQ(settings, "");
+ EXPECT_EQ(content, content_str[i]);
+ }
+}
+
+} // namespace media
« no previous file with comments | « media/webm/webm_webvtt_parser.cc ('k') | webkit/media/android/media_source_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698