OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "testing/gmock/include/gmock/gmock.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | |
14 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | |
15 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | |
16 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" | |
17 #include "webrtc/system_wrappers/include/clock.h" | |
18 | |
19 using testing::_; | |
20 using testing::NiceMock; | |
21 using testing::Return; | |
22 using testing::SaveArg; | |
23 using testing::StrictMock; | |
24 | |
25 namespace webrtc { | |
26 namespace test { | |
27 | |
28 class CongestionControllerTest : public ::testing::Test { | |
29 protected: | |
30 CongestionControllerTest() : clock_(123456) {} | |
31 ~CongestionControllerTest() override {} | |
32 | |
33 void SetUp() override { | |
34 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _)) | |
35 .WillOnce(SaveArg<0>(&initial_bitrate_bps_)); | |
36 | |
37 pacer_ = new NiceMock<MockPacedSender>(); | |
38 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. | |
39 std::unique_ptr<PacketRouter> packet_router(new PacketRouter()); | |
40 controller_.reset( | |
41 new CongestionController(&clock_, &observer_, &remote_bitrate_observer_, | |
42 std::move(packet_router), std::move(pacer))); | |
43 EXPECT_GT(initial_bitrate_bps_, 0u); | |
44 bandwidth_observer_.reset( | |
45 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); | |
46 } | |
47 | |
48 SimulatedClock clock_; | |
49 StrictMock<MockCongestionObserver> observer_; | |
50 NiceMock<MockPacedSender>* pacer_; | |
51 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | |
52 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | |
53 std::unique_ptr<CongestionController> controller_; | |
54 uint32_t initial_bitrate_bps_ = 0; | |
55 }; | |
56 | |
57 TEST_F(CongestionControllerTest, OnNetworkChanged) { | |
58 // Test no change. | |
59 clock_.AdvanceTimeMilliseconds(25); | |
60 controller_->Process(); | |
61 | |
62 EXPECT_CALL(observer_, OnNetworkChanged(initial_bitrate_bps_ * 2, _, _)); | |
63 bandwidth_observer_->OnReceivedEstimatedBitrate(initial_bitrate_bps_ * 2); | |
64 clock_.AdvanceTimeMilliseconds(25); | |
65 controller_->Process(); | |
66 | |
67 EXPECT_CALL(observer_, OnNetworkChanged(initial_bitrate_bps_, _, _)); | |
68 bandwidth_observer_->OnReceivedEstimatedBitrate(initial_bitrate_bps_); | |
69 clock_.AdvanceTimeMilliseconds(25); | |
70 controller_->Process(); | |
71 } | |
72 | |
73 TEST_F(CongestionControllerTest, OnSendQueueFull) { | |
74 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | |
75 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | |
76 | |
77 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | |
78 controller_->Process(); | |
79 | |
80 // Let the pacer not be full next time the controller checks. | |
81 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | |
82 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | |
83 | |
84 EXPECT_CALL(observer_, OnNetworkChanged(initial_bitrate_bps_, _, _)); | |
85 controller_->Process(); | |
86 } | |
87 | |
88 TEST_F(CongestionControllerTest, OnSendQueueFullAndEstimateChange) { | |
89 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | |
90 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | |
91 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | |
92 controller_->Process(); | |
93 | |
94 // Receive new estimate but let the queue still be full. | |
95 bandwidth_observer_->OnReceivedEstimatedBitrate(initial_bitrate_bps_ * 2); | |
96 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | |
97 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | |
98 clock_.AdvanceTimeMilliseconds(25); | |
99 controller_->Process(); | |
100 | |
101 // Let the pacer not be full next time the controller checks. | |
102 // |OnNetworkChanged| should be called with the new estimate. | |
103 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | |
104 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | |
105 EXPECT_CALL(observer_, OnNetworkChanged(initial_bitrate_bps_ * 2, _, _)); | |
106 clock_.AdvanceTimeMilliseconds(25); | |
107 controller_->Process(); | |
108 } | |
109 | |
110 } // namespace test | |
111 } // namespace webrtc | |
OLD | NEW |