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

Unified Diff: media/webm/webm_cluster_parser_unittest.cc

Issue 10829470: Support for parsing encrypted WebM streams by src. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments Created 7 years, 9 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_cluster_parser.cc ('k') | media/webm/webm_crypto_helpers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/webm/webm_cluster_parser_unittest.cc
diff --git a/media/webm/webm_cluster_parser_unittest.cc b/media/webm/webm_cluster_parser_unittest.cc
index 07deb05515ac7c3256b92a250178ec3c1722d579..2b906d0a0d2ebbd2d671b8ff7129d8c6e0efdf60 100644
--- a/media/webm/webm_cluster_parser_unittest.cc
+++ b/media/webm/webm_cluster_parser_unittest.cc
@@ -67,6 +67,23 @@ static scoped_ptr<Cluster> CreateCluster(int timecode,
return cb.Finish();
}
+static const uint8 kEncryptedFrame[] = {
ddorwin 2013/03/12 19:31:02 Please move up with other constants.
fgalligan1 2013/03/13 17:58:09 Done.
+ 0x01, // Block is encrypted
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 // IV
+};
+
+// Creates a Cluster with one encrypted Block. |bytes_to_write| is number of
+// bytes of the encrypted frame to write.
+static scoped_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) {
+ CHECK_GT(bytes_to_write, 0);
+ CHECK_LE(bytes_to_write, static_cast<int>(sizeof(kEncryptedFrame)));
+
+ ClusterBuilder cb;
+ cb.SetClusterTimecode(0);
+ cb.AddSimpleBlock(kVideoTrackNum, 0, 0, kEncryptedFrame, bytes_to_write);
+ return cb.Finish();
+}
+
static bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers,
const WebMClusterParser::BufferQueue& video_buffers,
const WebMClusterParser::BufferQueue& text_buffers,
@@ -165,6 +182,13 @@ static bool VerifyTextBuffers(
return true;
}
+static bool VerifyEncryptedFrame(
ddorwin 2013/03/12 19:31:02 IsEncryptedFrame(). The verification is at the cal
fgalligan1 2013/03/13 17:58:09 Done.
+ const WebMClusterParser::BufferQueue& video_buffers) {
ddorwin 2013/03/12 19:31:02 Since this just verifies one frame, it should only
fgalligan1 2013/03/13 17:58:09 Done.
+ scoped_refptr<StreamParserBuffer> buffer = video_buffers[0];
+ const uint8* data = buffer->GetData();
+ return data[0] & kWebMFlagEncryptedFrame;
+}
+
static void AppendToEnd(const WebMClusterParser::BufferQueue& src,
WebMClusterParser::BufferQueue* dest) {
for (WebMClusterParser::BufferQueue::const_iterator itr = src.begin();
@@ -440,4 +464,30 @@ TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) {
}
}
+TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
+ scoped_ptr<Cluster> cluster(CreateEncryptedCluster(sizeof(kEncryptedFrame)));
+
+ parser_.reset(new WebMClusterParser(
+ kTimecodeScale, kAudioTrackNum, kVideoTrackNum,
+ std::set<int>(),
+ std::set<int64>(), "", "video_key_id",
+ LogCB()));
+ int result = parser_->Parse(cluster->data(), cluster->size());
+ EXPECT_EQ(cluster->size(), result);
+ EXPECT_TRUE(VerifyEncryptedFrame(parser_->video_buffers()));
ddorwin 2013/03/12 19:31:02 The implementation of this really just checks the
fgalligan1 2013/03/13 17:58:09 Done. PTAL
+}
+
+TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) {
+ scoped_ptr<Cluster> cluster(
+ CreateEncryptedCluster(sizeof(kEncryptedFrame) - 1));
+
+ parser_.reset(new WebMClusterParser(
+ kTimecodeScale, kAudioTrackNum, kVideoTrackNum,
+ std::set<int>(),
+ std::set<int64>(), "", "video_key_id",
+ LogCB()));
+ int result = parser_->Parse(cluster->data(), cluster->size());
+ EXPECT_EQ(-1, result);
+}
+
} // namespace media
« no previous file with comments | « media/webm/webm_cluster_parser.cc ('k') | media/webm/webm_crypto_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698