Bug 1656438 - Simplify TestAudioTrackGraph.ErrorStateCrash. r=padenot

Depends on D89746

Differential Revision: https://phabricator.services.mozilla.com/D89747
This commit is contained in:
Andreas Pehrson 2020-09-15 11:53:52 +00:00
Родитель ec3f42e3a3
Коммит 102d6e1cc5
2 изменённых файлов: 21 добавлений и 16 удалений

Просмотреть файл

@ -201,6 +201,8 @@ class MockCubebStream {
return mFramesProcessedEvent;
}
MediaEventSource<void>& ErrorForcedEvent() { return mErrorForcedEvent; }
private:
// Simulates the audio thread. The thread is created at Start anda destroyed
// at Stop. At next StreamStart a new thread is created.
@ -228,7 +230,9 @@ class MockCubebStream {
break;
}
if (mForceErrorState) {
mForceErrorState = false;
mStateCallback(stream, mUserPtr, CUBEB_STATE_ERROR);
mErrorForcedEvent.Notify();
break;
}
uint32_t sampleRate(mInputParams.rate ? mInputParams.rate
@ -280,6 +284,7 @@ class MockCubebStream {
AudioVerifier<AudioDataValue> mAudioVerifier;
MediaEventProducer<uint32_t> mFramesProcessedEvent;
MediaEventProducer<void> mErrorForcedEvent;
};
// This class has two facets: it is both a fake cubeb backend that is intended

Просмотреть файл

@ -247,25 +247,25 @@ TEST(TestAudioTrackGraph, ErrorStateCrash)
MediaTrackGraph::AUDIO_THREAD_DRIVER, /*window*/ nullptr,
MediaTrackGraph::REQUEST_DEFAULT_SAMPLE_RATE, nullptr);
// Dummy track to make graph rolling. Add it and remove it to remove the
// graph from the global hash table and let it shutdown.
RefPtr<SourceMediaTrack> dummySource =
graph->CreateSourceTrack(MediaSegment::AUDIO);
RefPtr<SourceMediaTrack> dummySource;
auto started = Invoke([&] {
// Dummy track to make graph rolling. Add it and remove it to remove the
// graph from the global hash table and let it shutdown.
dummySource = graph->CreateSourceTrack(MediaSegment::AUDIO);
return graph->NotifyWhenDeviceStarted(dummySource);
});
RefPtr<GenericPromise> p = graph->NotifyWhenDeviceStarted(dummySource);
MockCubebStream* stream = WaitFor(cubeb->StreamInitEvent());
Result<bool, nsresult> rv = WaitFor(started);
EXPECT_TRUE(rv.unwrapOr(false));
GMPTestMonitor mon;
// Force a cubeb state_callback error and see that we don't crash.
DispatchFunction([&] { stream->ForceError(); });
WaitFor(stream->ErrorForcedEvent());
p->Then(GetMainThreadSerialEventTarget(), __func__,
[&mon, dummySource, cubeb]() {
cubeb->CurrentStream()->ForceError();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
// Test has finished, destroy the track to shutdown the MTG.
dummySource->Destroy();
mon.SetFinished();
});
mon.AwaitFinished();
// Test has finished, destroy the track to shut down the MTG.
DispatchMethod(dummySource, &SourceMediaTrack::Destroy);
WaitFor(cubeb->StreamDestroyEvent());
}
TEST(TestAudioTrackGraph, SourceTrack)