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() : num_times_callback_called_(0) { |
| 36 testing_clock_.Advance( |
| 37 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| 38 task_runner_ = new test::FakeSingleThreadTaskRunner(&testing_clock_); |
| 39 } |
| 40 |
| 41 virtual ~CastTransportSenderImplTest() {} |
| 42 |
| 43 void InitWithoutLogging() { |
| 44 transport_sender_.reset( |
| 45 new CastTransportSenderImpl(NULL, |
| 46 &testing_clock_, |
| 47 net::IPEndPoint(), |
| 48 net::IPEndPoint(), |
| 49 GetDefaultCastSenderLoggingConfig(), |
| 50 base::Bind(&UpdateCastTransportStatus), |
| 51 BulkRawEventsCallback(), |
| 52 base::TimeDelta(), |
| 53 task_runner_, |
| 54 &transport_)); |
| 55 task_runner_->RunTasks(); |
| 56 } |
| 57 |
| 58 void InitWithLogging() { |
| 59 transport_sender_.reset(new CastTransportSenderImpl( |
| 60 NULL, |
| 61 &testing_clock_, |
| 62 net::IPEndPoint(), |
| 63 net::IPEndPoint(), |
| 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 } |
| 83 |
| 84 base::SimpleTestTickClock testing_clock_; |
| 85 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
| 86 scoped_ptr<CastTransportSenderImpl> transport_sender_; |
| 87 FakePacketSender transport_; |
| 88 base::MessageLoopForIO message_loop_; |
| 89 base::RunLoop run_loop_; |
| 90 int num_times_callback_called_; |
| 91 }; |
| 92 |
| 93 TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { |
| 94 InitWithoutLogging(); |
| 95 message_loop_.PostDelayedTask(FROM_HERE, |
| 96 run_loop_.QuitClosure(), |
| 97 base::TimeDelta::FromMilliseconds(50)); |
| 98 run_loop_.Run(); |
| 99 EXPECT_EQ(0, num_times_callback_called_); |
| 100 } |
| 101 |
| 102 TEST_F(CastTransportSenderImplTest, InitWithLogging) { |
| 103 InitWithLogging(); |
| 104 message_loop_.PostDelayedTask(FROM_HERE, |
| 105 run_loop_.QuitClosure(), |
| 106 base::TimeDelta::FromMilliseconds(50)); |
| 107 run_loop_.Run(); |
| 108 EXPECT_GT(num_times_callback_called_, 1); |
| 109 } |
| 110 |
| 111 } // namespace transport |
| 112 } // namespace cast |
| 113 } // namespace media |
OLD | NEW |