blob: 16985f98343b1309da52f96eaecd1cd7ce3b2cc8 [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"
16#include "pc/test/mock_peer_connection_internal.h"
17#include "test/gmock.h"
18#include "test/gtest.h"
19
20namespace webrtc {
21
22namespace {
23
24using ::testing::NiceMock;
25using ::testing::Return;
26
27class DataChannelControllerTest : public ::testing::Test {
28 protected:
29 DataChannelControllerTest() {
30 pc_ = rtc::make_ref_counted<NiceMock<MockPeerConnectionInternal>>();
31 ON_CALL(*pc_, signaling_thread)
32 .WillByDefault(Return(rtc::Thread::Current()));
33 }
34
35 rtc::scoped_refptr<NiceMock<MockPeerConnectionInternal>> pc_;
36};
37
38TEST_F(DataChannelControllerTest, CreateAndDestroy) {
39 DataChannelController dcc(pc_.get());
40}
41
42TEST_F(DataChannelControllerTest, CreateDataChannelEarlyRelease) {
43 DataChannelController dcc(pc_.get());
44 auto channel = dcc.InternalCreateDataChannelWithProxy(
45 "label",
46 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
47 channel = nullptr; // Should call destructor of channel
48}
49
50TEST_F(DataChannelControllerTest, CreateDataChannelLateRelease) {
51 auto dcc = std::make_unique<DataChannelController>(pc_.get());
52 auto channel = dcc->InternalCreateDataChannelWithProxy(
53 "label",
54 std::make_unique<InternalDataChannelInit>(DataChannelInit()).get());
55 dcc.reset();
56 channel = nullptr;
57}
58
59} // namespace
60} // namespace webrtc