OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/simple_test_tick_clock.h" | 13 #include "base/test/simple_test_tick_clock.h" |
14 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
15 #include "media/cast/rtcp/rtcp.h" | 15 #include "media/cast/net/cast_transport_config.h" |
| 16 #include "media/cast/net/cast_transport_sender_impl.h" |
| 17 #include "media/cast/net/rtcp/rtcp.h" |
16 #include "media/cast/test/fake_single_thread_task_runner.h" | 18 #include "media/cast/test/fake_single_thread_task_runner.h" |
17 #include "media/cast/transport/cast_transport_config.h" | |
18 #include "media/cast/transport/cast_transport_sender_impl.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 namespace cast { | 22 namespace cast { |
23 namespace transport { | |
24 | 23 |
25 static const int64 kStartMillisecond = INT64_C(12345678900000); | 24 static const int64 kStartMillisecond = INT64_C(12345678900000); |
26 | 25 |
27 class FakePacketSender : public transport::PacketSender { | 26 class FakePacketSender : public PacketSender { |
28 public: | 27 public: |
29 FakePacketSender() {} | 28 FakePacketSender() {} |
30 | 29 |
31 virtual bool SendPacket(PacketRef packet, const base::Closure& cb) OVERRIDE { | 30 virtual bool SendPacket(PacketRef packet, const base::Closure& cb) OVERRIDE { |
32 return true; | 31 return true; |
33 } | 32 } |
34 }; | 33 }; |
35 | 34 |
36 class CastTransportSenderImplTest : public ::testing::Test { | 35 class CastTransportSenderImplTest : public ::testing::Test { |
37 protected: | 36 protected: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 task_runner_->RunTasks(); | 70 task_runner_->RunTasks(); |
72 } | 71 } |
73 | 72 |
74 void LogRawEvents(const std::vector<PacketEvent>& packet_events) { | 73 void LogRawEvents(const std::vector<PacketEvent>& packet_events) { |
75 num_times_callback_called_++; | 74 num_times_callback_called_++; |
76 if (num_times_callback_called_ == 3) { | 75 if (num_times_callback_called_ == 3) { |
77 run_loop_.Quit(); | 76 run_loop_.Quit(); |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { | 80 static void UpdateCastTransportStatus(CastTransportStatus status) { |
82 } | 81 } |
83 | 82 |
84 base::SimpleTestTickClock testing_clock_; | 83 base::SimpleTestTickClock testing_clock_; |
85 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 84 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
86 scoped_ptr<CastTransportSenderImpl> transport_sender_; | 85 scoped_ptr<CastTransportSenderImpl> transport_sender_; |
87 FakePacketSender transport_; | 86 FakePacketSender transport_; |
88 base::MessageLoopForIO message_loop_; | 87 base::MessageLoopForIO message_loop_; |
89 base::RunLoop run_loop_; | 88 base::RunLoop run_loop_; |
90 int num_times_callback_called_; | 89 int num_times_callback_called_; |
91 }; | 90 }; |
92 | 91 |
93 TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { | 92 TEST_F(CastTransportSenderImplTest, InitWithoutLogging) { |
94 InitWithoutLogging(); | 93 InitWithoutLogging(); |
95 message_loop_.PostDelayedTask(FROM_HERE, | 94 message_loop_.PostDelayedTask(FROM_HERE, |
96 run_loop_.QuitClosure(), | 95 run_loop_.QuitClosure(), |
97 base::TimeDelta::FromMilliseconds(50)); | 96 base::TimeDelta::FromMilliseconds(50)); |
98 run_loop_.Run(); | 97 run_loop_.Run(); |
99 EXPECT_EQ(0, num_times_callback_called_); | 98 EXPECT_EQ(0, num_times_callback_called_); |
100 } | 99 } |
101 | 100 |
102 TEST_F(CastTransportSenderImplTest, InitWithLogging) { | 101 TEST_F(CastTransportSenderImplTest, InitWithLogging) { |
103 InitWithLogging(); | 102 InitWithLogging(); |
104 message_loop_.PostDelayedTask(FROM_HERE, | 103 message_loop_.PostDelayedTask(FROM_HERE, |
105 run_loop_.QuitClosure(), | 104 run_loop_.QuitClosure(), |
106 base::TimeDelta::FromMilliseconds(50)); | 105 base::TimeDelta::FromMilliseconds(50)); |
107 run_loop_.Run(); | 106 run_loop_.Run(); |
108 EXPECT_GT(num_times_callback_called_, 1); | 107 EXPECT_GT(num_times_callback_called_, 1); |
109 } | 108 } |
110 | 109 |
111 } // namespace transport | |
112 } // namespace cast | 110 } // namespace cast |
113 } // namespace media | 111 } // namespace media |
OLD | NEW |