Chromium Code Reviews| Index: media/cast/transport/cast_transport_sender_impl_unittest.cc |
| diff --git a/media/cast/transport/cast_transport_sender_impl_unittest.cc b/media/cast/transport/cast_transport_sender_impl_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3910d3c2ab3031ff83c9c309539a6f27e5a1bf5d |
| --- /dev/null |
| +++ b/media/cast/transport/cast_transport_sender_impl_unittest.cc |
| @@ -0,0 +1,114 @@ |
| +// 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 <gtest/gtest.h> |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "base/test/simple_test_tick_clock.h" |
| +#include "media/cast/cast_config.h" |
| +#include "media/cast/rtcp/rtcp.h" |
| +#include "media/cast/test/fake_single_thread_task_runner.h" |
| +#include "media/cast/transport/cast_transport_config.h" |
| +#include "media/cast/transport/cast_transport_sender_impl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace media { |
| +namespace cast { |
| +namespace transport { |
| + |
| +static const int64 kStartMillisecond = GG_INT64_C(12345678900000); |
| + |
| +class FakePacketSender : public transport::PacketSender { |
| + public: |
| + FakePacketSender() {} |
| + |
| + virtual bool SendPacket(const Packet& packet) OVERRIDE { return true; } |
| +}; |
| + |
| +class CastTransportSenderImplTest : public ::testing::Test { |
| + protected: |
| + CastTransportSenderImplTest() |
| + : testing_clock_(new base::SimpleTestTickClock()), |
| + num_times_callback_called_(0) { |
| + testing_clock_->Advance( |
| + base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| + task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_.get()); |
| + } |
| + |
| + virtual ~CastTransportSenderImplTest() {} |
| + |
| + void InitWithoutLogging() { |
| + transport::CastTransportConfig transport_config; |
| + transport_sender_.reset( |
| + new CastTransportSenderImpl(testing_clock_.get(), |
| + transport_config, |
| + GetDefaultCastSenderLoggingConfig(), |
| + base::Bind(&UpdateCastTransportStatus), |
| + BulkRawEventsCallback(), |
| + base::TimeDelta(), |
| + task_runner_, |
| + &transport_)); |
| + task_runner_->RunTasks(); |
| + } |
| + |
| + void InitWithLogging() { |
| + transport::CastTransportConfig transport_config; |
| + transport_sender_.reset(new CastTransportSenderImpl( |
| + testing_clock_.get(), |
| + transport_config, |
| + GetLoggingConfigWithRawEventsAndStatsEnabled(), |
| + base::Bind(&UpdateCastTransportStatus), |
| + base::Bind(&CastTransportSenderImplTest::LogRawEvents, |
| + base::Unretained(this)), |
| + base::TimeDelta::FromMilliseconds(10), |
| + task_runner_, |
| + &transport_)); |
| + task_runner_->RunTasks(); |
| + } |
| + |
| + void LogRawEvents(const std::vector<PacketEvent>& packet_events) { |
| + num_times_callback_called_++; |
| + if (num_times_callback_called_ == 3) { |
| + run_loop_.Quit(); |
| + } |
| + } |
| + |
| + static void UpdateCastTransportStatus(transport::CastTransportStatus status) { |
| + EXPECT_EQ(status, transport::TRANSPORT_INITIALIZED); |
| + } |
| + |
| + scoped_ptr<base::SimpleTestTickClock> testing_clock_; |
|
miu
2014/02/26 22:43:51
nit: This can be part of the class, rather than a
imcheng
2014/02/26 23:35:55
Done.
|
| + scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
| + scoped_ptr<CastTransportSenderImpl> transport_sender_; |
| + FakePacketSender transport_; |
| + base::MessageLoopForIO message_loop_; |
| + base::RunLoop run_loop_; |
| + int num_times_callback_called_; |
| +}; |
| + |
| +TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { |
| + InitWithoutLogging(); |
| + message_loop_.PostDelayedTask(FROM_HERE, |
| + run_loop_.QuitClosure(), |
| + base::TimeDelta::FromMilliseconds(50)); |
| + run_loop_.Run(); |
| + EXPECT_EQ(0, num_times_callback_called_); |
| +} |
| + |
| +TEST_F(CastTransportSenderImplTest, InitWithLogging) { |
| + InitWithLogging(); |
| + message_loop_.PostDelayedTask(FROM_HERE, |
| + run_loop_.QuitClosure(), |
| + base::TimeDelta::FromMilliseconds(50)); |
| + run_loop_.Run(); |
| + EXPECT_GT(num_times_callback_called_, 1); |
| +} |
| + |
| +} // namespace transport |
| +} // namespace cast |
| +} // namespace media |