blob: 693277552c6e0d9c1e506fa0021096dda5e2dba9 [file] [log] [blame]
Irfan Sheriffb2540bb2016-09-12 12:28:54 -07001/*
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#include <memory>
11
12#include "testing/gmock/include/gmock/gmock.h"
13#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/base/logging.h"
15#include "webrtc/modules/congestion_controller/probe_controller.h"
16#include "webrtc/modules/pacing/mock/mock_paced_sender.h"
17#include "webrtc/system_wrappers/include/clock.h"
18
19using testing::_;
20using testing::AtLeast;
21using testing::NiceMock;
22
23namespace webrtc {
24namespace test {
25
26namespace {
27
28constexpr int kMinBitrateBps = 100;
29constexpr int kStartBitrateBps = 300;
30constexpr int kMaxBitrateBps = 1000;
31
32} // namespace
33
34class ProbeControllerTest : public ::testing::Test {
35 protected:
36 ProbeControllerTest() : clock_(0) {
37 probe_controller_.reset(new ProbeController(&pacer_, &clock_));
38 }
39 ~ProbeControllerTest() override {}
40
41 SimulatedClock clock_;
42 NiceMock<MockPacedSender> pacer_;
43 std::unique_ptr<ProbeController> probe_controller_;
44};
45
46TEST_F(ProbeControllerTest, InitiatesProbingAtStart) {
47 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2));
48 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
49 kMaxBitrateBps);
50}
51
52TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) {
53 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2));
54 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
55 kMaxBitrateBps);
56 clock_.AdvanceTimeMilliseconds(25);
57
58 probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
59 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100, _));
60 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
61 kMaxBitrateBps + 100);
62}
63
64TEST_F(ProbeControllerTest, TestExponentialProbing) {
65 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
66 kMaxBitrateBps);
67 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _));
68 probe_controller_->SetEstimatedBitrate(1800);
69}
70
71TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) {
72 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
73 kMaxBitrateBps);
74
75 // Advance far enough to cause a time out in waiting for probing result.
76 clock_.AdvanceTimeMilliseconds(5000);
77 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)).Times(0);
78 probe_controller_->SetEstimatedBitrate(1800);
79}
80
81} // namespace test
82} // namespace webrtc