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

Unified Diff: chrome/browser/media/webrtc_rtp_dump_handler_unittest.cc

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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: chrome/browser/media/webrtc_rtp_dump_handler_unittest.cc
diff --git a/chrome/browser/media/webrtc_rtp_dump_handler_unittest.cc b/chrome/browser/media/webrtc_rtp_dump_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6051e2f01b2883ba8ac943e55aeb81a8bade50c8
--- /dev/null
+++ b/chrome/browser/media/webrtc_rtp_dump_handler_unittest.cc
@@ -0,0 +1,183 @@
+// Copyright 2014 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/bind.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
+#include "chrome/browser/media/webrtc_rtp_dump_handler.h"
+#include "chrome/browser/media/webrtc_rtp_dump_writer.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FakeDumpWriter : public WebRtcRtpDumpWriter {
+ public:
+ explicit FakeDumpWriter(size_t max_dump_size,
+ const base::Closure& max_size_reached_callback)
+ : WebRtcRtpDumpWriter(base::FilePath(),
+ base::FilePath(),
+ max_dump_size,
+ base::Closure()),
+ max_dump_size_(max_dump_size),
+ current_dump_size_(0),
+ max_size_reached_callback_(max_size_reached_callback) {}
+
+ virtual void WriteRtpPacket(const uint8* packet_header,
+ size_t header_length,
+ size_t packet_length,
+ bool incoming) OVERRIDE {
+ current_dump_size_ += header_length;
+ if (current_dump_size_ > max_dump_size_)
+ max_size_reached_callback_.Run();
+ }
+
+ virtual void EndDump(
+ const base::Callback<void(bool)>& finished_callback) OVERRIDE {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(finished_callback, true));
+ }
+
+ private:
+ size_t max_dump_size_;
+ size_t current_dump_size_;
+ base::Closure max_size_reached_callback_;
+};
+
+class WebRtcRtpDumpHandlerTest : public testing::Test {
+ public:
+ WebRtcRtpDumpHandlerTest()
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
+ ResetDumpHandler();
+ }
+
+ void ResetDumpHandler() {
+ handler_.reset(new WebRtcRtpDumpHandler(base::FilePath()));
+
+ scoped_ptr<WebRtcRtpDumpWriter> writer(new FakeDumpWriter(
+ 10,
+ base::Bind(&WebRtcRtpDumpHandlerTest::OnMaxSizeReached,
+ base::Unretained(this))));
+
+ handler_->SetDumpWriterForTesting(writer.Pass());
+ }
+
+ MOCK_METHOD1(OnDumpReleased,
+ void(const WebRtcRtpDumpHandler::ReleasedDumps& dumps));
+
+ MOCK_METHOD0(OnMaxSizeReached, void(void));
+
+ protected:
+ content::TestBrowserThreadBundle thread_bundle_;
+ scoped_ptr<WebRtcRtpDumpHandler> handler_;
+};
+
+TEST_F(WebRtcRtpDumpHandlerTest, StateTransition) {
+ WebRtcRtpDumpHandler::PacketType type_none(false, false);
+ EXPECT_FALSE(handler_->StartDump(type_none));
+
+ WebRtcRtpDumpHandler::PacketType types[3];
+ types[0] = WebRtcRtpDumpHandler::PacketType(true, false);
+ types[1] = WebRtcRtpDumpHandler::PacketType(false, true);
+ types[2] = WebRtcRtpDumpHandler::PacketType(true, true);
+ for (size_t i = 0; i < arraysize(types); ++i) {
+ // Only StartDump is allowed in STATE_NONE.
+ EXPECT_FALSE(handler_->StopDump(types[i]));
+ EXPECT_FALSE(
+ handler_->ReleaseDump(WebRtcRtpDumpHandler::ReleaseDumpCallback()));
+ EXPECT_TRUE(handler_->StartDump(types[i]));
+
+ // Only StopDump is allowed in STATE_STARTED.
+ EXPECT_FALSE(handler_->StartDump(types[i]));
+ EXPECT_FALSE(
+ handler_->ReleaseDump(WebRtcRtpDumpHandler::ReleaseDumpCallback()));
+ EXPECT_TRUE(handler_->StopDump(types[i]));
+
+ // Only ReleaseDump is allowed in STATE_STOPPED.
+ EXPECT_FALSE(handler_->StartDump(types[i]));
+ EXPECT_FALSE(handler_->StopDump(types[i]));
+
+ EXPECT_CALL(*this, OnDumpReleased(testing::_));
+ EXPECT_TRUE(handler_->ReleaseDump(base::Bind(
+ &WebRtcRtpDumpHandlerTest::OnDumpReleased, base::Unretained(this))));
+
+ base::RunLoop().RunUntilIdle();
+ ResetDumpHandler();
+ }
+}
+
+TEST_F(WebRtcRtpDumpHandlerTest, StartOneDirectionDumpingFailsInInvalidState) {
+ // Start incoming and then start outgoing should succeed.
+ WebRtcRtpDumpHandler::PacketType type(true, false);
+ EXPECT_TRUE(handler_->StartDump(type));
+ type = {false, true};
+ EXPECT_TRUE(handler_->StartDump(type));
+
+ // Start incoming when outgoing has stopped should fail.
+ ResetDumpHandler();
+ type = {false, true};
+ EXPECT_TRUE(handler_->StartDump(type));
+ EXPECT_TRUE(handler_->StopDump(type));
+ type = {true, false};
+ EXPECT_FALSE(handler_->StartDump(type));
+
+ // Start incoming after outgoing dump is released and before the callback
+ // happens should fail.
+ ResetDumpHandler();
+ type = {false, true};
+ EXPECT_TRUE(handler_->StartDump(type));
+ EXPECT_TRUE(handler_->StopDump(type));
+
+ EXPECT_CALL(*this, OnDumpReleased(testing::_));
+ EXPECT_TRUE(handler_->ReleaseDump(base::Bind(
+ &WebRtcRtpDumpHandlerTest::OnDumpReleased, base::Unretained(this))));
+
+ type = {true, false};
+ EXPECT_FALSE(handler_->StartDump(type));
+
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(WebRtcRtpDumpHandlerTest, MaxDumpSizeReachedCallback) {
+ WebRtcRtpDumpHandler::PacketType type(true, false);
+ EXPECT_TRUE(handler_->StartDump(type));
+ EXPECT_CALL(*this, OnMaxSizeReached());
+
+ std::vector<uint8> buffer(100, 0);
+ handler_->OnRtpPacket(buffer.data(), buffer.size(), buffer.size(), true);
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(WebRtcRtpDumpHandlerTest, PacketIgnoredIfDumpingNotStarted) {
+ std::vector<uint8> buffer(100, 0);
+ handler_->OnRtpPacket(buffer.data(), buffer.size(), buffer.size(), true);
+ handler_->OnRtpPacket(buffer.data(), buffer.size(), buffer.size(), false);
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(WebRtcRtpDumpHandlerTest, PacketIgnoredIfDumpingStopped) {
+ WebRtcRtpDumpHandler::PacketType type(true, false);
+ EXPECT_TRUE(handler_->StartDump(type));
+ EXPECT_TRUE(handler_->StopDump(type));
+
+ std::vector<uint8> buffer(100, 0);
+ handler_->OnRtpPacket(buffer.data(), buffer.size(), buffer.size(), true);
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(WebRtcRtpDumpHandlerTest, CannotStartMoreThanFiveDumps) {
+ handler_.reset();
+
+ scoped_ptr<WebRtcRtpDumpHandler> handlers[6];
+
+ for (size_t i = 0; i < arraysize(handlers); ++i) {
+ handlers[i].reset(new WebRtcRtpDumpHandler(base::FilePath()));
+
+ WebRtcRtpDumpHandler::PacketType type(true, false);
+ if (i < arraysize(handlers) - 1)
+ EXPECT_TRUE(handlers[i]->StartDump(type));
+ else
+ EXPECT_FALSE(handlers[i]->StartDump(type));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698