Add support for sending packets with ECT(1) based on packet options in native WebRTC.

With L4S in WebRTC, only RTP packets are supposed to be send with ECT(1)

Bug: webrtc:42225697
Change-Id: If10bf74a867d3ea04fd1fb931cdc2a6380176270
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367220
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43343}
diff --git a/rtc_base/async_udp_socket_unittest.cc b/rtc_base/async_udp_socket_unittest.cc
index 7df1ca0..26ab09e 100644
--- a/rtc_base/async_udp_socket_unittest.cc
+++ b/rtc_base/async_udp_socket_unittest.cc
@@ -10,41 +10,46 @@
 
 #include "rtc_base/async_udp_socket.h"
 
+#include <cstdint>
 #include <memory>
-#include <string>
 
-#include "rtc_base/gunit.h"
-#include "rtc_base/physical_socket_server.h"
+#include "absl/memory/memory.h"
+#include "rtc_base/async_packet_socket.h"
+#include "rtc_base/socket.h"
+#include "rtc_base/socket_address.h"
 #include "rtc_base/virtual_socket_server.h"
+#include "test/gtest.h"
 
 namespace rtc {
 
-class AsyncUdpSocketTest : public ::testing::Test, public sigslot::has_slots<> {
- public:
-  AsyncUdpSocketTest()
-      : pss_(new rtc::PhysicalSocketServer),
-        vss_(new rtc::VirtualSocketServer(pss_.get())),
-        socket_(vss_->CreateSocket(SOCK_DGRAM)),
-        udp_socket_(new AsyncUDPSocket(socket_)),
-        ready_to_send_(false) {
-    udp_socket_->SignalReadyToSend.connect(this,
-                                           &AsyncUdpSocketTest::OnReadyToSend);
-  }
+static const SocketAddress kAddr("22.22.22.22", 0);
 
-  void OnReadyToSend(rtc::AsyncPacketSocket* socket) { ready_to_send_ = true; }
+TEST(AsyncUDPSocketTest, SetSocketOptionIfEctChange) {
+  VirtualSocketServer socket_server;
+  Socket* socket = socket_server.CreateSocket(kAddr.family(), SOCK_DGRAM);
+  std::unique_ptr<AsyncUDPSocket> udp__socket =
+      absl::WrapUnique(AsyncUDPSocket::Create(socket, kAddr));
 
- protected:
-  std::unique_ptr<PhysicalSocketServer> pss_;
-  std::unique_ptr<VirtualSocketServer> vss_;
-  Socket* socket_;
-  std::unique_ptr<AsyncUDPSocket> udp_socket_;
-  bool ready_to_send_;
-};
+  int ect = 0;
+  socket->GetOption(Socket::OPT_SEND_ECN, &ect);
+  ASSERT_EQ(ect, 0);
 
-TEST_F(AsyncUdpSocketTest, OnWriteEvent) {
-  EXPECT_FALSE(ready_to_send_);
-  socket_->SignalWriteEvent(socket_);
-  EXPECT_TRUE(ready_to_send_);
+  uint8_t buffer[] = "hello";
+  rtc::PacketOptions packet_options;
+  packet_options.ecn_1 = false;
+  udp__socket->SendTo(buffer, 5, kAddr, packet_options);
+  socket->GetOption(Socket::OPT_SEND_ECN, &ect);
+  EXPECT_EQ(ect, 0);
+
+  packet_options.ecn_1 = true;
+  udp__socket->SendTo(buffer, 5, kAddr, packet_options);
+  socket->GetOption(Socket::OPT_SEND_ECN, &ect);
+  EXPECT_EQ(ect, 1);
+
+  packet_options.ecn_1 = false;
+  udp__socket->SendTo(buffer, 5, kAddr, packet_options);
+  socket->GetOption(Socket::OPT_SEND_ECN, &ect);
+  EXPECT_EQ(ect, 0);
 }
 
 }  // namespace rtc