xref: /aosp_15_r20/external/webrtc/pc/data_channel_controller_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2022 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #include "pc/data_channel_controller.h"
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <memory>
14*d9f75844SAndroid Build Coastguard Worker 
15*d9f75844SAndroid Build Coastguard Worker #include "pc/peer_connection_internal.h"
16*d9f75844SAndroid Build Coastguard Worker #include "pc/sctp_data_channel.h"
17*d9f75844SAndroid Build Coastguard Worker #include "pc/test/mock_peer_connection_internal.h"
18*d9f75844SAndroid Build Coastguard Worker #include "test/gmock.h"
19*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h"
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
22*d9f75844SAndroid Build Coastguard Worker 
23*d9f75844SAndroid Build Coastguard Worker namespace {
24*d9f75844SAndroid Build Coastguard Worker 
25*d9f75844SAndroid Build Coastguard Worker using ::testing::NiceMock;
26*d9f75844SAndroid Build Coastguard Worker using ::testing::Return;
27*d9f75844SAndroid Build Coastguard Worker 
28*d9f75844SAndroid Build Coastguard Worker class DataChannelControllerTest : public ::testing::Test {
29*d9f75844SAndroid Build Coastguard Worker  protected:
DataChannelControllerTest()30*d9f75844SAndroid Build Coastguard Worker   DataChannelControllerTest() {
31*d9f75844SAndroid Build Coastguard Worker     pc_ = rtc::make_ref_counted<NiceMock<MockPeerConnectionInternal>>();
32*d9f75844SAndroid Build Coastguard Worker     ON_CALL(*pc_, signaling_thread)
33*d9f75844SAndroid Build Coastguard Worker         .WillByDefault(Return(rtc::Thread::Current()));
34*d9f75844SAndroid Build Coastguard Worker   }
35*d9f75844SAndroid Build Coastguard Worker 
36*d9f75844SAndroid Build Coastguard Worker   rtc::AutoThread main_thread_;
37*d9f75844SAndroid Build Coastguard Worker   rtc::scoped_refptr<NiceMock<MockPeerConnectionInternal>> pc_;
38*d9f75844SAndroid Build Coastguard Worker };
39*d9f75844SAndroid Build Coastguard Worker 
TEST_F(DataChannelControllerTest,CreateAndDestroy)40*d9f75844SAndroid Build Coastguard Worker TEST_F(DataChannelControllerTest, CreateAndDestroy) {
41*d9f75844SAndroid Build Coastguard Worker   DataChannelController dcc(pc_.get());
42*d9f75844SAndroid Build Coastguard Worker }
43*d9f75844SAndroid Build Coastguard Worker 
TEST_F(DataChannelControllerTest,CreateDataChannelEarlyRelease)44*d9f75844SAndroid Build Coastguard Worker TEST_F(DataChannelControllerTest, CreateDataChannelEarlyRelease) {
45*d9f75844SAndroid Build Coastguard Worker   DataChannelController dcc(pc_.get());
46*d9f75844SAndroid Build Coastguard Worker   auto channel = dcc.InternalCreateDataChannelWithProxy(
47*d9f75844SAndroid Build Coastguard Worker       "label",
48*d9f75844SAndroid Build Coastguard Worker       std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
49*d9f75844SAndroid Build Coastguard Worker   channel = nullptr;  // dcc holds a reference to channel, so not destroyed yet
50*d9f75844SAndroid Build Coastguard Worker }
51*d9f75844SAndroid Build Coastguard Worker 
TEST_F(DataChannelControllerTest,CreateDataChannelLateRelease)52*d9f75844SAndroid Build Coastguard Worker TEST_F(DataChannelControllerTest, CreateDataChannelLateRelease) {
53*d9f75844SAndroid Build Coastguard Worker   auto dcc = std::make_unique<DataChannelController>(pc_.get());
54*d9f75844SAndroid Build Coastguard Worker   auto channel = dcc->InternalCreateDataChannelWithProxy(
55*d9f75844SAndroid Build Coastguard Worker       "label",
56*d9f75844SAndroid Build Coastguard Worker       std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
57*d9f75844SAndroid Build Coastguard Worker   dcc.reset();
58*d9f75844SAndroid Build Coastguard Worker   channel = nullptr;
59*d9f75844SAndroid Build Coastguard Worker }
60*d9f75844SAndroid Build Coastguard Worker 
TEST_F(DataChannelControllerTest,CloseAfterControllerDestroyed)61*d9f75844SAndroid Build Coastguard Worker TEST_F(DataChannelControllerTest, CloseAfterControllerDestroyed) {
62*d9f75844SAndroid Build Coastguard Worker   auto dcc = std::make_unique<DataChannelController>(pc_.get());
63*d9f75844SAndroid Build Coastguard Worker   auto channel = dcc->InternalCreateDataChannelWithProxy(
64*d9f75844SAndroid Build Coastguard Worker       "label",
65*d9f75844SAndroid Build Coastguard Worker       std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
66*d9f75844SAndroid Build Coastguard Worker   // Connect to provider
67*d9f75844SAndroid Build Coastguard Worker   auto inner_channel =
68*d9f75844SAndroid Build Coastguard Worker       DowncastProxiedDataChannelInterfaceToSctpDataChannelForTesting(
69*d9f75844SAndroid Build Coastguard Worker           channel.get());
70*d9f75844SAndroid Build Coastguard Worker   dcc->ConnectDataChannel(inner_channel);
71*d9f75844SAndroid Build Coastguard Worker   dcc.reset();
72*d9f75844SAndroid Build Coastguard Worker   channel->Close();
73*d9f75844SAndroid Build Coastguard Worker }
74*d9f75844SAndroid Build Coastguard Worker 
75*d9f75844SAndroid Build Coastguard Worker }  // namespace
76*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
77