blob: 2f5c924796e56a94b088bc60f855ee949943210a [file] [log] [blame]
Harald Alvestranda45c8f42022-05-10 08:44:481/*
2 * Copyright 2022 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 "pc/data_channel_controller.h"
12
13#include <memory>
14
15#include "pc/peer_connection_internal.h"
Harald Alvestrand9e5aeb92022-05-11 09:35:3616#include "pc/sctp_data_channel.h"
Harald Alvestranda45c8f42022-05-10 08:44:4817#include "pc/test/mock_peer_connection_internal.h"
18#include "test/gmock.h"
19#include "test/gtest.h"
20
21namespace webrtc {
22
23namespace {
24
25using ::testing::NiceMock;
26using ::testing::Return;
27
28class DataChannelControllerTest : public ::testing::Test {
29 protected:
30 DataChannelControllerTest() {
31 pc_ = rtc::make_ref_counted<NiceMock<MockPeerConnectionInternal>>();
32 ON_CALL(*pc_, signaling_thread)
33 .WillByDefault(Return(rtc::Thread::Current()));
34 }
35
Niels Möller83830f32022-05-20 07:12:5736 rtc::AutoThread main_thread_;
Harald Alvestranda45c8f42022-05-10 08:44:4837 rtc::scoped_refptr<NiceMock<MockPeerConnectionInternal>> pc_;
38};
39
40TEST_F(DataChannelControllerTest, CreateAndDestroy) {
41 DataChannelController dcc(pc_.get());
42}
43
44TEST_F(DataChannelControllerTest, CreateDataChannelEarlyRelease) {
45 DataChannelController dcc(pc_.get());
46 auto channel = dcc.InternalCreateDataChannelWithProxy(
47 "label",
48 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
Harald Alvestrand9e5aeb92022-05-11 09:35:3649 channel = nullptr; // dcc holds a reference to channel, so not destroyed yet
Harald Alvestranda45c8f42022-05-10 08:44:4850}
51
52TEST_F(DataChannelControllerTest, CreateDataChannelLateRelease) {
53 auto dcc = std::make_unique<DataChannelController>(pc_.get());
54 auto channel = dcc->InternalCreateDataChannelWithProxy(
55 "label",
56 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
57 dcc.reset();
58 channel = nullptr;
59}
60
Harald Alvestrand9e5aeb92022-05-11 09:35:3661TEST_F(DataChannelControllerTest, CloseAfterControllerDestroyed) {
62 auto dcc = std::make_unique<DataChannelController>(pc_.get());
63 auto channel = dcc->InternalCreateDataChannelWithProxy(
64 "label",
65 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
66 // Connect to provider
67 auto inner_channel =
68 DowncastProxiedDataChannelInterfaceToSctpDataChannelForTesting(
69 channel.get());
70 dcc->ConnectDataChannel(inner_channel);
71 dcc.reset();
72 channel->Close();
73}
74
Harald Alvestranda45c8f42022-05-10 08:44:4875} // namespace
76} // namespace webrtc