OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { | 75 - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { |
76 ARDTestExpectation *expectation = | 76 ARDTestExpectation *expectation = |
77 [[ARDTestExpectation alloc] initWithDescription:description]; | 77 [[ARDTestExpectation alloc] initWithDescription:description]; |
78 [_expectations addObject:expectation]; | 78 [_expectations addObject:expectation]; |
79 return expectation; | 79 return expectation; |
80 } | 80 } |
81 | 81 |
82 - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout | 82 - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout |
83 handler:(void (^)(NSError *error))handler { | 83 handler:(void (^)(NSError *error))handler { |
84 NSDate *startDate = [NSDate date]; | 84 NSDate *startDate = [NSDate date]; |
85 NSError *error = nil; | |
85 while (![self areExpectationsFulfilled]) { | 86 while (![self areExpectationsFulfilled]) { |
86 NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; | 87 NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; |
87 if (duration > timeout) { | 88 if (duration > timeout) { |
88 NSAssert(NO, @"Expectation timed out."); | 89 error = [NSError errorWithDomain:@"ARDAppClient" |
daniela-webrtc
2016/10/17 11:33:31
By removing the NSAssert here you'll break the `te
|
daniela-webrtc
2016/10/17 11:33:31
I think you can use:
error = [[NSError alloc] in
|
90 code:101 | |
91 userInfo:@{NSLocalizedDescriptionKey : @"Expectati on timed out"}]; | |
89 break; | 92 break; |
90 } | 93 } |
91 [[NSRunLoop currentRunLoop] | 94 [[NSRunLoop currentRunLoop] |
92 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | 95 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
93 } | 96 } |
94 handler(nil); | 97 handler(error); |
95 } | 98 } |
96 | 99 |
97 - (BOOL)areExpectationsFulfilled { | 100 - (BOOL)areExpectationsFulfilled { |
98 for (ARDTestExpectation *expectation in _expectations) { | 101 for (ARDTestExpectation *expectation in _expectations) { |
99 if (!expectation.isFulfilled) { | 102 if (!expectation.isFulfilled) { |
100 return NO; | 103 return NO; |
101 } | 104 } |
102 } | 105 } |
103 return YES; | 106 return YES; |
104 } | 107 } |
(...skipping 25 matching lines...) Expand all Loading... | |
130 joinResponse.messages = messages; | 133 joinResponse.messages = messages; |
131 | 134 |
132 // Successful message response. | 135 // Successful message response. |
133 ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init]; | 136 ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init]; |
134 messageResponse.result = kARDMessageResultTypeSuccess; | 137 messageResponse.result = kARDMessageResultTypeSuccess; |
135 | 138 |
136 // Return join response from above on join. | 139 // Return join response from above on join. |
137 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { | 140 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { |
138 __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, | 141 __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, |
139 NSError *error); | 142 NSError *error); |
140 [invocation getArgument:&completionHandler atIndex:3]; | 143 [invocation getArgument:&completionHandler atIndex:4]; |
141 completionHandler(joinResponse, nil); | 144 completionHandler(joinResponse, nil); |
142 }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; | 145 }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; |
143 | 146 |
144 // Return message response from above on join. | 147 // Return message response from above on join. |
145 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { | 148 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { |
146 __unsafe_unretained ARDSignalingMessage *message; | 149 __unsafe_unretained ARDSignalingMessage *message; |
147 __unsafe_unretained void (^completionHandler)(ARDMessageResponse *response, | 150 __unsafe_unretained void (^completionHandler)(ARDMessageResponse *response, |
148 NSError *error); | 151 NSError *error); |
149 [invocation getArgument:&message atIndex:2]; | 152 [invocation getArgument:&message atIndex:2]; |
150 [invocation getArgument:&completionHandler atIndex:5]; | 153 [invocation getArgument:&completionHandler atIndex:5]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 }] requestServersWithCompletionHandler:[OCMArg any]]; | 199 }] requestServersWithCompletionHandler:[OCMArg any]]; |
197 return mockTURNClient; | 200 return mockTURNClient; |
198 } | 201 } |
199 | 202 |
200 - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId | 203 - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
201 clientId:(NSString *)clientId | 204 clientId:(NSString *)clientId |
202 isInitiator:(BOOL)isInitiator | 205 isInitiator:(BOOL)isInitiator |
203 messages:(NSArray *)messages | 206 messages:(NSArray *)messages |
204 messageHandler: | 207 messageHandler: |
205 (void (^)(ARDSignalingMessage *message))messageHandler | 208 (void (^)(ARDSignalingMessage *message))messageHandler |
206 connectedHandler:(void (^)(void))connectedHandler { | 209 connectedHandler:(void (^)(NSInvocation *))connectedHa ndler { |
207 id turnClient = [self mockTURNClient]; | 210 id turnClient = [self mockTURNClient]; |
208 id signalingChannel = [self mockSignalingChannelForRoomId:roomId | 211 id signalingChannel = [self mockSignalingChannelForRoomId:roomId |
209 clientId:clientId | 212 clientId:clientId |
210 messageHandler:messageHandler]; | 213 messageHandler:messageHandler]; |
211 id roomServerClient = | 214 id roomServerClient = |
212 [self mockRoomServerClientForRoomId:roomId | 215 [self mockRoomServerClientForRoomId:roomId |
213 clientId:clientId | 216 clientId:clientId |
214 isInitiator:isInitiator | 217 isInitiator:isInitiator |
215 messages:messages | 218 messages:messages |
216 messageHandler:messageHandler]; | 219 messageHandler:messageHandler]; |
217 id delegate = | 220 id delegate = |
218 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; | 221 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
219 [[[delegate stub] andDo:^(NSInvocation *invocation) { | 222 [[[delegate stub] andDo:^(NSInvocation *invocation) { |
220 connectedHandler(); | 223 connectedHandler(invocation); |
221 }] appClient:[OCMArg any] | 224 }] appClient:[OCMArg any] |
222 didChangeConnectionState:RTCIceConnectionStateConnected]; | 225 didChangeConnectionState:RTCIceConnectionStateConnected]; |
226 [[[delegate stub] andDo:^(NSInvocation *invocation) { | |
227 connectedHandler(invocation); | |
228 }] appClient:[OCMArg any] | |
229 didReceiveLocalVideoTrack:[OCMArg any]]; | |
223 | 230 |
224 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient | 231 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
225 signalingChannel:signalingChannel | 232 signalingChannel:signalingChannel |
226 turnClient:turnClient | 233 turnClient:turnClient |
227 delegate:delegate]; | 234 delegate:delegate]; |
228 } | 235 } |
229 | 236 |
230 // Tests that an ICE connection is established between two ARDAppClient objects | 237 // Tests that an ICE connection is established between two ARDAppClient objects |
231 // where one is set up as a caller and the other the answerer. Network | 238 // where one is set up as a caller and the other the answerer. Network |
232 // components are mocked out and messages are relayed directly from object to | 239 // components are mocked out and messages are relayed directly from object to |
(...skipping 15 matching lines...) Expand all Loading... | |
248 ARDTestExpectation *answererConnectionExpectation = | 255 ARDTestExpectation *answererConnectionExpectation = |
249 [self expectationWithDescription:@"Answerer PC connected."]; | 256 [self expectationWithDescription:@"Answerer PC connected."]; |
250 | 257 |
251 caller = [self createAppClientForRoomId:roomId | 258 caller = [self createAppClientForRoomId:roomId |
252 clientId:callerId | 259 clientId:callerId |
253 isInitiator:YES | 260 isInitiator:YES |
254 messages:[NSArray array] | 261 messages:[NSArray array] |
255 messageHandler:^(ARDSignalingMessage *message) { | 262 messageHandler:^(ARDSignalingMessage *message) { |
256 ARDAppClient *strongAnswerer = weakAnswerer; | 263 ARDAppClient *strongAnswerer = weakAnswerer; |
257 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; | 264 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
258 } connectedHandler:^{ | 265 } connectedHandler:^(NSInvocation *invocation){ |
259 [callerConnectionExpectation fulfill]; | 266 if ([NSStringFromSelector([invocation selector]) |
267 isEqualToString:@"appClient:didChangeConnectionState:"]) | |
268 [callerConnectionExpectation fulfill]; | |
260 }]; | 269 }]; |
261 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 270 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
262 // crash in Debug. | 271 // crash in Debug. |
263 caller.defaultPeerConnectionConstraints = | 272 caller.defaultPeerConnectionConstraints = |
264 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil | 273 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
265 optionalConstraints:nil]; | 274 optionalConstraints:nil]; |
266 weakCaller = caller; | 275 weakCaller = caller; |
267 | 276 |
268 answerer = [self createAppClientForRoomId:roomId | 277 answerer = [self createAppClientForRoomId:roomId |
269 clientId:answererId | 278 clientId:answererId |
270 isInitiator:NO | 279 isInitiator:NO |
271 messages:[NSArray array] | 280 messages:[NSArray array] |
272 messageHandler:^(ARDSignalingMessage *message) { | 281 messageHandler:^(ARDSignalingMessage *message) { |
273 ARDAppClient *strongCaller = weakCaller; | 282 ARDAppClient *strongCaller = weakCaller; |
274 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; | 283 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
275 } connectedHandler:^{ | 284 } connectedHandler:^(NSInvocation *invocation){ |
276 [answererConnectionExpectation fulfill]; | 285 if ([NSStringFromSelector([invocation selector]) |
286 isEqualToString:@"appClient:didChangeConnectionState:"]) | |
287 [answererConnectionExpectation fulfill]; | |
277 }]; | 288 }]; |
278 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 289 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
279 // crash in Debug. | 290 // crash in Debug. |
280 answerer.defaultPeerConnectionConstraints = | 291 answerer.defaultPeerConnectionConstraints = |
281 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil | 292 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
282 optionalConstraints:nil]; | 293 optionalConstraints:nil]; |
283 weakAnswerer = answerer; | 294 weakAnswerer = answerer; |
284 | 295 |
285 // Kick off connection. | 296 // Kick off connection. |
286 [caller connectToRoomWithId:roomId | 297 [caller connectToRoomWithId:roomId |
287 isLoopback:NO | 298 isLoopback:NO |
288 isAudioOnly:NO | 299 isAudioOnly:NO |
289 shouldMakeAecDump:NO | 300 shouldMakeAecDump:NO |
290 shouldUseLevelControl:NO]; | 301 shouldUseLevelControl:NO]; |
291 [answerer connectToRoomWithId:roomId | 302 [answerer connectToRoomWithId:roomId |
292 isLoopback:NO | 303 isLoopback:NO |
293 isAudioOnly:NO | 304 isAudioOnly:NO |
294 shouldMakeAecDump:NO | 305 shouldMakeAecDump:NO |
295 shouldUseLevelControl:NO]; | 306 shouldUseLevelControl:NO]; |
296 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { | 307 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
297 if (error) { | 308 if (error) { |
298 NSLog(@"Expectations error: %@", error); | 309 NSLog(@"Expectations error: %@", error); |
299 } | 310 } |
300 }]; | 311 }]; |
301 } | 312 } |
302 | 313 |
314 // Test to see that we get a local video connection | |
315 // Note this will currently pass even when no camera is connected as a local | |
316 // video track is created regardless (Perhaps there should be a test for that... ) | |
317 - (void)testSession_ShouldGetLocalVideoTrackCallback { | |
daniela-webrtc
2016/10/17 11:33:31
Please remove the underscore from the name of the
| |
318 ARDAppClient *caller = nil; | |
319 NSString *roomId = @"testRoom"; | |
320 NSString *callerId = @"testCallerId"; | |
321 | |
322 ARDTestExpectation *callerConnectionExpectation = | |
323 [self expectationWithDescription:@"Caller PC connected."]; | |
324 | |
325 caller = [self createAppClientForRoomId:roomId | |
326 clientId:callerId | |
327 isInitiator:YES | |
328 messages:[NSArray array] | |
329 messageHandler:^(ARDSignalingMessage *message) { | |
330 } connectedHandler:^(NSInvocation *invocation){ | |
daniela-webrtc
2016/10/17 11:33:31
Nit: move connectedHandler parameter to next line
| |
331 if ([NSStringFromSelector([invocation selector]) | |
332 isEqualToString:@"appClient:didReceiveLocalVid eoTrack:"]) | |
333 [callerConnectionExpectation fulfill]; | |
334 }]; | |
335 caller.defaultPeerConnectionConstraints = | |
336 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil | |
337 optionalConstraints:nil]; | |
338 | |
339 // Kick off connection. | |
340 [caller connectToRoomWithId:roomId | |
341 isLoopback:NO | |
342 isAudioOnly:NO | |
343 shouldMakeAecDump:NO | |
344 shouldUseLevelControl:NO]; | |
345 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { | |
346 if (error) { | |
347 EXPECT_TRUE(0); | |
348 } | |
349 }]; | |
350 } | |
351 | |
303 @end | 352 @end |
304 | 353 |
354 @interface NSString (WebRTCTests) | |
355 - (BOOL) webrtc_containsString: (NSString *)otherString; | |
356 @end | |
357 @implementation NSString (WebRTCTests) | |
358 - (BOOL) webrtc_containsString: (NSString *)otherString | |
359 { | |
360 return (otherString && [self rangeOfString: otherString].location != NSNotFoun d); | |
361 } | |
362 @end | |
363 | |
305 @interface ARDSDPUtilsTest : ARDTestCase | 364 @interface ARDSDPUtilsTest : ARDTestCase |
306 - (void)testPreferVideoCodec; | 365 - (void)testPreferVideoCodec; |
307 @end | 366 @end |
308 | 367 |
309 @implementation ARDSDPUtilsTest | 368 @implementation ARDSDPUtilsTest |
310 | 369 |
370 | |
daniela-webrtc
2016/10/17 11:33:31
Nit: remove extra line
| |
311 - (void)testPreferVideoCodec { | 371 - (void)testPreferVideoCodec { |
312 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" | 372 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" |
313 "a=rtpmap:120 H264/90000\n"); | 373 "a=rtpmap:120 H264/90000\n"); |
314 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" | 374 NSArray *expectedSdpLines = @[@"m=video 9 RTP/SAVPF 120 100 116 117 96\n", |
315 "a=rtpmap:120 H264/90000\n"); | 375 @"a=rtpmap:120 H264/90000\n"]; |
316 RTCSessionDescription* desc = | 376 RTCSessionDescription* desc = |
317 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; | 377 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; |
318 RTCSessionDescription *h264Desc = | 378 RTCSessionDescription *h264Desc = |
319 [ARDSDPUtils descriptionForDescription:desc | 379 [ARDSDPUtils descriptionForDescription:desc |
320 preferredVideoCodec:@"H264"]; | 380 preferredVideoCodec:@"H264"]; |
321 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); | 381 EXPECT_TRUE([h264Desc.description webrtc_containsString: expectedSdpLines[0]] |
daniela-webrtc
2016/10/17 11:33:31
There seems to be no apparent change in the ARDSDP
afedor
2016/10/19 03:10:47
I get:
"RTCSessionDescription:\n
offer\n
m=video
| |
382 && [h264Desc.description webrtc_containsString: expectedSdpLines[1 ]]); | |
322 } | 383 } |
323 | 384 |
324 @end | 385 @end |
325 | 386 |
326 class SignalingTest : public ::testing::Test { | 387 class SignalingTest : public ::testing::Test { |
327 protected: | 388 protected: |
328 static void SetUpTestCase() { | 389 static void SetUpTestCase() { |
329 rtc::InitializeSSL(); | 390 rtc::InitializeSSL(); |
330 } | 391 } |
331 static void TearDownTestCase() { | 392 static void TearDownTestCase() { |
332 rtc::CleanupSSL(); | 393 rtc::CleanupSSL(); |
333 } | 394 } |
334 }; | 395 }; |
335 | 396 |
336 TEST_F(SignalingTest, SessionTest) { | 397 TEST_F(SignalingTest, SessionTest) { |
337 @autoreleasepool { | 398 @autoreleasepool { |
338 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; | 399 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; |
339 [test testSession]; | 400 [test testSession]; |
340 } | 401 } |
341 } | 402 } |
342 | 403 |
404 TEST_F(SignalingTest, SessionLocalVideoCallbackTest) { | |
405 @autoreleasepool { | |
406 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; | |
407 [test testSession_ShouldGetLocalVideoTrackCallback]; | |
408 } | |
409 } | |
410 | |
343 TEST_F(SignalingTest, SDPTest) { | 411 TEST_F(SignalingTest, SDPTest) { |
344 @autoreleasepool { | 412 @autoreleasepool { |
345 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; | 413 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |
346 [test testPreferVideoCodec]; | 414 [test testPreferVideoCodec]; |
347 } | 415 } |
348 } | 416 } |
349 | 417 |
350 | 418 int main(int argc, char **argv) { |
419 ::testing::InitGoogleTest(&argc, argv); | |
420 return RUN_ALL_TESTS(); | |
421 } | |
OLD | NEW |