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