tor-browser

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

commit 75c1a65bd7c8fddd7aa0f0102d64afd1440f31ee
parent 244863e8ab21f9386112a2de0ef8558b7950040e
Author: Andreas Pehrson <apehrson@mozilla.com>
Date:   Tue, 11 Nov 2025 08:21:03 +0000

Bug 1931328 - Improve and simplify tests of AudioDecoderInputTrack::OnOutput. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D238749

Diffstat:
Mdom/media/gtest/TestAudioDecoderInputTrack.cpp | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/dom/media/gtest/TestAudioDecoderInputTrack.cpp b/dom/media/gtest/TestAudioDecoderInputTrack.cpp @@ -394,30 +394,21 @@ TEST_F(TestAudioDecoderInputTrack, OutputAndEndEvent) { // Append an audio and EOS, the output event should notify the amount of // frames that is equal to the amount of audio we appended. RefPtr<AudioData> audio = CreateAudioData(10); - MozPromiseHolder<GenericPromise> holder; - RefPtr<GenericPromise> p = holder.Ensure(__func__); - MediaEventListener outputListener = - mTrack->OnOutput().Connect(NS_GetCurrentThread(), [&](TrackTime aFrame) { - EXPECT_EQ(aFrame, audio->Frames()); - holder.Resolve(true, __func__); - }); + auto outputPromise = TakeN(mTrack->OnOutput(), 1); mTrack->AppendData(audio, nullptr); mTrack->NotifyEndOfStream(); TrackTime start = 0; TrackTime end = 10; mTrack->ProcessInput(start, end, ProcessedMediaTrack::ALLOW_END); - (void)WaitFor(p); + auto output = WaitFor(outputPromise).unwrap()[0]; + EXPECT_EQ(std::get<int64_t>(output), audio->Frames()); // Track should end in this iteration, so the end event should be notified. - p = holder.Ensure(__func__); - MediaEventListener endListener = mTrack->OnEnd().Connect( - NS_GetCurrentThread(), [&]() { holder.Resolve(true, __func__); }); + auto endPromise = TakeN(mTrack->OnEnd(), 1); start = end; end += 10; mTrack->ProcessInput(start, end, ProcessedMediaTrack::ALLOW_END); - (void)WaitFor(p); - outputListener.Disconnect(); - endListener.Disconnect(); + (void)WaitFor(endPromise); } TEST_F(TestAudioDecoderInputTrack, PlaybackRateChange) { @@ -445,10 +436,13 @@ TEST_F(TestAudioDecoderInputTrack, PlaybackRateChange) { mTrack->NotifyEndOfStream(); // Playback rate is 2x, so we should only get 1/2x sample frames, another 1/2 - // should be silence. + // should be silence. Output should not be rate-aware. + auto outputPromise = TakeN(mTrack->OnOutput(), 1); TrackTime start = 0; TrackTime end = audio->Frames(); mTrack->ProcessInput(start, end, kNoFlags); + auto output = WaitFor(outputPromise).unwrap()[0]; + EXPECT_EQ(std::get<int64_t>(output), audio->Frames()); EXPECT_PRED_FORMAT2(ExpectSegmentNonSilence, start, audio->Frames() / 2); EXPECT_PRED_FORMAT2(ExpectSegmentSilence, start + audio->Frames() / 2, end); }