tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e36f39e8bae3b1e11422f293e46bd0fc71b76510
parent 763e5000b7bf81f08d72cb29c93582e47c655858
Author: Dan Baker <dbaker@mozilla.com>
Date:   Mon,  1 Dec 2025 16:58:17 -0700

Bug 2000941 - Vendor libwebrtc from 706520bd0c

Upstream commit: https://webrtc.googlesource.com/src/+/706520bd0c997a512e7c0e1cef613fe1ef646115
    Use injected clock in pc/test

    This means setting up the environment in the test classes and
    propogating modified versions to the peer connection with the field
    trials required.

    Bug: webrtc:42223992
    Change-Id: I91355023e5b64ab8e045b2e583e7fb6b539475e9
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408101
    Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
    Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
    Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
    Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45572}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0102.patch | 2+-
Mthird_party/libwebrtc/pc/BUILD.gn | 7++++++-
Mthird_party/libwebrtc/pc/peer_connection_adaptation_integrationtest.cc | 23++++++++++++++---------
Mthird_party/libwebrtc/pc/peer_connection_callsetup_perf_tests.cc | 8++++++--
Mthird_party/libwebrtc/pc/peer_connection_encodings_integrationtest.cc | 12++++++++----
Mthird_party/libwebrtc/pc/peer_connection_end_to_end_unittest.cc | 9++++++---
Mthird_party/libwebrtc/pc/peer_connection_integrationtest.cc | 20+++++++++-----------
Mthird_party/libwebrtc/pc/rtc_stats_integrationtest.cc | 11+++++++----
Mthird_party/libwebrtc/pc/test/integration_test_helpers.cc | 5+----
Mthird_party/libwebrtc/pc/test/integration_test_helpers.h | 33++++++++++++++++++++-------------
Mthird_party/libwebrtc/pc/test/peer_connection_test_wrapper.cc | 11++++++++---
Mthird_party/libwebrtc/pc/test/peer_connection_test_wrapper.h | 3+++
13 files changed, 91 insertions(+), 57 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T23:55:14.213672+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T23:58:02.723130+00:00. # base of lastest vendoring -176f169606 +706520bd0c diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch @@ -601,7 +601,7 @@ index b7561e53b6..fe7eb57423 100644 import("../../webrtc.gni") diff --git a/pc/BUILD.gn b/pc/BUILD.gn -index 696829d6ca..81bd2a6215 100644 +index f43d1b9ba1..2efd33c566 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -30,8 +30,8 @@ diff --git a/third_party/libwebrtc/pc/BUILD.gn b/third_party/libwebrtc/pc/BUILD.gn @@ -2272,6 +2272,8 @@ if (rtc_include_tests && !build_with_chromium) { "../api:scoped_refptr", "../api/audio_codecs:builtin_audio_decoder_factory", "../api/audio_codecs:builtin_audio_encoder_factory", + "../api/environment", + "../api/environment:environment_factory", "../api/test/metrics:global_metrics_logger_and_exporter", "../api/test/metrics:metric", "../api/units:time_delta", @@ -2300,6 +2302,7 @@ if (rtc_include_tests && !build_with_chromium) { "../rtc_base:threading", "../rtc_base:timeutils", "../system_wrappers", + "../test:create_test_environment", "../test:create_test_field_trials", "../test:test_support", "../test:wait_until", @@ -2737,6 +2740,7 @@ if (rtc_include_tests && !build_with_chromium) { "../api:sequence_checker", "../api/audio:builtin_audio_processing_builder", "../api/crypto:options", + "../api/environment", "../api/environment:environment_factory", "../api/metronome", "../api/rtc_event_log:rtc_event_log_factory", @@ -2763,7 +2767,9 @@ if (rtc_include_tests && !build_with_chromium) { "../rtc_base:task_queue_for_test", "../rtc_base:threading", "../rtc_base:timeutils", + "../system_wrappers", "../system_wrappers:metrics", + "../test:create_test_environment", "../test:create_test_field_trials", "../test:test_support", "../test:wait_until", @@ -2858,7 +2864,6 @@ if (rtc_include_tests && !build_with_chromium) { "../api:dtls_transport_interface", "../api:field_trials", "../api:field_trials_view", - "../api:field_trials_view", "../api:frame_transformer_interface", "../api:libjingle_logging_api", "../api:libjingle_peerconnection_api", diff --git a/third_party/libwebrtc/pc/peer_connection_adaptation_integrationtest.cc b/third_party/libwebrtc/pc/peer_connection_adaptation_integrationtest.cc @@ -14,6 +14,7 @@ #include "api/adaptation/resource.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" +#include "api/environment/environment.h" #include "api/make_ref_counted.h" #include "api/media_stream_interface.h" #include "api/peer_connection_interface.h" @@ -29,8 +30,9 @@ #include "pc/test/peer_connection_test_wrapper.h" #include "rtc_base/checks.h" #include "rtc_base/thread.h" -#include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" +#include "system_wrappers/include/clock.h" +#include "test/create_test_environment.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/wait_until.h" @@ -53,10 +55,11 @@ void Negotiate(scoped_refptr<PeerConnectionTestWrapper> caller, } TrackWithPeriodicSource CreateTrackWithPeriodicSource( + Clock& clock, scoped_refptr<PeerConnectionFactoryInterface> factory) { FakePeriodicVideoSource::Config periodic_track_source_config; periodic_track_source_config.frame_interval_ms = 100; - periodic_track_source_config.timestamp_offset_ms = TimeMillis(); + periodic_track_source_config.timestamp_offset_ms = clock.TimeInMilliseconds(); scoped_refptr<FakePeriodicVideoTrackSource> periodic_track_source = make_ref_counted<FakePeriodicVideoTrackSource>( periodic_track_source_config, /* remote */ false); @@ -68,9 +71,9 @@ TrackWithPeriodicSource CreateTrackWithPeriodicSource( } // Triggers overuse and obtains VideoSinkWants. Adaptation processing happens in -// parallel and this function makes no guarantee that the returnd VideoSinkWants -// have yet to reflect the overuse signal. Used together with EXPECT_TRUE_WAIT -// to "spam overuse until a change is observed". +// parallel and this function makes no guarantee that the returned +// VideoSinkWants have yet to reflect the overuse signal. Used together with +// EXPECT_TRUE_WAIT to "spam overuse until a change is observed". VideoSinkWants TriggerOveruseAndGetSinkWants( scoped_refptr<FakeResource> fake_resource, const FakePeriodicVideoSource& source) { @@ -81,7 +84,8 @@ VideoSinkWants TriggerOveruseAndGetSinkWants( class PeerConnectionAdaptationIntegrationTest : public ::testing::Test { public: PeerConnectionAdaptationIntegrationTest() - : virtual_socket_server_(), + : env_(CreateTestEnvironment()), + virtual_socket_server_(), network_thread_(new Thread(&virtual_socket_server_)), worker_thread_(Thread::Create()) { RTC_CHECK(network_thread_->Start()); @@ -91,7 +95,7 @@ class PeerConnectionAdaptationIntegrationTest : public ::testing::Test { scoped_refptr<PeerConnectionTestWrapper> CreatePcWrapper(const char* name) { scoped_refptr<PeerConnectionTestWrapper> pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>( - name, &virtual_socket_server_, network_thread_.get(), + name, env_, &virtual_socket_server_, network_thread_.get(), worker_thread_.get()); PeerConnectionInterface::RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; @@ -101,6 +105,7 @@ class PeerConnectionAdaptationIntegrationTest : public ::testing::Test { } protected: + const Environment env_; VirtualSocketServer virtual_socket_server_; std::unique_ptr<Thread> network_thread_; std::unique_ptr<Thread> worker_thread_; @@ -114,7 +119,7 @@ TEST_F(PeerConnectionAdaptationIntegrationTest, // Adding a track and negotiating ensures that a VideoSendStream exists. TrackWithPeriodicSource track_with_source = - CreateTrackWithPeriodicSource(caller_wrapper->pc_factory()); + CreateTrackWithPeriodicSource(env_.clock(), caller_wrapper->pc_factory()); auto sender = caller->AddTrack(track_with_source.track, {}).value(); Negotiate(caller_wrapper, callee_wrapper); // Prefer degrading resolution. @@ -150,7 +155,7 @@ TEST_F(PeerConnectionAdaptationIntegrationTest, // Adding a track and negotiating ensures that a VideoSendStream exists. TrackWithPeriodicSource track_with_source = - CreateTrackWithPeriodicSource(caller_wrapper->pc_factory()); + CreateTrackWithPeriodicSource(env_.clock(), caller_wrapper->pc_factory()); auto sender = caller->AddTrack(track_with_source.track, {}).value(); Negotiate(caller_wrapper, callee_wrapper); // Prefer degrading resolution. diff --git a/third_party/libwebrtc/pc/peer_connection_callsetup_perf_tests.cc b/third_party/libwebrtc/pc/peer_connection_callsetup_perf_tests.cc @@ -21,6 +21,7 @@ #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/data_channel_interface.h" +#include "api/environment/environment.h" #include "api/jsep.h" #include "api/make_ref_counted.h" #include "api/rtc_error.h" @@ -37,6 +38,7 @@ #include "rtc_base/thread.h" #include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" @@ -60,7 +62,8 @@ class PeerConnectionDataChannelOpenTest /*dtls_role=*/ConnectionRole>> { public: PeerConnectionDataChannelOpenTest() - : background_thread_(std::make_unique<Thread>(&vss_)) { + : env_(CreateTestEnvironment()), + background_thread_(std::make_unique<Thread>(&vss_)) { RTC_CHECK(background_thread_->Start()); // Delay is set to 50ms so we get a 100ms RTT. vss_.set_delay_mean(/*delay_mean=*/50); @@ -70,7 +73,7 @@ class PeerConnectionDataChannelOpenTest scoped_refptr<PeerConnectionTestWrapper> CreatePc( absl::string_view field_trials = "") { auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>( - "pc", &vss_, background_thread_.get(), background_thread_.get()); + "pc", env_, &vss_, background_thread_.get(), background_thread_.get()); pc_wrapper->CreatePc({}, CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), CreateTestFieldTrialsPtr(field_trials)); @@ -171,6 +174,7 @@ class PeerConnectionDataChannelOpenTest return true; } + const Environment env_; VirtualSocketServer vss_; std::unique_ptr<Thread> background_thread_; }; diff --git a/third_party/libwebrtc/pc/peer_connection_encodings_integrationtest.cc b/third_party/libwebrtc/pc/peer_connection_encodings_integrationtest.cc @@ -26,6 +26,7 @@ #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_options.h" +#include "api/environment/environment.h" #include "api/field_trials_view.h" #include "api/jsep.h" #include "api/make_ref_counted.h" @@ -57,6 +58,7 @@ #include "rtc_base/logging.h" #include "rtc_base/physical_socket_server.h" #include "rtc_base/thread.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" @@ -226,14 +228,15 @@ const RTCOutboundRtpStreamStats* FindOutboundRtpByRid( class PeerConnectionEncodingsIntegrationTest : public ::testing::Test { public: PeerConnectionEncodingsIntegrationTest() - : background_thread_(std::make_unique<Thread>(&pss_)) { + : env_(CreateTestEnvironment()), + background_thread_(std::make_unique<Thread>(&pss_)) { RTC_CHECK(background_thread_->Start()); } scoped_refptr<PeerConnectionTestWrapper> CreatePc( absl::string_view field_trials = "") { auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>( - "pc", &pss_, background_thread_.get(), background_thread_.get()); + "pc", env_, &pss_, background_thread_.get(), background_thread_.get()); pc_wrapper->CreatePc({}, CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), CreateTestFieldTrialsPtr(field_trials)); @@ -419,6 +422,7 @@ class PeerConnectionEncodingsIntegrationTest : public ::testing::Test { return true; } + const Environment env_; PhysicalSocketServer pss_; std::unique_ptr<Thread> background_thread_; }; @@ -3082,7 +3086,7 @@ class PeerConnectionEncodingsFakeCodecsIntegrationTest std::make_unique<FakeWebRtcVideoDecoderFactory>(); video_decoder_factory->AddSupportedVideoCodecType("H265"); auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>( - "pc", &pss_, background_thread_.get(), background_thread_.get()); + "pc", env_, &pss_, background_thread_.get(), background_thread_.get()); pc_wrapper->CreatePc( {}, CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), std::move(video_encoder_factory), @@ -3120,7 +3124,7 @@ class PeerConnectionEncodingsFakeCodecsIntegrationTest {"profile-level-id", "f4001f"}}, // recvonly {ScalabilityMode::kL1T1})); auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>( - "pc", &pss_, background_thread_.get(), background_thread_.get()); + "pc", env_, &pss_, background_thread_.get(), background_thread_.get()); pc_wrapper->CreatePc( {}, CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), std::move(video_encoder_factory), diff --git a/third_party/libwebrtc/pc/peer_connection_end_to_end_unittest.cc b/third_party/libwebrtc/pc/peer_connection_end_to_end_unittest.cc @@ -46,6 +46,7 @@ #include "rtc_base/physical_socket_server.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/thread.h" +#include "test/create_test_environment.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/wait_until.h" @@ -83,14 +84,15 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>, DataChannelList; explicit PeerConnectionEndToEndBaseTest(SdpSemantics sdp_semantics) - : network_thread_(std::make_unique<webrtc::Thread>(&pss_)), + : env_(webrtc::CreateTestEnvironment()), + network_thread_(std::make_unique<webrtc::Thread>(&pss_)), worker_thread_(webrtc::Thread::Create()) { RTC_CHECK(network_thread_->Start()); RTC_CHECK(worker_thread_->Start()); caller_ = webrtc::make_ref_counted<PeerConnectionTestWrapper>( - "caller", &pss_, network_thread_.get(), worker_thread_.get()); + "caller", env_, &pss_, network_thread_.get(), worker_thread_.get()); callee_ = webrtc::make_ref_counted<PeerConnectionTestWrapper>( - "callee", &pss_, network_thread_.get(), worker_thread_.get()); + "callee", env_, &pss_, network_thread_.get(), worker_thread_.get()); webrtc::PeerConnectionInterface::IceServer ice_server; ice_server.uri = "stun:stun.l.google.com:19302"; config_.servers.push_back(ice_server); @@ -253,6 +255,7 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>, protected: webrtc::AutoThread main_thread_; webrtc::PhysicalSocketServer pss_; + webrtc::Environment env_; std::unique_ptr<webrtc::Thread> network_thread_; std::unique_ptr<webrtc::Thread> worker_thread_; webrtc::scoped_refptr<PeerConnectionTestWrapper> caller_; diff --git a/third_party/libwebrtc/pc/peer_connection_integrationtest.cc b/third_party/libwebrtc/pc/peer_connection_integrationtest.cc @@ -75,7 +75,6 @@ #include "pc/test/fake_periodic_video_source.h" #include "pc/test/integration_test_helpers.h" #include "pc/test/mock_peer_connection_observers.h" -#include "rtc_base/checks.h" #include "rtc_base/fake_clock.h" #include "rtc_base/fake_mdns_responder.h" #include "rtc_base/fake_network.h" @@ -90,7 +89,6 @@ #include "rtc_base/string_encode.h" #include "rtc_base/task_queue_for_test.h" #include "rtc_base/test_certificate_verifier.h" -#include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" #include "system_wrappers/include/metrics.h" #include "test/gmock.h" @@ -380,7 +378,7 @@ TEST_P(PeerConnectionIntegrationTest, FakePeriodicVideoSource::Config config; config.width = 1280; config.height = 720; - config.timestamp_offset_ms = TimeMillis(); + config.timestamp_offset_ms = env_.clock().TimeInMilliseconds(); caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); @@ -2524,7 +2522,7 @@ TEST_P(PeerConnectionIntegrationTestWithFakeClock, // For explanation of these values, see comment above. static constexpr int required_media_hops = 9; static constexpr int required_signaling_trips = 2; - // For internal delays (such as posting an event asychronously). + // For internal delays (such as posting an event asynchronously). static constexpr int allowed_internal_delay_ms = 20; static constexpr int total_connection_time_ms = media_hop_delay_ms * required_media_hops + @@ -2986,7 +2984,7 @@ TEST_P(PeerConnectionIntegrationTest, UnsignaledSsrcGetSourcesVideo) { // Similar to the above test, except instead of waiting until GetSources() is // non-empty we wait until media is flowing and then assert that GetSources() // is not empty. This provides test coverage for https://crbug.com/webrtc/14817 -// where a race due to the re-creationg of the unsignaled ssrc stream would +// where a race due to the re-creation of the unsignaled ssrc stream would // clear the GetSources() history. This test not flaking confirms the bug fix. // TODO(crbug.com/webrtc/441652589): Figure out why this is flaking and // re-enable the test. @@ -3632,12 +3630,12 @@ TEST_F(PeerConnectionIntegrationTestUnifiedPlan, } current_size = caller()->pc()->GetTransceivers().size(); RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; - auto start_time_ms = TimeMillis(); + auto start_time_ms = env_.clock().TimeInMilliseconds(); caller()->CreateAndSetAndSignalOffer(); // We want to stop when the time exceeds one second. ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()), IsRtcOk()); - auto elapsed_time_ms = TimeMillis() - start_time_ms; + auto elapsed_time_ms = env_.clock().TimeInMilliseconds() - start_time_ms; RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; ASSERT_GT(1000, elapsed_time_ms) << "Audio transceivers: Negotiation took too long after " @@ -3670,12 +3668,12 @@ TEST_F(PeerConnectionIntegrationTestUnifiedPlan, } current_size = caller()->pc()->GetTransceivers().size(); RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; - auto start_time_ms = TimeMillis(); + auto start_time_ms = env_.clock().TimeInMilliseconds(); caller()->CreateAndSetAndSignalOffer(); // We want to stop when the time exceeds one second. ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()), IsRtcOk()); - auto elapsed_time_ms = TimeMillis() - start_time_ms; + auto elapsed_time_ms = env_.clock().TimeInMilliseconds() - start_time_ms; RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; ASSERT_GT(1000, elapsed_time_ms) << "Video transceivers: Negotiation took too long after " @@ -3714,12 +3712,12 @@ TEST_F(PeerConnectionIntegrationTestUnifiedPlan, } current_size = caller()->pc()->GetTransceivers().size(); RTC_LOG(LS_INFO) << "Renegotiating with " << current_size << " tracks"; - auto start_time_ms = TimeMillis(); + auto start_time_ms = env_.clock().TimeInMilliseconds(); caller()->CreateAndSetAndSignalOffer(); // We want to stop when the time exceeds one second. ASSERT_THAT(WaitUntil([&] { return SignalingStateStable(); }, IsTrue()), IsRtcOk()); - auto elapsed_time_ms = TimeMillis() - start_time_ms; + auto elapsed_time_ms = env_.clock().TimeInMilliseconds() - start_time_ms; RTC_LOG(LS_INFO) << "Renegotiating took " << elapsed_time_ms << " ms"; // This is a guard against the test using excessive amounts of time. ASSERT_GT(5000, elapsed_time_ms) diff --git a/third_party/libwebrtc/pc/rtc_stats_integrationtest.cc b/third_party/libwebrtc/pc/rtc_stats_integrationtest.cc @@ -21,7 +21,7 @@ #include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_options.h" #include "api/data_channel_interface.h" -#include "api/field_trials.h" +#include "api/environment/environment.h" #include "api/make_ref_counted.h" #include "api/media_stream_interface.h" #include "api/media_types.h" @@ -44,6 +44,7 @@ #include "rtc_base/thread.h" #include "rtc_base/trace_event.h" #include "rtc_base/virtual_socket_server.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" @@ -62,16 +63,17 @@ constexpr int64_t kGetStatsTimeoutMs = 10000; class RTCStatsIntegrationTest : public ::testing::Test { public: RTCStatsIntegrationTest() - : network_thread_(new Thread(&virtual_socket_server_)), + : env_(CreateTestEnvironment()), + network_thread_(new Thread(&virtual_socket_server_)), worker_thread_(Thread::Create()) { RTC_CHECK(network_thread_->Start()); RTC_CHECK(worker_thread_->Start()); caller_ = make_ref_counted<PeerConnectionTestWrapper>( - "caller", &virtual_socket_server_, network_thread_.get(), + "caller", env_, &virtual_socket_server_, network_thread_.get(), worker_thread_.get()); callee_ = make_ref_counted<PeerConnectionTestWrapper>( - "callee", &virtual_socket_server_, network_thread_.get(), + "callee", env_, &virtual_socket_server_, network_thread_.get(), worker_thread_.get()); } @@ -159,6 +161,7 @@ class RTCStatsIntegrationTest : public ::testing::Test { // `network_thread_` uses `virtual_socket_server_` so they must be // constructed/destructed in the correct order. + const Environment env_; VirtualSocketServer virtual_socket_server_; std::unique_ptr<Thread> network_thread_; std::unique_ptr<Thread> worker_thread_; diff --git a/third_party/libwebrtc/pc/test/integration_test_helpers.cc b/third_party/libwebrtc/pc/test/integration_test_helpers.cc @@ -21,8 +21,6 @@ #include "api/audio/builtin_audio_processing_builder.h" #include "api/create_modular_peer_connection_factory.h" #include "api/enable_media_with_defaults.h" -#include "api/environment/environment_factory.h" -#include "api/field_trials_view.h" #include "api/jsep.h" #include "api/peer_connection_interface.h" #include "api/rtc_event_log/rtc_event_log_factory.h" @@ -223,7 +221,6 @@ bool PeerConnectionIntegrationWrapper::Init( SocketServer* socket_server, Thread* network_thread, Thread* worker_thread, - std::unique_ptr<FieldTrialsView> field_trials, std::unique_ptr<FakeRtcEventLogFactory> event_log_factory, bool reset_encoder_factory, bool reset_decoder_factory, @@ -250,7 +247,7 @@ bool PeerConnectionIntegrationWrapper::Init( pc_factory_dependencies.signaling_thread = signaling_thread; pc_factory_dependencies.socket_factory = socket_server; pc_factory_dependencies.network_manager = std::move(network_manager); - pc_factory_dependencies.env = CreateEnvironment(std::move(field_trials)); + pc_factory_dependencies.env = env_; pc_factory_dependencies.decode_metronome = std::make_unique<TaskQueueMetronome>(TimeDelta::Millis(8)); diff --git a/third_party/libwebrtc/pc/test/integration_test_helpers.h b/third_party/libwebrtc/pc/test/integration_test_helpers.h @@ -34,7 +34,8 @@ #include "api/crypto/crypto_options.h" #include "api/data_channel_interface.h" #include "api/dtls_transport_interface.h" -#include "api/field_trials_view.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "api/ice_transport_interface.h" #include "api/jsep.h" #include "api/make_ref_counted.h" @@ -90,9 +91,10 @@ #include "rtc_base/ssl_stream_adapter.h" #include "rtc_base/task_queue_for_test.h" #include "rtc_base/thread.h" -#include "rtc_base/time_utils.h" #include "rtc_base/virtual_socket_server.h" +#include "system_wrappers/include/clock.h" #include "system_wrappers/include/metrics.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" @@ -362,7 +364,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, scoped_refptr<VideoTrackInterface> CreateLocalVideoTrack() { FakePeriodicVideoSource::Config config; - config.timestamp_offset_ms = TimeMillis(); + config.timestamp_offset_ms = env_.clock().TimeInMilliseconds(); return CreateLocalVideoTrackInternal(config); } @@ -375,7 +377,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, VideoRotation rotation) { FakePeriodicVideoSource::Config config; config.rotation = rotation; - config.timestamp_offset_ms = TimeMillis(); + config.timestamp_offset_ms = env_.clock().TimeInMilliseconds(); return CreateLocalVideoTrackInternal(config); } @@ -793,8 +795,9 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, private: // Constructor used by friend class PeerConnectionIntegrationBaseTest. - explicit PeerConnectionIntegrationWrapper(const std::string& debug_name) - : debug_name_(debug_name) {} + explicit PeerConnectionIntegrationWrapper(const std::string& debug_name, + Environment env) + : debug_name_(debug_name), env_(env) {} bool Init(const PeerConnectionFactory::Options* options, const PeerConnectionInterface::RTCConfiguration* config, @@ -802,7 +805,6 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, SocketServer* socket_server, Thread* network_thread, Thread* worker_thread, - std::unique_ptr<FieldTrialsView> field_trials, std::unique_ptr<FakeRtcEventLogFactory> event_log_factory, bool reset_encoder_factory, bool reset_decoder_factory, @@ -916,7 +918,6 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, return description; } - // This is a work around to remove unused fake_video_renderers from // transceivers that have either stopped or are no longer receiving. void RemoveUnusedVideoRenderers() { @@ -1145,6 +1146,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, } std::string debug_name_; + const Environment env_; // Network manager is owned by the `peer_connection_factory_`. FakeNetworkManager* fake_network_manager_ = nullptr; @@ -1378,6 +1380,7 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics) : sdp_semantics_(sdp_semantics), + env_(CreateTestEnvironment()), ss_(new VirtualSocketServer()), fss_(new FirewallSocketServer(ss_.get())), network_thread_(new Thread(fss_.get())), @@ -1475,17 +1478,20 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { dependencies.cert_generator = std::make_unique<FakeRTCCertificateGenerator>(); } - std::unique_ptr<PeerConnectionIntegrationWrapper> client( - new PeerConnectionIntegrationWrapper(debug_name)); - std::string field_trials = field_trials_; auto it = field_trials_overrides_.find(debug_name); if (it != field_trials_overrides_.end()) { field_trials = it->second; } + // Override the field trials in the environment. + EnvironmentFactory env = EnvironmentFactory(env_); + env.Set(CreateTestFieldTrialsPtr(field_trials)); + + std::unique_ptr<PeerConnectionIntegrationWrapper> client( + new PeerConnectionIntegrationWrapper(debug_name, env.Create())); + if (!client->Init(options, &modified_config, std::move(dependencies), fss_.get(), network_thread_.get(), worker_thread_.get(), - CreateTestFieldTrialsPtr(field_trials), std::move(event_log_factory), reset_encoder_factory, reset_decoder_factory, create_media_engine)) { return nullptr; @@ -1722,7 +1728,7 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { PeerConnectionIntegrationWrapper* caller() { return caller_.get(); } - // Destroy peerconnections. + // Destroy peer connections. // This can be used to ensure that all pointers to on-stack mocks // get dropped before exit. void DestroyPeerConnections() { @@ -1914,6 +1920,7 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { protected: SdpSemantics sdp_semantics_; + const Environment env_; private: AutoThread main_thread_; // Used as the signal thread by most tests. diff --git a/third_party/libwebrtc/pc/test/peer_connection_test_wrapper.cc b/third_party/libwebrtc/pc/test/peer_connection_test_wrapper.cc @@ -67,7 +67,7 @@ #include "rtc_base/logging.h" #include "rtc_base/rtc_certificate_generator.h" #include "rtc_base/socket_server.h" -#include "rtc_base/time_utils.h" +#include "system_wrappers/include/clock.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/wait_until.h" @@ -154,10 +154,12 @@ void PeerConnectionTestWrapper::AwaitNegotiation( PeerConnectionTestWrapper::PeerConnectionTestWrapper( const std::string& name, + const webrtc::Environment& env, webrtc::SocketServer* socket_server, webrtc::Thread* network_thread, webrtc::Thread* worker_thread) : name_(name), + env_(env), socket_server_(socket_server), network_thread_(network_thread), worker_thread_(worker_thread), @@ -186,8 +188,11 @@ bool PeerConnectionTestWrapper::CreatePc( std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory, std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory, std::unique_ptr<webrtc::FieldTrialsView> field_trials) { + webrtc::EnvironmentFactory env_factory(env_); + env_factory.Set(field_trials.get()); + Environment env = env_factory.Create(); auto port_allocator = std::make_unique<webrtc::FakePortAllocator>( - CreateEnvironment(field_trials.get()), socket_server_, network_thread_); + env, socket_server_, network_thread_); RTC_DCHECK_RUN_ON(&pc_thread_checker_); @@ -554,7 +559,7 @@ PeerConnectionTestWrapper::GetUserMedia( // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. webrtc::FakePeriodicVideoSource::Config config; config.frame_interval_ms = 100; - config.timestamp_offset_ms = webrtc::TimeMillis(); + config.timestamp_offset_ms = env_.clock().TimeInMilliseconds(); config.width = resolution.width; config.height = resolution.height; diff --git a/third_party/libwebrtc/pc/test/peer_connection_test_wrapper.h b/third_party/libwebrtc/pc/test/peer_connection_test_wrapper.h @@ -20,6 +20,7 @@ #include "api/audio_codecs/audio_encoder_factory.h" #include "api/audio_options.h" #include "api/data_channel_interface.h" +#include "api/environment/environment.h" #include "api/field_trials_view.h" #include "api/jsep.h" #include "api/media_stream_interface.h" @@ -55,6 +56,7 @@ class PeerConnectionTestWrapper PeerConnectionTestWrapper* callee); PeerConnectionTestWrapper(const std::string& name, + const webrtc::Environment& env, webrtc::SocketServer* socket_server, webrtc::Thread* network_thread, webrtc::Thread* worker_thread); @@ -164,6 +166,7 @@ class PeerConnectionTestWrapper const std::string& candidate); std::string name_; + const webrtc::Environment env_; webrtc::SocketServer* const socket_server_; webrtc::Thread* const network_thread_; webrtc::Thread* const worker_thread_;