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

Side by Side Diff: content/renderer/media/rtc_peer_connection_handler_unittest.cc

Issue 2644853002: Use explicit WebString conversion methods in content/renderer/media (unittests) (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/rtc_peer_connection_handler.h" 5 #include "content/renderer/media/rtc_peer_connection_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 CHECK(audio_source->ConnectToTrack(audio_tracks[0])); 328 CHECK(audio_source->ConnectToTrack(audio_tracks[0]));
329 blink::WebVector<blink::WebMediaStreamTrack> video_tracks( 329 blink::WebVector<blink::WebMediaStreamTrack> video_tracks(
330 static_cast<size_t>(1)); 330 static_cast<size_t>(1));
331 blink::WebMediaConstraints video_constraints; 331 blink::WebMediaConstraints video_constraints;
332 video_constraints.initialize(); 332 video_constraints.initialize();
333 video_tracks[0] = MediaStreamVideoTrack::CreateVideoTrack( 333 video_tracks[0] = MediaStreamVideoTrack::CreateVideoTrack(
334 native_video_source, video_constraints, 334 native_video_source, video_constraints,
335 MediaStreamVideoSource::ConstraintsCallback(), true); 335 MediaStreamVideoSource::ConstraintsCallback(), true);
336 336
337 blink::WebMediaStream local_stream; 337 blink::WebMediaStream local_stream;
338 local_stream.initialize(base::UTF8ToUTF16(stream_label), audio_tracks, 338 local_stream.initialize(blink::WebString::fromUTF8(stream_label),
jrummell 2017/01/19 20:17:03 Most of the conversions of UTF8ToUTF16() became fr
kinuko 2017/01/20 02:22:35 I wasn't sure if this method always takes ascii st
339 video_tracks); 339 audio_tracks, video_tracks);
340 local_stream.setExtraData(new MediaStream()); 340 local_stream.setExtraData(new MediaStream());
341 return local_stream; 341 return local_stream;
342 } 342 }
343 343
344 // Creates a remote MediaStream and adds it to the mocked native 344 // Creates a remote MediaStream and adds it to the mocked native
345 // peer connection. 345 // peer connection.
346 rtc::scoped_refptr<webrtc::MediaStreamInterface> AddRemoteMockMediaStream( 346 rtc::scoped_refptr<webrtc::MediaStreamInterface> AddRemoteMockMediaStream(
347 const std::string& stream_label, 347 const std::string& stream_label,
348 const std::string& video_track_label, 348 const std::string& video_track_label,
349 const std::string& audio_track_label) { 349 const std::string& audio_track_label) {
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 EXPECT_EQ(-1, mock_client_->candidate_mlineindex()); 1003 EXPECT_EQ(-1, mock_client_->candidate_mlineindex());
1004 EXPECT_EQ("", mock_client_->candidate_sdp()); 1004 EXPECT_EQ("", mock_client_->candidate_sdp());
1005 } 1005 }
1006 1006
1007 TEST_F(RTCPeerConnectionHandlerTest, OnAddAndOnRemoveStream) { 1007 TEST_F(RTCPeerConnectionHandlerTest, OnAddAndOnRemoveStream) {
1008 std::string remote_stream_label("remote_stream"); 1008 std::string remote_stream_label("remote_stream");
1009 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( 1009 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream(
1010 AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); 1010 AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
1011 1011
1012 testing::InSequence sequence; 1012 testing::InSequence sequence;
1013 EXPECT_CALL(*mock_tracker_.get(), TrackAddStream( 1013 EXPECT_CALL(
1014 pc_handler_.get(), 1014 *mock_tracker_.get(),
1015 testing::Property(&blink::WebMediaStream::id, 1015 TrackAddStream(
1016 base::UTF8ToUTF16(remote_stream_label)), 1016 pc_handler_.get(),
1017 PeerConnectionTracker::SOURCE_REMOTE)); 1017 testing::Property(&blink::WebMediaStream::id,
1018 EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( 1018 blink::WebString::fromASCII(remote_stream_label)),
1019 testing::Property(&blink::WebMediaStream::id, 1019 PeerConnectionTracker::SOURCE_REMOTE));
1020 base::UTF8ToUTF16(remote_stream_label)))); 1020 EXPECT_CALL(*mock_client_.get(),
1021 didAddRemoteStream(testing::Property(
1022 &blink::WebMediaStream::id,
1023 blink::WebString::fromASCII(remote_stream_label))));
1021 1024
1022 EXPECT_CALL(*mock_tracker_.get(), TrackRemoveStream( 1025 EXPECT_CALL(
1023 pc_handler_.get(), 1026 *mock_tracker_.get(),
1024 testing::Property(&blink::WebMediaStream::id, 1027 TrackRemoveStream(
1025 base::UTF8ToUTF16(remote_stream_label)), 1028 pc_handler_.get(),
1026 PeerConnectionTracker::SOURCE_REMOTE)); 1029 testing::Property(&blink::WebMediaStream::id,
1027 EXPECT_CALL(*mock_client_.get(), didRemoveRemoteStream( 1030 blink::WebString::fromASCII(remote_stream_label)),
1028 testing::Property(&blink::WebMediaStream::id, 1031 PeerConnectionTracker::SOURCE_REMOTE));
1029 base::UTF8ToUTF16(remote_stream_label)))); 1032 EXPECT_CALL(*mock_client_.get(),
1033 didRemoveRemoteStream(testing::Property(
1034 &blink::WebMediaStream::id,
1035 blink::WebString::fromASCII(remote_stream_label))));
1030 1036
1031 pc_handler_->observer()->OnAddStream(remote_stream); 1037 pc_handler_->observer()->OnAddStream(remote_stream);
1032 base::RunLoop().RunUntilIdle(); 1038 base::RunLoop().RunUntilIdle();
1033 pc_handler_->observer()->OnRemoveStream(remote_stream); 1039 pc_handler_->observer()->OnRemoveStream(remote_stream);
1034 base::RunLoop().RunUntilIdle(); 1040 base::RunLoop().RunUntilIdle();
1035 } 1041 }
1036 1042
1037 // This test that WebKit is notified about remote track state changes. 1043 // This test that WebKit is notified about remote track state changes.
1038 TEST_F(RTCPeerConnectionHandlerTest, RemoteTrackState) { 1044 TEST_F(RTCPeerConnectionHandlerTest, RemoteTrackState) {
1039 std::string remote_stream_label("remote_stream"); 1045 std::string remote_stream_label("remote_stream");
1040 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( 1046 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream(
1041 AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); 1047 AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
1042 1048
1043 testing::InSequence sequence; 1049 testing::InSequence sequence;
1044 EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( 1050 EXPECT_CALL(*mock_client_.get(),
1045 testing::Property(&blink::WebMediaStream::id, 1051 didAddRemoteStream(testing::Property(
1046 base::UTF8ToUTF16(remote_stream_label)))); 1052 &blink::WebMediaStream::id,
1053 blink::WebString::fromASCII(remote_stream_label))));
1047 pc_handler_->observer()->OnAddStream(remote_stream); 1054 pc_handler_->observer()->OnAddStream(remote_stream);
1048 base::RunLoop().RunUntilIdle(); 1055 base::RunLoop().RunUntilIdle();
1049 const blink::WebMediaStream& webkit_stream = mock_client_->remote_stream(); 1056 const blink::WebMediaStream& webkit_stream = mock_client_->remote_stream();
1050 1057
1051 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; 1058 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
1052 webkit_stream.audioTracks(audio_tracks); 1059 webkit_stream.audioTracks(audio_tracks);
1053 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive, 1060 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive,
1054 audio_tracks[0].source().getReadyState()); 1061 audio_tracks[0].source().getReadyState());
1055 1062
1056 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 1063 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
(...skipping 13 matching lines...) Expand all
1070 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, 1077 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded,
1071 video_tracks[0].source().getReadyState()); 1078 video_tracks[0].source().getReadyState());
1072 } 1079 }
1073 1080
1074 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) { 1081 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddAudioTrackFromRemoteStream) {
1075 std::string remote_stream_label("remote_stream"); 1082 std::string remote_stream_label("remote_stream");
1076 base::RunLoop run_loop; 1083 base::RunLoop run_loop;
1077 1084
1078 // Grab the added media stream when it's been successfully added to the PC. 1085 // Grab the added media stream when it's been successfully added to the PC.
1079 blink::WebMediaStream webkit_stream; 1086 blink::WebMediaStream webkit_stream;
1080 EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( 1087 EXPECT_CALL(*mock_client_.get(),
1081 testing::Property(&blink::WebMediaStream::id, 1088 didAddRemoteStream(testing::Property(
1082 base::UTF8ToUTF16(remote_stream_label)))) 1089 &blink::WebMediaStream::id,
1083 .WillOnce( 1090 blink::WebString::fromASCII(remote_stream_label))))
1084 DoAll(SaveArg<0>(&webkit_stream), 1091 .WillOnce(DoAll(SaveArg<0>(&webkit_stream),
1085 ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); 1092 ExitMessageLoop(&message_loop_, run_loop.QuitClosure())));
1086 1093
1087 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( 1094 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream(
1088 AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); 1095 AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
1089 pc_handler_->observer()->OnAddStream(remote_stream); 1096 pc_handler_->observer()->OnAddStream(remote_stream);
1090 run_loop.Run(); 1097 run_loop.Run();
1091 1098
1092 { 1099 {
1093 // Test in a small scope so that |audio_tracks| don't hold on to destroyed 1100 // Test in a small scope so that |audio_tracks| don't hold on to destroyed
1094 // source later. 1101 // source later.
1095 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; 1102 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
(...skipping 22 matching lines...) Expand all
1118 webkit_stream.audioTracks(modified_audio_tracks2); 1125 webkit_stream.audioTracks(modified_audio_tracks2);
1119 EXPECT_EQ(1u, modified_audio_tracks2.size()); 1126 EXPECT_EQ(1u, modified_audio_tracks2.size());
1120 } 1127 }
1121 1128
1122 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) { 1129 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddVideoTrackFromRemoteStream) {
1123 std::string remote_stream_label("remote_stream"); 1130 std::string remote_stream_label("remote_stream");
1124 base::RunLoop run_loop; 1131 base::RunLoop run_loop;
1125 1132
1126 // Grab the added media stream when it's been successfully added to the PC. 1133 // Grab the added media stream when it's been successfully added to the PC.
1127 blink::WebMediaStream webkit_stream; 1134 blink::WebMediaStream webkit_stream;
1128 EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( 1135 EXPECT_CALL(*mock_client_.get(),
1129 testing::Property(&blink::WebMediaStream::id, 1136 didAddRemoteStream(testing::Property(
1130 base::UTF8ToUTF16(remote_stream_label)))) 1137 &blink::WebMediaStream::id,
1131 .WillOnce( 1138 blink::WebString::fromASCII(remote_stream_label))))
1132 DoAll(SaveArg<0>(&webkit_stream), 1139 .WillOnce(DoAll(SaveArg<0>(&webkit_stream),
1133 ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); 1140 ExitMessageLoop(&message_loop_, run_loop.QuitClosure())));
1134 1141
1135 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( 1142 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream(
1136 AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); 1143 AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
1137 pc_handler_->observer()->OnAddStream(remote_stream); 1144 pc_handler_->observer()->OnAddStream(remote_stream);
1138 run_loop.Run(); 1145 run_loop.Run();
1139 1146
1140 { 1147 {
1141 // Test in a small scope so that |video_tracks| don't hold on to destroyed 1148 // Test in a small scope so that |video_tracks| don't hold on to destroyed
1142 // source later. 1149 // source later.
1143 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 1150 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
(...skipping 21 matching lines...) Expand all
1165 webkit_stream.videoTracks(modified_video_tracks2); 1172 webkit_stream.videoTracks(modified_video_tracks2);
1166 EXPECT_EQ(1u, modified_video_tracks2.size()); 1173 EXPECT_EQ(1u, modified_video_tracks2.size());
1167 } 1174 }
1168 1175
1169 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddTracksFromRemoteStream) { 1176 TEST_F(RTCPeerConnectionHandlerTest, RemoveAndAddTracksFromRemoteStream) {
1170 std::string remote_stream_label("remote_stream"); 1177 std::string remote_stream_label("remote_stream");
1171 base::RunLoop run_loop; 1178 base::RunLoop run_loop;
1172 1179
1173 // Grab the added media stream when it's been successfully added to the PC. 1180 // Grab the added media stream when it's been successfully added to the PC.
1174 blink::WebMediaStream webkit_stream; 1181 blink::WebMediaStream webkit_stream;
1175 EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( 1182 EXPECT_CALL(*mock_client_.get(),
1176 testing::Property(&blink::WebMediaStream::id, 1183 didAddRemoteStream(testing::Property(
1177 base::UTF8ToUTF16(remote_stream_label)))) 1184 &blink::WebMediaStream::id,
1178 .WillOnce( 1185 blink::WebString::fromASCII(remote_stream_label))))
1179 DoAll(SaveArg<0>(&webkit_stream), 1186 .WillOnce(DoAll(SaveArg<0>(&webkit_stream),
1180 ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); 1187 ExitMessageLoop(&message_loop_, run_loop.QuitClosure())));
1181 1188
1182 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( 1189 rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream(
1183 AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); 1190 AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
1184 pc_handler_->observer()->OnAddStream(remote_stream); 1191 pc_handler_->observer()->OnAddStream(remote_stream);
1185 run_loop.Run(); 1192 run_loop.Run();
1186 1193
1187 { 1194 {
1188 // Test in a small scope so that |audio_tracks| don't hold on to destroyed 1195 // Test in a small scope so that |audio_tracks| don't hold on to destroyed
1189 // source later. 1196 // source later.
1190 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; 1197 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 testing::Ref(tracks[0]))); 1293 testing::Ref(tracks[0])));
1287 1294
1288 std::unique_ptr<blink::WebRTCDTMFSenderHandler> sender( 1295 std::unique_ptr<blink::WebRTCDTMFSenderHandler> sender(
1289 pc_handler_->createDTMFSender(tracks[0])); 1296 pc_handler_->createDTMFSender(tracks[0]));
1290 EXPECT_TRUE(sender.get()); 1297 EXPECT_TRUE(sender.get());
1291 1298
1292 StopAllTracks(local_stream); 1299 StopAllTracks(local_stream);
1293 } 1300 }
1294 1301
1295 } // namespace content 1302 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/mock_media_stream_registry.cc ('k') | content/renderer/media/video_track_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698