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 : num_times_callback_called_(0) { |
| 37 testing_clock_.Advance( |
| 38 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| 39 task_runner_ = new test::FakeSingleThreadTaskRunner(&testing_clock_); |
| 40 } |
| 41 |
| 42 virtual ~CastTransportSenderImplTest() {} |
| 43 |
| 44 void InitWithoutLogging() { |
| 45 transport::CastTransportConfig transport_config; |
| 46 transport_sender_.reset( |
| 47 new CastTransportSenderImpl(NULL, |
| 48 &testing_clock_, |
| 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 NULL, |
| 63 &testing_clock_, |
| 64 transport_config, |
| 65 GetLoggingConfigWithRawEventsAndStatsEnabled(), |
| 66 base::Bind(&UpdateCastTransportStatus), |
| 67 base::Bind(&CastTransportSenderImplTest::LogRawEvents, |
| 68 base::Unretained(this)), |
| 69 base::TimeDelta::FromMilliseconds(10), |
| 70 task_runner_, |
| 71 &transport_)); |
| 72 task_runner_->RunTasks(); |
| 73 } |
| 74 |
| 75 void LogRawEvents(const std::vector<PacketEvent>& packet_events) { |
| 76 num_times_callback_called_++; |
| 77 if (num_times_callback_called_ == 3) { |
| 78 run_loop_.Quit(); |
| 79 } |
| 80 } |
| 81 |
| 82 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { |
| 83 EXPECT_EQ(status, transport::TRANSPORT_INITIALIZED); |
| 84 } |
| 85 |
| 86 base::SimpleTestTickClock testing_clock_; |
| 87 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
| 88 scoped_ptr<CastTransportSenderImpl> transport_sender_; |
| 89 FakePacketSender transport_; |
| 90 base::MessageLoopForIO message_loop_; |
| 91 base::RunLoop run_loop_; |
| 92 int num_times_callback_called_; |
| 93 }; |
| 94 |
| 95 TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { |
| 96 InitWithoutLogging(); |
| 97 message_loop_.PostDelayedTask(FROM_HERE, |
| 98 run_loop_.QuitClosure(), |
| 99 base::TimeDelta::FromMilliseconds(50)); |
| 100 run_loop_.Run(); |
| 101 EXPECT_EQ(0, num_times_callback_called_); |
| 102 } |
| 103 |
| 104 TEST_F(CastTransportSenderImplTest, InitWithLogging) { |
| 105 InitWithLogging(); |
| 106 message_loop_.PostDelayedTask(FROM_HERE, |
| 107 run_loop_.QuitClosure(), |
| 108 base::TimeDelta::FromMilliseconds(50)); |
| 109 run_loop_.Run(); |
| 110 EXPECT_GT(num_times_callback_called_, 1); |
| 111 } |
| 112 |
| 113 } // namespace transport |
| 114 } // namespace cast |
| 115 } // namespace media |
OLD | NEW |