blob: 7a1f68a52f5af1eab98758fc8d1f0c8673d761a8 [file] [log] [blame]
Harald Alvestranda45c8f42022-05-10 08:44:48 +00001/*
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:36 +000016#include "pc/sctp_data_channel.h"
Harald Alvestranda45c8f42022-05-10 08:44:48 +000017#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
36 rtc::scoped_refptr<NiceMock<MockPeerConnectionInternal>> pc_;
37};
38
39TEST_F(DataChannelControllerTest, CreateAndDestroy) {
40 DataChannelController dcc(pc_.get());
41}
42
43TEST_F(DataChannelControllerTest, CreateDataChannelEarlyRelease) {
44 DataChannelController dcc(pc_.get());
45 auto channel = dcc.InternalCreateDataChannelWithProxy(
46 "label",
47 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
Harald Alvestrand9e5aeb92022-05-11 09:35:36 +000048 channel = nullptr; // dcc holds a reference to channel, so not destroyed yet
Harald Alvestranda45c8f42022-05-10 08:44:48 +000049}
50
51TEST_F(DataChannelControllerTest, CreateDataChannelLateRelease) {
52 auto dcc = std::make_unique<DataChannelController>(pc_.get());
53 auto channel = dcc->InternalCreateDataChannelWithProxy(
54 "label",
55 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
56 dcc.reset();
57 channel = nullptr;
58}
59
Harald Alvestrand9e5aeb92022-05-11 09:35:36 +000060TEST_F(DataChannelControllerTest, CloseAfterControllerDestroyed) {
61 auto dcc = std::make_unique<DataChannelController>(pc_.get());
62 auto channel = dcc->InternalCreateDataChannelWithProxy(
63 "label",
64 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
65 // Connect to provider
66 auto inner_channel =
67 DowncastProxiedDataChannelInterfaceToSctpDataChannelForTesting(
68 channel.get());
69 dcc->ConnectDataChannel(inner_channel);
70 dcc.reset();
71 channel->Close();
72}
73
Harald Alvestranda45c8f42022-05-10 08:44:48 +000074} // namespace
75} // namespace webrtc