Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2756)

Unified Diff: content/renderer/media/rtc_peer_connection_handler_unittest.cc

Issue 2924563002: Make RTCPeerConnectionHandlerTest use the webrtc signaling thread. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/rtc_peer_connection_handler_unittest.cc
diff --git a/content/renderer/media/rtc_peer_connection_handler_unittest.cc b/content/renderer/media/rtc_peer_connection_handler_unittest.cc
index 1b83f15fe69b58832105646f72750b17d6d4b45b..30f7db73453b8e590e85952748e0374a9a20bb07 100644
--- a/content/renderer/media/rtc_peer_connection_handler_unittest.cc
+++ b/content/renderer/media/rtc_peer_connection_handler_unittest.cc
@@ -17,6 +17,7 @@
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "content/child/child_process.h"
@@ -249,11 +250,6 @@ class RTCPeerConnectionHandlerUnderTest : public RTCPeerConnectionHandler {
webrtc::PeerConnectionObserver* observer() {
return native_peer_connection()->observer();
}
-
- scoped_refptr<base::SingleThreadTaskRunner>
- signaling_thread() const override {
- return base::ThreadTaskRunnerHandle::Get();
- }
};
class RTCPeerConnectionHandlerTest : public ::testing::Test {
@@ -377,6 +373,26 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
MediaStreamRequestResult result,
const blink::WebString& result_name) {}
+ // Wait for all current posts to the webrtc signaling thread to run and then
+ // run the message loop until idle on the main thread.
+ void RunMessageLoopsUntilIdle() {
+ base::WaitableEvent waitable_event(
+ base::WaitableEvent::ResetPolicy::MANUAL,
+ base::WaitableEvent::InitialState::NOT_SIGNALED);
+ mock_dependency_factory_->GetWebRtcSignalingThread()->PostTask(
+ FROM_HERE,
+ base::Bind(&RTCPeerConnectionHandlerTest::SignalWaitableEvent,
+ base::Unretained(this), &waitable_event));
+ waitable_event.Wait();
+ base::RunLoop().RunUntilIdle();
+ }
+
+ private:
+ void SignalWaitableEvent(base::WaitableEvent* waitable_event) {
+ waitable_event->Signal();
+ }
+
+ public:
base::MessageLoop message_loop_;
std::unique_ptr<ChildProcess> child_process_;
std::unique_ptr<MockWebRTCPeerConnectionHandlerClient> mock_client_;
@@ -433,7 +449,7 @@ TEST_F(RTCPeerConnectionHandlerTest, NoCallbacksToClientAfterStop) {
new rtc::RefCountedObject<MockDataChannel>("dummy", &config));
pc_handler_->observer()->OnDataChannel(remote_data_channel);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
}
TEST_F(RTCPeerConnectionHandlerTest, DestructAllHandlers) {
@@ -480,7 +496,7 @@ TEST_F(RTCPeerConnectionHandlerTest, setLocalDescription) {
EXPECT_CALL(*mock_peer_connection_, SetLocalDescription(_, _));
pc_handler_->SetLocalDescription(request, description);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(description.GetType(), pc_handler_->LocalDescription().GetType());
EXPECT_EQ(description.Sdp(), pc_handler_->LocalDescription().Sdp());
@@ -516,7 +532,7 @@ TEST_F(RTCPeerConnectionHandlerTest, setLocalDescriptionParseError) {
// Used to simulate a parse failure.
mock_dependency_factory_->SetFailToCreateSessionDescription(true);
pc_handler_->SetLocalDescription(request, description);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
// A description that failed to be applied shouldn't be stored.
EXPECT_TRUE(pc_handler_->LocalDescription().Sdp().IsEmpty());
}
@@ -536,7 +552,7 @@ TEST_F(RTCPeerConnectionHandlerTest, setRemoteDescription) {
EXPECT_CALL(*mock_peer_connection_, SetRemoteDescription(_, _));
pc_handler_->SetRemoteDescription(request, description);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(description.GetType(), pc_handler_->RemoteDescription().GetType());
EXPECT_EQ(description.Sdp(), pc_handler_->RemoteDescription().Sdp());
@@ -572,7 +588,7 @@ TEST_F(RTCPeerConnectionHandlerTest, setRemoteDescriptionParseError) {
// Used to simulate a parse failure.
mock_dependency_factory_->SetFailToCreateSessionDescription(true);
pc_handler_->SetRemoteDescription(request, description);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
// A description that failed to be applied shouldn't be stored.
EXPECT_TRUE(pc_handler_->RemoteDescription().Sdp().IsEmpty());
}
@@ -681,7 +697,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsNoSelector) {
scoped_refptr<MockRTCStatsRequest> request(
new rtc::RefCountedObject<MockRTCStatsRequest>());
pc_handler_->getStats(request.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
ASSERT_TRUE(request->result());
EXPECT_LT(1, request->result()->report_count());
}
@@ -690,9 +706,9 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsAfterClose) {
scoped_refptr<MockRTCStatsRequest> request(
new rtc::RefCountedObject<MockRTCStatsRequest>());
pc_handler_->Stop();
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
pc_handler_->getStats(request.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
ASSERT_TRUE(request->result());
EXPECT_LT(1, request->result()->report_count());
}
@@ -710,7 +726,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithLocalSelector) {
new rtc::RefCountedObject<MockRTCStatsRequest>());
request->setSelector(tracks[0]);
pc_handler_->getStats(request.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(1, request->result()->report_count());
StopAllTracks(local_stream);
@@ -720,7 +736,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithRemoteSelector) {
rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
AddRemoteMockMediaStream("remote_stream", "video", "audio"));
pc_handler_->observer()->OnAddStream(stream);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
const blink::WebMediaStream& remote_stream = mock_client_->remote_stream();
blink::WebVector<blink::WebMediaStreamTrack> tracks;
@@ -731,7 +747,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithRemoteSelector) {
new rtc::RefCountedObject<MockRTCStatsRequest>());
request->setSelector(tracks[0]);
pc_handler_->getStats(request.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(1, request->result()->report_count());
}
@@ -751,7 +767,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithBadSelector) {
new rtc::RefCountedObject<MockRTCStatsRequest>());
request->setSelector(component);
pc_handler_->getStats(request.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(0, request->result()->report_count());
StopAllTracks(local_stream);
@@ -789,7 +805,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetRTCStats) {
std::unique_ptr<blink::WebRTCStatsReport> result;
pc_handler_->GetStats(std::unique_ptr<blink::WebRTCStatsReportCallback>(
new MockRTCStatsReportCallback(&result)));
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_TRUE(result);
int undefined_stats_count = 0;
@@ -883,15 +899,15 @@ TEST_F(RTCPeerConnectionHandlerTest, GetReceivers) {
pc_handler_->observer()->OnAddStream(
AddRemoteMockMediaStream("stream0", "video0", "audio0"));
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
remote_streams.push_back(mock_client_->remote_stream());
pc_handler_->observer()->OnAddStream(
AddRemoteMockMediaStream("stream1", "video1", "audio1"));
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
remote_streams.push_back(mock_client_->remote_stream());
pc_handler_->observer()->OnAddStream(
AddRemoteMockMediaStream("stream2", "video2", "audio2"));
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
remote_streams.push_back(mock_client_->remote_stream());
std::set<std::string> expected_remote_track_ids;
@@ -1154,9 +1170,9 @@ TEST_F(RTCPeerConnectionHandlerTest, OnAddAndOnRemoveStream) {
blink::WebString::FromASCII(remote_stream_label))));
pc_handler_->observer()->OnAddStream(remote_stream);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
pc_handler_->observer()->OnRemoveStream(remote_stream);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
}
// This test that WebKit is notified about remote track state changes.
@@ -1171,7 +1187,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoteTrackState) {
&blink::WebMediaStream::Id,
blink::WebString::FromASCII(remote_stream_label))));
pc_handler_->observer()->OnAddStream(remote_stream);
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
const blink::WebMediaStream& webkit_stream = mock_client_->remote_stream();
blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
@@ -1186,13 +1202,13 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoteTrackState) {
static_cast<MockWebRtcAudioTrack*>(remote_stream->GetAudioTracks()[0].get())
->SetEnded();
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded,
audio_tracks[0].Source().GetReadyState());
static_cast<MockWebRtcVideoTrack*>(remote_stream->GetVideoTracks()[0].get())
->SetEnded();
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ(blink::WebMediaStreamSource::kReadyStateEnded,
video_tracks[0].Source().GetReadyState());
}
@@ -1227,7 +1243,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) {
scoped_refptr<webrtc::AudioTrackInterface> webrtc_track =
remote_stream->GetAudioTracks()[0].get();
remote_stream->RemoveTrack(webrtc_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
{
blink::WebVector<blink::WebMediaStreamTrack> modified_audio_tracks1;
@@ -1239,7 +1255,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) {
// Add the WebRtc audio track again.
remote_stream->AddTrack(webrtc_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
blink::WebVector<blink::WebMediaStreamTrack> modified_audio_tracks2;
webkit_stream.AudioTracks(modified_audio_tracks2);
EXPECT_EQ(1u, modified_audio_tracks2.size());
@@ -1275,7 +1291,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) {
scoped_refptr<webrtc::VideoTrackInterface> webrtc_track =
remote_stream->GetVideoTracks()[0].get();
remote_stream->RemoveTrack(webrtc_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
{
blink::WebVector<blink::WebMediaStreamTrack> modified_video_tracks1;
webkit_stream.VideoTracks(modified_video_tracks1);
@@ -1286,7 +1302,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) {
// Add the WebRtc video track again.
remote_stream->AddTrack(webrtc_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
blink::WebVector<blink::WebMediaStreamTrack> modified_video_tracks2;
webkit_stream.VideoTracks(modified_video_tracks2);
EXPECT_EQ(1u, modified_video_tracks2.size());
@@ -1326,7 +1342,7 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddTracksFromRemoteStream) {
EXPECT_TRUE(remote_stream->RemoveTrack(audio_track.get()));
auto video_track = remote_stream->GetVideoTracks()[0];
EXPECT_TRUE(remote_stream->RemoveTrack(video_track.get()));
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
{
blink::WebVector<blink::WebMediaStreamTrack> modified_audio_tracks;
@@ -1341,9 +1357,9 @@ TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddTracksFromRemoteStream) {
// Add the tracks again.
remote_stream->AddTrack(audio_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
remote_stream->AddTrack(video_track.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
blink::WebHeap::CollectGarbageForTesting();
@@ -1365,7 +1381,7 @@ TEST_F(RTCPeerConnectionHandlerTest, OnIceCandidate) {
std::unique_ptr<webrtc::IceCandidateInterface> native_candidate(
mock_dependency_factory_->CreateIceCandidate("sdpMid", 1, kDummySdp));
pc_handler_->observer()->OnIceCandidate(native_candidate.get());
- base::RunLoop().RunUntilIdle();
+ RunMessageLoopsUntilIdle();
EXPECT_EQ("sdpMid", mock_client_->candidate_mid());
EXPECT_EQ(1, mock_client_->candidate_mlineindex());
EXPECT_EQ(kDummySdp, mock_client_->candidate_sdp());
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698