|
34 | 34 | #include "modules/audio_processing/include/audio_processing.h" |
35 | 35 | #include "p2p/base/port_allocator.h" |
36 | 36 | #include "pc/peer_connection_wrapper.h" |
| 37 | +#include "pc/session_description.h" |
37 | 38 | #include "pc/test/fake_audio_capture_module.h" |
38 | 39 | #include "pc/test/mock_peer_connection_observers.h" |
39 | 40 | #include "rtc_base/rtc_certificate_generator.h" |
@@ -467,4 +468,83 @@ TEST_F(SdpOfferAnswerTest, RollbackPreservesAddTrackMid) { |
467 | 468 | EXPECT_EQ(saved_mid, first_transceiver->mid()); |
468 | 469 | } |
469 | 470 |
|
| 471 | +#ifdef WEBRTC_HAVE_SCTP |
| 472 | + |
| 473 | +TEST_F(SdpOfferAnswerTest, RejectedDataChannelsDoNotGetReoffered) { |
| 474 | + auto pc = CreatePeerConnection(); |
| 475 | + EXPECT_TRUE(pc->pc()->CreateDataChannelOrError("dc", nullptr).ok()); |
| 476 | + EXPECT_TRUE(pc->CreateOfferAndSetAsLocal()); |
| 477 | + auto mid = pc->pc()->local_description()->description()->contents()[0].mid(); |
| 478 | + |
| 479 | + // An answer that rejects the datachannel content. |
| 480 | + std::string sdp = |
| 481 | + "v=0\r\n" |
| 482 | + "o=- 4131505339648218884 3 IN IP4 **-----**\r\n" |
| 483 | + "s=-\r\n" |
| 484 | + "t=0 0\r\n" |
| 485 | + "a=ice-ufrag:zGWFZ+fVXDeN6UoI/136\r\n" |
| 486 | + "a=ice-pwd:9AUNgUqRNI5LSIrC1qFD2iTR\r\n" |
| 487 | + "a=fingerprint:sha-256 " |
| 488 | + "AD:52:52:E0:B1:37:34:21:0E:15:8E:B7:56:56:7B:B4:39:0E:6D:1C:F5:84:A7:EE:" |
| 489 | + "B5:27:3E:30:B1:7D:69:42\r\n" |
| 490 | + "a=setup:passive\r\n" |
| 491 | + "m=application 0 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
| 492 | + "c=IN IP4 0.0.0.0\r\n" |
| 493 | + "a=sctp-port:5000\r\n" |
| 494 | + "a=max-message-size:262144\r\n" |
| 495 | + "a=mid:" + |
| 496 | + mid + "\r\n"; |
| 497 | + auto answer = CreateSessionDescription(SdpType::kAnswer, sdp); |
| 498 | + ASSERT_TRUE(pc->SetRemoteDescription(std::move(answer))); |
| 499 | + // The subsequent offer should not recycle the m-line since the existing data |
| 500 | + // channel is closed. |
| 501 | + auto offer = pc->CreateOffer(); |
| 502 | + const auto& offer_contents = offer->description()->contents(); |
| 503 | + ASSERT_EQ(offer_contents.size(), 1u); |
| 504 | + EXPECT_EQ(offer_contents[0].mid(), mid); |
| 505 | + EXPECT_EQ(offer_contents[0].rejected, true); |
| 506 | +} |
| 507 | + |
| 508 | +TEST_F(SdpOfferAnswerTest, RejectedDataChannelsDoGetReofferedWhenActive) { |
| 509 | + auto pc = CreatePeerConnection(); |
| 510 | + EXPECT_TRUE(pc->pc()->CreateDataChannelOrError("dc", nullptr).ok()); |
| 511 | + EXPECT_TRUE(pc->CreateOfferAndSetAsLocal()); |
| 512 | + auto mid = pc->pc()->local_description()->description()->contents()[0].mid(); |
| 513 | + |
| 514 | + // An answer that rejects the datachannel content. |
| 515 | + std::string sdp = |
| 516 | + "v=0\r\n" |
| 517 | + "o=- 4131505339648218884 3 IN IP4 **-----**\r\n" |
| 518 | + "s=-\r\n" |
| 519 | + "t=0 0\r\n" |
| 520 | + "a=ice-ufrag:zGWFZ+fVXDeN6UoI/136\r\n" |
| 521 | + "a=ice-pwd:9AUNgUqRNI5LSIrC1qFD2iTR\r\n" |
| 522 | + "a=fingerprint:sha-256 " |
| 523 | + "AD:52:52:E0:B1:37:34:21:0E:15:8E:B7:56:56:7B:B4:39:0E:6D:1C:F5:84:A7:EE:" |
| 524 | + "B5:27:3E:30:B1:7D:69:42\r\n" |
| 525 | + "a=setup:passive\r\n" |
| 526 | + "m=application 0 UDP/DTLS/SCTP webrtc-datachannel\r\n" |
| 527 | + "c=IN IP4 0.0.0.0\r\n" |
| 528 | + "a=sctp-port:5000\r\n" |
| 529 | + "a=max-message-size:262144\r\n" |
| 530 | + "a=mid:" + |
| 531 | + mid + "\r\n"; |
| 532 | + auto answer = CreateSessionDescription(SdpType::kAnswer, sdp); |
| 533 | + ASSERT_TRUE(pc->SetRemoteDescription(std::move(answer))); |
| 534 | + |
| 535 | + // The subsequent offer should recycle the m-line when there is a new data |
| 536 | + // channel. |
| 537 | + EXPECT_TRUE(pc->pc()->CreateDataChannelOrError("dc2", nullptr).ok()); |
| 538 | + EXPECT_TRUE(pc->pc()->ShouldFireNegotiationNeededEvent( |
| 539 | + pc->observer()->latest_negotiation_needed_event())); |
| 540 | + |
| 541 | + auto offer = pc->CreateOffer(); |
| 542 | + const auto& offer_contents = offer->description()->contents(); |
| 543 | + ASSERT_EQ(offer_contents.size(), 1u); |
| 544 | + EXPECT_EQ(offer_contents[0].mid(), mid); |
| 545 | + EXPECT_EQ(offer_contents[0].rejected, false); |
| 546 | +} |
| 547 | + |
| 548 | +#endif // WEBRTC_HAVE_SCTP |
| 549 | + |
470 | 550 | } // namespace webrtc |
0 commit comments