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

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
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..bbba49a07de28cad31dbd03308011a1ca058bbdc
--- /dev/null
+++ b/media/webm/webm_webvtt_parser_unittest.cc
@@ -0,0 +1,129 @@
+// 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 "base/logging.h"
+#include "media/webm/webm_webvtt_parser.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::InSequence;
+using ::testing::Return;
+using ::testing::_;
+
+namespace media {
+
+class WebMWebVTTParserTest : public testing::Test {
+ public:
+ WebMWebVTTParserTest() {}
+};
+
+TEST_F(WebMWebVTTParserTest, TestBlank) {
+ InSequence s;
+
+ const char* const str = "\n\nSubtitle";
+ const uint8* const buf = reinterpret_cast<const uint8*>(str);
+ const int buflen = static_cast<int>(strlen(str));
+
+ std::string id, settings, content;
+
+ WebMWebVTTParser::Parse(buf, buflen, &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) {
+ std::string strbuf;
+
+ const char c = '0' + i;
+ strbuf += c;
+
+ strbuf += "\n\nSubtitle";
+
+ const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data());
+ const int buflen = static_cast<int>(strbuf.length());
+
+ std::string id, settings, content;
+
+ WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content);
+ ASSERT_EQ(id.length(), 1);
+ EXPECT_EQ(id[0], c);
+ 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) {
+ std::string strbuf;
+
+ // blank id
+ strbuf += "\n";
acolwell GONE FROM CHROMIUM 2013/05/15 22:42:36 nit: If you create a helper function along the lin
Matthew Heaney (Chromium) 2013/05/16 22:05:22 Done.
+
+ // settings
+ strbuf += settings_str[i];
+ strbuf += "\n";
+
+ // content
+ strbuf += "Subtitle";
+
+ const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data());
+ const int buflen = static_cast<int>(strbuf.length());
+
+ std::string id, settings, content;
+
+ WebMWebVTTParser::Parse(buf, buflen, &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) {
+ std::string strbuf;
+
+ // blank id
+ strbuf += "\n";
+
+ // blank settings
+ strbuf += "\n";
+
+ // content
+ strbuf += content_str[i];
+
+ const uint8* const buf = reinterpret_cast<const uint8*>(strbuf.data());
+ const int buflen = static_cast<int>(strbuf.length());
+
+ std::string id, settings, content;
+
+ WebMWebVTTParser::Parse(buf, buflen, &id, &settings, &content);
+ EXPECT_EQ(id, "");
+ EXPECT_EQ(settings, "");
+ EXPECT_EQ(content, content_str[i]);
+ }
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698