File: ice_proposal_test.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (124 lines) | stat: -rw-r--r-- 5,430 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/webrtc_overrides/p2p/base/ice_ping_proposal.h"
#include "third_party/webrtc_overrides/p2p/base/ice_prune_proposal.h"
#include "third_party/webrtc_overrides/p2p/base/ice_switch_proposal.h"

#include <vector>

#include "testing/gtest/include/gtest/gtest.h"

#include "third_party/blink/renderer/platform/peerconnection/fake_connection_test_base.h"
#include "third_party/blink/renderer/platform/peerconnection/webrtc_connection_matchers.h"

#include "third_party/webrtc/p2p/base/ice_controller_interface.h"
#include "third_party/webrtc/p2p/base/ice_switch_reason.h"

namespace {

using ::webrtc::Connection;
using ::webrtc::IceControllerInterface;
using ::webrtc::IceRecheckEvent;
using ::webrtc::IceSwitchReason;

using ::blink::IcePingProposal;
using ::blink::IcePruneProposal;
using ::blink::IceSwitchProposal;
using ::blink::PingProposalEq;
using ::blink::PruneProposalEq;
using ::blink::SwitchProposalEq;

static const std::string kIp = "1.2.3.4";
static const std::string kIpTwo = "1.3.5.7";
static const int kPort = 6745;

class IceProposalTest : public blink::FakeConnectionTestBase {};

TEST_F(IceProposalTest, ConstructIcePingProposal) {
  const Connection* conn = GetConnection(kIp, kPort);
  const int recheck_delay_ms = 10;
  const bool reply_expected = true;

  IceControllerInterface::PingResult ping_result(conn, recheck_delay_ms);
  EXPECT_THAT(IcePingProposal(ping_result, reply_expected),
              PingProposalEq(ping_result, reply_expected));

  IceControllerInterface::PingResult null_ping_result(nullptr,
                                                      recheck_delay_ms);
  EXPECT_THAT(IcePingProposal(null_ping_result, reply_expected),
              PingProposalEq(null_ping_result, reply_expected));
}

TEST_F(IceProposalTest, ConstructIceSwitchProposal) {
  const Connection* conn = GetConnection(kIp, kPort);
  const Connection* conn_two = GetConnection(kIpTwo, kPort);
  const IceSwitchReason reason = IceSwitchReason::CONNECT_STATE_CHANGE;
  const int recheck_delay_ms = 10;
  const bool reply_expected = true;
  const IceRecheckEvent recheck_event(IceSwitchReason::ICE_CONTROLLER_RECHECK,
                                      recheck_delay_ms);
  std::vector<const Connection*> conns_to_forget{conn_two};
  std::vector<const Connection*> empty_conns_to_forget{};
  std::vector<const Connection*> null_conns_to_forget{nullptr};

  IceControllerInterface::SwitchResult switch_result{conn, recheck_event,
                                                     conns_to_forget};
  EXPECT_THAT(IceSwitchProposal(reason, switch_result, reply_expected),
              SwitchProposalEq(reason, switch_result, reply_expected));

  IceControllerInterface::SwitchResult empty_switch_result{
      std::nullopt, recheck_event, conns_to_forget};
  EXPECT_THAT(IceSwitchProposal(reason, empty_switch_result, reply_expected),
              SwitchProposalEq(reason, empty_switch_result, reply_expected));

  IceControllerInterface::SwitchResult null_switch_result{
      nullptr, recheck_event, conns_to_forget};
  EXPECT_THAT(IceSwitchProposal(reason, null_switch_result, reply_expected),
              SwitchProposalEq(reason, null_switch_result, reply_expected));

  IceControllerInterface::SwitchResult switch_result_no_recheck{
      conn, std::nullopt, conns_to_forget};
  EXPECT_THAT(
      IceSwitchProposal(reason, switch_result_no_recheck, reply_expected),
      SwitchProposalEq(reason, switch_result_no_recheck, reply_expected));

  IceControllerInterface::SwitchResult switch_result_empty_conns_to_forget{
      conn, recheck_event, empty_conns_to_forget};
  EXPECT_THAT(IceSwitchProposal(reason, switch_result_empty_conns_to_forget,
                                reply_expected),
              SwitchProposalEq(reason, switch_result_empty_conns_to_forget,
                               reply_expected));

  IceControllerInterface::SwitchResult switch_result_null_conns_to_forget{
      conn, recheck_event, null_conns_to_forget};
  EXPECT_THAT(IceSwitchProposal(reason, switch_result_null_conns_to_forget,
                                reply_expected),
              SwitchProposalEq(reason, switch_result_null_conns_to_forget,
                               reply_expected));
}

TEST_F(IceProposalTest, ConstructIcePruneProposal) {
  const Connection* conn = GetConnection(kIp, kPort);
  const Connection* conn_two = GetConnection(kIpTwo, kPort);
  const bool reply_expected = true;

  std::vector<const Connection*> conns_to_prune{conn, conn_two};
  EXPECT_THAT(IcePruneProposal(conns_to_prune, reply_expected),
              PruneProposalEq(conns_to_prune, reply_expected));

  std::vector<const Connection*> empty_conns_to_prune{};
  EXPECT_THAT(IcePruneProposal(empty_conns_to_prune, reply_expected),
              PruneProposalEq(empty_conns_to_prune, reply_expected));

  std::vector<const Connection*> null_conns_to_prune{nullptr};
  EXPECT_THAT(IcePruneProposal(null_conns_to_prune, reply_expected),
              PruneProposalEq(null_conns_to_prune, reply_expected));

  std::vector<const Connection*> mixed_conns_to_prune{nullptr, conn, nullptr};
  EXPECT_THAT(IcePruneProposal(mixed_conns_to_prune, reply_expected),
              PruneProposalEq(mixed_conns_to_prune, reply_expected));
}

}  // unnamed namespace