henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #import <Foundation/Foundation.h> |
| 29 | |
| 30 | #import "RTCICEServer.h" |
| 31 | #import "RTCMediaConstraints.h" |
| 32 | #import "RTCMediaStream.h" |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 33 | #import "RTCPair.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #import "RTCPeerConnection.h" |
| 35 | #import "RTCPeerConnectionFactory.h" |
| 36 | #import "RTCPeerConnectionSyncObserver.h" |
| 37 | #import "RTCSessionDescription.h" |
| 38 | #import "RTCSessionDescriptionSyncObserver.h" |
| 39 | #import "RTCVideoRenderer.h" |
| 40 | #import "RTCVideoTrack.h" |
| 41 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 42 | #include "webrtc/base/gunit.h" |
| 43 | #include "webrtc/base/ssladapter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
| 45 | #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 46 | #error "This file requires ARC support." |
| 47 | #endif |
| 48 | |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 49 | @interface RTCFakeRenderer : NSObject <RTCVideoRenderer> |
| 50 | @end |
| 51 | |
| 52 | @implementation RTCFakeRenderer |
| 53 | |
| 54 | - (void)setSize:(CGSize)size {} |
| 55 | - (void)renderFrame:(RTCI420Frame*)frame {} |
| 56 | |
| 57 | @end |
| 58 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | @interface RTCPeerConnectionTest : NSObject |
| 60 | |
| 61 | // Returns whether the two sessions are of the same type. |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 62 | + (BOOL)isSession:(RTCSessionDescription*)session1 |
| 63 | ofSameTypeAsSession:(RTCSessionDescription*)session2; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | |
| 65 | // Create and add tracks to pc, with the given source, label, and IDs |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 66 | - (RTCMediaStream*)addTracksToPeerConnection:(RTCPeerConnection*)pc |
| 67 | withFactory:(RTCPeerConnectionFactory*)factory |
| 68 | videoSource:(RTCVideoSource*)videoSource |
| 69 | streamLabel:(NSString*)streamLabel |
| 70 | videoTrackID:(NSString*)videoTrackID |
| 71 | audioTrackID:(NSString*)audioTrackID; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 73 | - (void)testCompleteSessionWithFactory:(RTCPeerConnectionFactory*)factory; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
| 75 | @end |
| 76 | |
| 77 | @implementation RTCPeerConnectionTest |
| 78 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 79 | + (BOOL)isSession:(RTCSessionDescription*)session1 |
| 80 | ofSameTypeAsSession:(RTCSessionDescription*)session2 { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | return [session1.type isEqual:session2.type]; |
| 82 | } |
| 83 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 84 | - (RTCMediaStream*)addTracksToPeerConnection:(RTCPeerConnection*)pc |
| 85 | withFactory:(RTCPeerConnectionFactory*)factory |
| 86 | videoSource:(RTCVideoSource*)videoSource |
| 87 | streamLabel:(NSString*)streamLabel |
| 88 | videoTrackID:(NSString*)videoTrackID |
| 89 | audioTrackID:(NSString*)audioTrackID { |
| 90 | RTCMediaStream* localMediaStream = [factory mediaStreamWithLabel:streamLabel]; |
| 91 | RTCVideoTrack* videoTrack = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | [factory videoTrackWithID:videoTrackID source:videoSource]; |
tkchin@webrtc.org | 8125744 | 2014-11-04 23:06:15 +0000 | [diff] [blame] | 93 | RTCFakeRenderer* videoRenderer = [[RTCFakeRenderer alloc] init]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | [videoTrack addRenderer:videoRenderer]; |
| 95 | [localMediaStream addVideoTrack:videoTrack]; |
| 96 | // Test that removal/re-add works. |
| 97 | [localMediaStream removeVideoTrack:videoTrack]; |
| 98 | [localMediaStream addVideoTrack:videoTrack]; |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 99 | RTCAudioTrack* audioTrack = [factory audioTrackWithID:audioTrackID]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | [localMediaStream addAudioTrack:audioTrack]; |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 101 | [pc addStream:localMediaStream]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | return localMediaStream; |
| 103 | } |
| 104 | |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 105 | - (void)testCompleteSessionWithFactory:(RTCPeerConnectionFactory*)factory { |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 106 | NSArray* mandatory = @[ |
| 107 | [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"], |
| 108 | [[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"], |
| 109 | ]; |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 110 | RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] init]; |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 111 | RTCMediaConstraints* pcConstraints = |
| 112 | [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatory |
| 113 | optionalConstraints:nil]; |
| 114 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 115 | RTCPeerConnectionSyncObserver* offeringExpectations = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | [[RTCPeerConnectionSyncObserver alloc] init]; |
fischman@webrtc.org | 13320ea | 2014-03-07 22:15:30 +0000 | [diff] [blame] | 117 | RTCPeerConnection* pcOffer = |
| 118 | [factory peerConnectionWithICEServers:nil |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 119 | constraints:pcConstraints |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | delegate:offeringExpectations]; |
| 121 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 122 | RTCPeerConnectionSyncObserver* answeringExpectations = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | [[RTCPeerConnectionSyncObserver alloc] init]; |
fischman@webrtc.org | 13320ea | 2014-03-07 22:15:30 +0000 | [diff] [blame] | 124 | |
| 125 | RTCPeerConnection* pcAnswer = |
| 126 | [factory peerConnectionWithICEServers:nil |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 127 | constraints:pcConstraints |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | delegate:answeringExpectations]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | // TODO(hughv): Create video capturer |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 130 | RTCVideoCapturer* capturer = nil; |
| 131 | RTCVideoSource* videoSource = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | [factory videoSourceWithCapturer:capturer constraints:constraints]; |
| 133 | |
| 134 | // Here and below, "oLMS" refers to offerer's local media stream, and "aLMS" |
| 135 | // refers to the answerer's local media stream, with suffixes of "a0" and "v0" |
| 136 | // for audio and video tracks, resp. These mirror chrome historical naming. |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 137 | RTCMediaStream* oLMSUnused = [self addTracksToPeerConnection:pcOffer |
| 138 | withFactory:factory |
| 139 | videoSource:videoSource |
| 140 | streamLabel:@"oLMS" |
| 141 | videoTrackID:@"oLMSv0" |
| 142 | audioTrackID:@"oLMSa0"]; |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 143 | |
| 144 | RTCDataChannel* offerDC = |
| 145 | [pcOffer createDataChannelWithLabel:@"offerDC" |
| 146 | config:[[RTCDataChannelInit alloc] init]]; |
| 147 | EXPECT_TRUE([offerDC.label isEqual:@"offerDC"]); |
| 148 | offerDC.delegate = offeringExpectations; |
| 149 | offeringExpectations.dataChannel = offerDC; |
| 150 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 151 | RTCSessionDescriptionSyncObserver* sdpObserver = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | [[RTCSessionDescriptionSyncObserver alloc] init]; |
| 153 | [pcOffer createOfferWithDelegate:sdpObserver constraints:constraints]; |
| 154 | [sdpObserver wait]; |
| 155 | EXPECT_TRUE(sdpObserver.success); |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 156 | RTCSessionDescription* offerSDP = sdpObserver.sessionDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 157 | EXPECT_EQ([@"offer" compare:offerSDP.type options:NSCaseInsensitiveSearch], |
| 158 | NSOrderedSame); |
| 159 | EXPECT_GT([offerSDP.description length], 0); |
| 160 | |
| 161 | sdpObserver = [[RTCSessionDescriptionSyncObserver alloc] init]; |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 162 | [answeringExpectations expectSignalingChange:RTCSignalingHaveRemoteOffer]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | [answeringExpectations expectAddStream:@"oLMS"]; |
| 164 | [pcAnswer setRemoteDescriptionWithDelegate:sdpObserver |
| 165 | sessionDescription:offerSDP]; |
| 166 | [sdpObserver wait]; |
| 167 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 168 | RTCMediaStream* aLMSUnused = [self addTracksToPeerConnection:pcAnswer |
| 169 | withFactory:factory |
| 170 | videoSource:videoSource |
| 171 | streamLabel:@"aLMS" |
| 172 | videoTrackID:@"aLMSv0" |
| 173 | audioTrackID:@"aLMSa0"]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | |
| 175 | sdpObserver = [[RTCSessionDescriptionSyncObserver alloc] init]; |
| 176 | [pcAnswer createAnswerWithDelegate:sdpObserver constraints:constraints]; |
| 177 | [sdpObserver wait]; |
| 178 | EXPECT_TRUE(sdpObserver.success); |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 179 | RTCSessionDescription* answerSDP = sdpObserver.sessionDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | EXPECT_EQ([@"answer" compare:answerSDP.type options:NSCaseInsensitiveSearch], |
| 181 | NSOrderedSame); |
| 182 | EXPECT_GT([answerSDP.description length], 0); |
| 183 | |
| 184 | [offeringExpectations expectICECandidates:2]; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 185 | // It's possible to only have 1 ICE candidate for the answerer, since we use |
| 186 | // BUNDLE and rtcp-mux by default, and don't provide any ICE servers in this |
| 187 | // test. |
| 188 | [answeringExpectations expectICECandidates:1]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 189 | |
| 190 | sdpObserver = [[RTCSessionDescriptionSyncObserver alloc] init]; |
| 191 | [answeringExpectations expectSignalingChange:RTCSignalingStable]; |
| 192 | [pcAnswer setLocalDescriptionWithDelegate:sdpObserver |
| 193 | sessionDescription:answerSDP]; |
| 194 | [sdpObserver wait]; |
| 195 | EXPECT_TRUE(sdpObserver.sessionDescription == NULL); |
| 196 | |
| 197 | sdpObserver = [[RTCSessionDescriptionSyncObserver alloc] init]; |
| 198 | [offeringExpectations expectSignalingChange:RTCSignalingHaveLocalOffer]; |
| 199 | [pcOffer setLocalDescriptionWithDelegate:sdpObserver |
| 200 | sessionDescription:offerSDP]; |
| 201 | [sdpObserver wait]; |
| 202 | EXPECT_TRUE(sdpObserver.sessionDescription == NULL); |
| 203 | |
| 204 | [offeringExpectations expectICEConnectionChange:RTCICEConnectionChecking]; |
| 205 | [offeringExpectations expectICEConnectionChange:RTCICEConnectionConnected]; |
fischman@webrtc.org | a01daf0 | 2014-03-08 03:17:55 +0000 | [diff] [blame] | 206 | // TODO(fischman): figure out why this is flaky and re-introduce (and remove |
| 207 | // special-casing from the observer!). |
| 208 | // [offeringExpectations expectICEConnectionChange:RTCICEConnectionCompleted]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | [answeringExpectations expectICEConnectionChange:RTCICEConnectionChecking]; |
| 210 | [answeringExpectations expectICEConnectionChange:RTCICEConnectionConnected]; |
| 211 | |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 212 | [offeringExpectations expectStateChange:kRTCDataChannelStateOpen]; |
| 213 | [answeringExpectations expectDataChannel:@"offerDC"]; |
| 214 | [answeringExpectations expectStateChange:kRTCDataChannelStateOpen]; |
| 215 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 216 | [offeringExpectations expectICEGatheringChange:RTCICEGatheringComplete]; |
| 217 | [answeringExpectations expectICEGatheringChange:RTCICEGatheringComplete]; |
| 218 | |
| 219 | sdpObserver = [[RTCSessionDescriptionSyncObserver alloc] init]; |
| 220 | [offeringExpectations expectSignalingChange:RTCSignalingStable]; |
| 221 | [offeringExpectations expectAddStream:@"aLMS"]; |
| 222 | [pcOffer setRemoteDescriptionWithDelegate:sdpObserver |
| 223 | sessionDescription:answerSDP]; |
| 224 | [sdpObserver wait]; |
| 225 | EXPECT_TRUE(sdpObserver.sessionDescription == NULL); |
| 226 | |
| 227 | EXPECT_TRUE([offerSDP.type isEqual:pcOffer.localDescription.type]); |
| 228 | EXPECT_TRUE([answerSDP.type isEqual:pcOffer.remoteDescription.type]); |
| 229 | EXPECT_TRUE([offerSDP.type isEqual:pcAnswer.remoteDescription.type]); |
| 230 | EXPECT_TRUE([answerSDP.type isEqual:pcAnswer.localDescription.type]); |
| 231 | |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 232 | for (RTCICECandidate* candidate in offeringExpectations |
| 233 | .releaseReceivedICECandidates) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | [pcAnswer addICECandidate:candidate]; |
| 235 | } |
fischman@webrtc.org | 7fa1fcb | 2014-03-25 00:11:56 +0000 | [diff] [blame] | 236 | for (RTCICECandidate* candidate in answeringExpectations |
| 237 | .releaseReceivedICECandidates) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | [pcOffer addICECandidate:candidate]; |
| 239 | } |
| 240 | |
| 241 | [offeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 242 | [answeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 243 | |
tkchin@webrtc.org | ff27332 | 2014-04-30 18:32:33 +0000 | [diff] [blame] | 244 | EXPECT_EQ(pcOffer.signalingState, RTCSignalingStable); |
| 245 | EXPECT_EQ(pcAnswer.signalingState, RTCSignalingStable); |
| 246 | |
| 247 | // Test send and receive UTF-8 text |
| 248 | NSString* text = @"你好"; |
| 249 | NSData* textData = [text dataUsingEncoding:NSUTF8StringEncoding]; |
| 250 | RTCDataBuffer* buffer = |
| 251 | [[RTCDataBuffer alloc] initWithData:textData isBinary:NO]; |
| 252 | [answeringExpectations expectMessage:[textData copy] isBinary:NO]; |
| 253 | EXPECT_TRUE([offeringExpectations.dataChannel sendData:buffer]); |
| 254 | [answeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 255 | |
| 256 | // Test send and receive binary data |
| 257 | const size_t byteLength = 5; |
| 258 | char bytes[byteLength] = {1, 2, 3, 4, 5}; |
| 259 | NSData* byteData = [NSData dataWithBytes:bytes length:byteLength]; |
| 260 | buffer = [[RTCDataBuffer alloc] initWithData:byteData isBinary:YES]; |
| 261 | [answeringExpectations expectMessage:[byteData copy] isBinary:YES]; |
| 262 | EXPECT_TRUE([offeringExpectations.dataChannel sendData:buffer]); |
| 263 | [answeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 264 | |
| 265 | [offeringExpectations expectStateChange:kRTCDataChannelStateClosing]; |
| 266 | [answeringExpectations expectStateChange:kRTCDataChannelStateClosing]; |
| 267 | [offeringExpectations expectStateChange:kRTCDataChannelStateClosed]; |
| 268 | [answeringExpectations expectStateChange:kRTCDataChannelStateClosed]; |
| 269 | |
| 270 | [answeringExpectations.dataChannel close]; |
| 271 | [offeringExpectations.dataChannel close]; |
| 272 | |
| 273 | [offeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 274 | [answeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 275 | // Don't need to listen to further state changes. |
| 276 | // TODO(tkchin): figure out why Closed->Closing without this. |
| 277 | offeringExpectations.dataChannel.delegate = nil; |
| 278 | answeringExpectations.dataChannel.delegate = nil; |
| 279 | |
fischman@webrtc.org | 13320ea | 2014-03-07 22:15:30 +0000 | [diff] [blame] | 280 | // Let the audio feedback run for 2s to allow human testing and to ensure |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | // things stabilize. TODO(fischman): replace seconds with # of video frames, |
| 282 | // when we have video flowing. |
| 283 | [[NSRunLoop currentRunLoop] |
fischman@webrtc.org | 13320ea | 2014-03-07 22:15:30 +0000 | [diff] [blame] | 284 | runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 286 | [offeringExpectations expectICEConnectionChange:RTCICEConnectionClosed]; |
| 287 | [answeringExpectations expectICEConnectionChange:RTCICEConnectionClosed]; |
| 288 | [offeringExpectations expectSignalingChange:RTCSignalingClosed]; |
| 289 | [answeringExpectations expectSignalingChange:RTCSignalingClosed]; |
| 290 | |
| 291 | [pcOffer close]; |
| 292 | [pcAnswer close]; |
| 293 | |
| 294 | [offeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 295 | [answeringExpectations waitForAllExpectationsToBeSatisfied]; |
| 296 | |
| 297 | capturer = nil; |
| 298 | videoSource = nil; |
| 299 | pcOffer = nil; |
| 300 | pcAnswer = nil; |
| 301 | // TODO(fischman): be stricter about shutdown checks; ensure thread |
| 302 | // counts return to where they were before the test kicked off, and |
| 303 | // that all objects have in fact shut down. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @end |
| 307 | |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 308 | // TODO(fischman): move {Initialize,Cleanup}SSL into alloc/dealloc of |
| 309 | // RTCPeerConnectionTest and avoid the appearance of RTCPeerConnectionTest being |
| 310 | // a TestBase since it's not. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | TEST(RTCPeerConnectionTest, SessionTest) { |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 312 | @autoreleasepool { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 313 | rtc::InitializeSSL(); |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 314 | // Since |factory| will own the signaling & worker threads, it's important |
| 315 | // that it outlive the created PeerConnections since they self-delete on the |
| 316 | // signaling thread, and if |factory| is freed first then a last refcount on |
| 317 | // the factory will expire during this teardown, causing the signaling |
| 318 | // thread to try to Join() with itself. This is a hack to ensure that the |
| 319 | // factory outlives RTCPeerConnection:dealloc. |
| 320 | // See https://code.google.com/p/webrtc/issues/detail?id=3100. |
| 321 | RTCPeerConnectionFactory* factory = [[RTCPeerConnectionFactory alloc] init]; |
| 322 | @autoreleasepool { |
| 323 | RTCPeerConnectionTest* pcTest = [[RTCPeerConnectionTest alloc] init]; |
| 324 | [pcTest testCompleteSessionWithFactory:factory]; |
| 325 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 326 | rtc::CleanupSSL(); |
fischman@webrtc.org | 385a722 | 2014-03-25 05:16:29 +0000 | [diff] [blame] | 327 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | } |