| 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..3d8ef64e3742ef9a43cc181e355a2ca8c86f45f2
|
| --- /dev/null
|
| +++ b/chromecast/media/cma/base/buffering_controller_unittest.cc
|
| @@ -0,0 +1,132 @@
|
| +// 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 "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 media {
|
| +namespace cma {
|
| +
|
| +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 cma
|
| +} // namespace media
|
| +
|
|
|