Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <gtest/gtest.h> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "base/test/simple_test_tick_clock.h" | |
| 13 #include "media/cast/cast_config.h" | |
| 14 #include "media/cast/rtcp/rtcp.h" | |
| 15 #include "media/cast/test/fake_single_thread_task_runner.h" | |
| 16 #include "media/cast/transport/cast_transport_config.h" | |
| 17 #include "media/cast/transport/cast_transport_sender_impl.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace media { | |
| 21 namespace cast { | |
| 22 namespace transport { | |
| 23 | |
| 24 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | |
| 25 | |
| 26 class FakePacketSender : public transport::PacketSender { | |
| 27 public: | |
| 28 FakePacketSender() {} | |
| 29 | |
| 30 virtual bool SendPacket(const Packet& packet) OVERRIDE { return true; } | |
| 31 }; | |
| 32 | |
| 33 class CastTransportSenderImplTest : public ::testing::Test { | |
| 34 protected: | |
| 35 CastTransportSenderImplTest() | |
| 36 : testing_clock_(new base::SimpleTestTickClock()), | |
| 37 num_times_callback_called_(0) { | |
| 38 testing_clock_->Advance( | |
| 39 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | |
| 40 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_.get()); | |
| 41 } | |
| 42 | |
| 43 virtual ~CastTransportSenderImplTest() {} | |
| 44 | |
| 45 void InitWithoutLogging() { | |
| 46 transport::CastTransportConfig transport_config; | |
| 47 transport_sender_.reset( | |
| 48 new CastTransportSenderImpl(testing_clock_.get(), | |
| 49 transport_config, | |
| 50 GetDefaultCastSenderLoggingConfig(), | |
| 51 base::Bind(&UpdateCastTransportStatus), | |
| 52 BulkRawEventsCallback(), | |
| 53 base::TimeDelta(), | |
| 54 task_runner_, | |
| 55 &transport_)); | |
| 56 task_runner_->RunTasks(); | |
| 57 } | |
| 58 | |
| 59 void InitWithLogging() { | |
| 60 transport::CastTransportConfig transport_config; | |
| 61 transport_sender_.reset(new CastTransportSenderImpl( | |
| 62 testing_clock_.get(), | |
| 63 transport_config, | |
| 64 GetLoggingConfigWithRawEventsAndStatsEnabled(), | |
| 65 base::Bind(&UpdateCastTransportStatus), | |
| 66 base::Bind(&CastTransportSenderImplTest::LogRawEvents, | |
| 67 base::Unretained(this)), | |
| 68 base::TimeDelta::FromMilliseconds(10), | |
| 69 task_runner_, | |
| 70 &transport_)); | |
| 71 task_runner_->RunTasks(); | |
| 72 } | |
| 73 | |
| 74 void LogRawEvents(const std::vector<PacketEvent>& packet_events) { | |
| 75 num_times_callback_called_++; | |
| 76 if (num_times_callback_called_ == 3) { | |
| 77 run_loop_.Quit(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { | |
| 82 EXPECT_EQ(status, transport::TRANSPORT_INITIALIZED); | |
| 83 } | |
| 84 | |
| 85 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.
| |
| 86 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | |
| 87 scoped_ptr<CastTransportSenderImpl> transport_sender_; | |
| 88 FakePacketSender transport_; | |
| 89 base::MessageLoopForIO message_loop_; | |
| 90 base::RunLoop run_loop_; | |
| 91 int num_times_callback_called_; | |
| 92 }; | |
| 93 | |
| 94 TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { | |
| 95 InitWithoutLogging(); | |
| 96 message_loop_.PostDelayedTask(FROM_HERE, | |
| 97 run_loop_.QuitClosure(), | |
| 98 base::TimeDelta::FromMilliseconds(50)); | |
| 99 run_loop_.Run(); | |
| 100 EXPECT_EQ(0, num_times_callback_called_); | |
| 101 } | |
| 102 | |
| 103 TEST_F(CastTransportSenderImplTest, InitWithLogging) { | |
| 104 InitWithLogging(); | |
| 105 message_loop_.PostDelayedTask(FROM_HERE, | |
| 106 run_loop_.QuitClosure(), | |
| 107 base::TimeDelta::FromMilliseconds(50)); | |
| 108 run_loop_.Run(); | |
| 109 EXPECT_GT(num_times_callback_called_, 1); | |
| 110 } | |
| 111 | |
| 112 } // namespace transport | |
| 113 } // namespace cast | |
| 114 } // namespace media | |
| OLD | NEW |