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

Unified Diff: chromecast/media/cma/base/buffering_controller_unittest.cc

Issue 509213002: Add a buffering controller for Chromecast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad license header. Created 6 years, 4 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 | « chromecast/media/cma/base/buffering_controller.cc ('k') | chromecast/media/cma/base/buffering_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/media/cma/base/buffering_controller_unittest.cc
diff --git a/chromecast/media/cma/base/buffering_controller_unittest.cc b/chromecast/media/cma/base/buffering_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..75eaed9ce1acb25063864ab15357b0d643de5c20
--- /dev/null
+++ b/chromecast/media/cma/base/buffering_controller_unittest.cc
@@ -0,0 +1,133 @@
+// 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/callback_helpers.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "chromecast/media/cma/base/buffering_controller.h"
+#include "chromecast/media/cma/base/buffering_state.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromecast {
+namespace media {
+
+namespace {
+
+class MockBufferingControllerClient {
+ public:
+ MockBufferingControllerClient();
+ ~MockBufferingControllerClient();
+
+ MOCK_METHOD1(OnBufferingNotification, void(bool is_buffering));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockBufferingControllerClient);
+};
+
+MockBufferingControllerClient::MockBufferingControllerClient() {
+}
+
+MockBufferingControllerClient::~MockBufferingControllerClient() {
+}
+
+} // namespace
+
+class BufferingControllerTest : public testing::Test {
+ public:
+ BufferingControllerTest();
+ virtual ~BufferingControllerTest();
+
+ protected:
+ scoped_ptr<BufferingController> buffering_controller_;
+
+ MockBufferingControllerClient client_;
+
+ // Buffer level under the low level threshold.
+ base::TimeDelta d1_;
+
+ // Buffer level between the low and the high level.
+ base::TimeDelta d2_;
+
+ // Buffer level above the high level.
+ base::TimeDelta d3_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BufferingControllerTest);
+};
+
+BufferingControllerTest::BufferingControllerTest() {
+ base::TimeDelta low_level_threshold(
+ base::TimeDelta::FromMilliseconds(2000));
+ base::TimeDelta high_level_threshold(
+ base::TimeDelta::FromMilliseconds(6000));
+
+ d1_ = low_level_threshold - base::TimeDelta::FromMilliseconds(50);
+ d2_ = (low_level_threshold + high_level_threshold) / 2;
+ d3_ = high_level_threshold + base::TimeDelta::FromMilliseconds(50);
+
+ scoped_refptr<BufferingConfig> buffering_config(
+ new BufferingConfig(low_level_threshold, high_level_threshold));
+ buffering_controller_.reset(new BufferingController(
+ buffering_config,
+ base::Bind(&MockBufferingControllerClient::OnBufferingNotification,
+ base::Unretained(&client_))));
+}
+
+BufferingControllerTest::~BufferingControllerTest() {
+}
+
+TEST_F(BufferingControllerTest, OneStream_Typical) {
+ EXPECT_CALL(client_, OnBufferingNotification(true)).Times(1);
+ scoped_refptr<BufferingState> buffering_state =
+ buffering_controller_->AddStream();
+ buffering_state->SetMediaTime(base::TimeDelta());
+
+ // Simulate pre-buffering.
+ buffering_state->SetBufferedTime(d2_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kMediumLevel);
+
+ EXPECT_CALL(client_, OnBufferingNotification(false)).Times(1);
+ buffering_state->SetBufferedTime(d3_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kHighLevel);
+
+ // Simulate some fluctuations of the buffering level.
+ buffering_state->SetBufferedTime(d2_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kMediumLevel);
+
+ // Simulate an underrun.
+ EXPECT_CALL(client_, OnBufferingNotification(true)).Times(1);
+ buffering_state->SetBufferedTime(d1_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kLowLevel);
+
+ EXPECT_CALL(client_, OnBufferingNotification(false)).Times(1);
+ buffering_state->SetBufferedTime(d3_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kHighLevel);
+
+ // Simulate the end of stream.
+ buffering_state->NotifyEos();
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kEosReached);
+
+ buffering_state->SetBufferedTime(d2_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kEosReached);
+
+ buffering_state->SetBufferedTime(d1_);
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kEosReached);
+}
+
+TEST_F(BufferingControllerTest, OneStream_LeaveBufferingOnEos) {
+ EXPECT_CALL(client_, OnBufferingNotification(true)).Times(1);
+ scoped_refptr<BufferingState> buffering_state =
+ buffering_controller_->AddStream();
+ buffering_state->SetMediaTime(base::TimeDelta());
+
+ EXPECT_CALL(client_, OnBufferingNotification(false)).Times(1);
+ buffering_state->NotifyEos();
+ EXPECT_EQ(buffering_state->GetState(), BufferingState::kEosReached);
+}
+
+} // namespace media
+} // namespace chromecast
« no previous file with comments | « chromecast/media/cma/base/buffering_controller.cc ('k') | chromecast/media/cma/base/buffering_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698