Use TimeController in p2p/dtls/dtls_ice_integration_fixture.h

This removes use of the ScopedFakeClock and AutoThread

Bug: webrtc:469327588
Bug: webrtc:42223992
Change-Id: I30ac1518fed228e6029e4dcf1b93bf866a6a6964
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/464462
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47478}
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index 3b769fd..937dc57 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -1268,6 +1268,7 @@
       "../api:network_emulation_manager_api",
       "../api:scoped_refptr",
       "../api:simulated_network_api",
+      "../api:time_controller",
       "../api/crypto:options",
       "../api/environment",
       "../api/environment:environment_factory",
@@ -1290,6 +1291,7 @@
       "../test:run_loop",
       "../test:test_support",
       "../test:wait_until",
+      "../test/time_controller",
       "//third_party/abseil-cpp/absl/algorithm:container",
       "//third_party/abseil-cpp/absl/container:flat_hash_set",
       "//third_party/abseil-cpp/absl/flags:flag",
diff --git a/p2p/dtls/dtls_ice_integration_fixture.h b/p2p/dtls/dtls_ice_integration_fixture.h
index 0b5374e..de16c0a 100644
--- a/p2p/dtls/dtls_ice_integration_fixture.h
+++ b/p2p/dtls/dtls_ice_integration_fixture.h
@@ -30,6 +30,7 @@
 #include "api/test/create_network_emulation_manager.h"
 #include "api/test/network_emulation_manager.h"
 #include "api/test/simulated_network.h"
+#include "api/test/time_controller.h"
 #include "api/units/data_rate.h"
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
@@ -44,7 +45,6 @@
 #include "p2p/test/fake_ice_transport.h"
 #include "rtc_base/async_packet_socket.h"
 #include "rtc_base/checks.h"
-#include "rtc_base/fake_clock.h"
 #include "rtc_base/fake_network.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/network.h"
@@ -56,6 +56,7 @@
 #include "rtc_base/thread.h"
 #include "rtc_base/virtual_socket_server.h"
 #include "test/create_test_field_trials.h"
+#include "test/time_controller/simulated_time_controller.h"
 #include "test/wait_until.h"
 
 namespace webrtc {
@@ -385,7 +386,11 @@
         RTCCertificate::Create(SSLIdentity::Create("test", KT_DEFAULT));
 
     if (network_emulation_manager_ == nullptr) {
-      thread_ = std::make_unique<AutoSocketServerThread>(ss_.get());
+      global_time_controller_ = std::make_unique<GlobalSimulatedTimeController>(
+          Timestamp::Seconds(10000), ss_.get());
+      time_controller_ = global_time_controller_.get();
+    } else {
+      time_controller_ = network_emulation_manager_->time_controller();
     }
 
     client_thread()->BlockingCall([&]() {
@@ -406,41 +411,21 @@
   }
 
   Timestamp CurrentTime() {
-    if (network_emulation_manager_ == nullptr) {
-      return Timestamp::Micros(fake_clock_.TimeNanos() / 1000);
-    } else {
-      return network_emulation_manager_->time_controller()
-          ->GetClock()
-          ->CurrentTime();
-    }
+    return time_controller_->GetClock()->CurrentTime();
   }
 
-  void AdvanceTime(TimeDelta delta) {
-    RTC_CHECK(network_emulation_manager_ != nullptr);
-    if (network_emulation_manager_ == nullptr) {
-      fake_clock_.AdvanceTime(delta);
-    } else {
-      network_emulation_manager_->time_controller()->AdvanceTime(delta);
-    }
-  }
+  void AdvanceTime(TimeDelta delta) { time_controller_->AdvanceTime(delta); }
 
   WaitUntilSettings wait_until_settings(int timeout_ms = kDefaultTimeout) {
-    if (network_emulation_manager_ == nullptr) {
-      return {
-          .timeout = TimeDelta::Millis(timeout_ms),
-          .clock = &fake_clock_,
-      };
-    } else {
-      return {
-          .timeout = TimeDelta::Millis(timeout_ms),
-          .clock = network_emulation_manager_->time_controller(),
-      };
-    }
+    return {
+        .timeout = TimeDelta::Millis(timeout_ms),
+        .clock = time_controller_,
+    };
   }
 
   Thread* thread(Endpoint& ep) {
     if (ep.emulated_network_manager == nullptr) {
-      return thread_.get();
+      return time_controller_->GetMainThread();
     } else {
       return ep.emulated_network_manager->network_thread();
     }
@@ -484,11 +469,11 @@
   }
 
   TestConfig config_;
-  ScopedFakeClock fake_clock_;
   std::unique_ptr<VirtualSocketServer> ss_;
   std::unique_ptr<BasicPacketSocketFactory> socket_factory_;
   std::unique_ptr<NetworkEmulationManager> network_emulation_manager_;
-  std::unique_ptr<AutoSocketServerThread> thread_;
+  std::unique_ptr<GlobalSimulatedTimeController> global_time_controller_;
+  TimeController* time_controller_ = nullptr;
   std::unique_ptr<FakeNetworkManager> network_manager_;
 
   Endpoint client_;