Harald Alvestrand | a45c8f4 | 2022-05-10 08:44:48 | [diff] [blame] | 1 | /* |
| 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 Alvestrand | 9e5aeb9 | 2022-05-11 09:35:36 | [diff] [blame] | 16 | #include "pc/sctp_data_channel.h" |
Harald Alvestrand | a45c8f4 | 2022-05-10 08:44:48 | [diff] [blame] | 17 | #include "pc/test/mock_peer_connection_internal.h" |
| 18 | #include "test/gmock.h" |
| 19 | #include "test/gtest.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | namespace { |
| 24 | |
| 25 | using ::testing::NiceMock; |
| 26 | using ::testing::Return; |
| 27 | |
| 28 | class 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öller | 83830f3 | 2022-05-20 07:12:57 | [diff] [blame] | 36 | rtc::AutoThread main_thread_; |
Harald Alvestrand | a45c8f4 | 2022-05-10 08:44:48 | [diff] [blame] | 37 | rtc::scoped_refptr<NiceMock<MockPeerConnectionInternal>> pc_; |
| 38 | }; |
| 39 | |
| 40 | TEST_F(DataChannelControllerTest, CreateAndDestroy) { |
| 41 | DataChannelController dcc(pc_.get()); |
| 42 | } |
| 43 | |
| 44 | TEST_F(DataChannelControllerTest, CreateDataChannelEarlyRelease) { |
| 45 | DataChannelController dcc(pc_.get()); |
| 46 | auto channel = dcc.InternalCreateDataChannelWithProxy( |
| 47 | "label", |
| 48 | std::make_unique<InternalDataChannelInit>(DataChannelInit()).get()); |
Harald Alvestrand | 9e5aeb9 | 2022-05-11 09:35:36 | [diff] [blame] | 49 | channel = nullptr; // dcc holds a reference to channel, so not destroyed yet |
Harald Alvestrand | a45c8f4 | 2022-05-10 08:44:48 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | TEST_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 Alvestrand | 9e5aeb9 | 2022-05-11 09:35:36 | [diff] [blame] | 61 | TEST_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 Alvestrand | a45c8f4 | 2022-05-10 08:44:48 | [diff] [blame] | 75 | } // namespace |
| 76 | } // namespace webrtc |