| 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:@"ARDAppClientTest" |
| 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 EXPECT_TRUE(0); |
| 310 } |
| 311 }]; |
| 312 } |
| 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)testSessionShouldGetLocalVideoTrackCallback { |
| 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 } |
| 331 connectedHandler:^(NSInvocation *invocation){ |
| 332 if ([NSStringFromSelector([invocation selector]) |
| 333 isEqualToString:@"appClient:didReceiveLocalVid
eoTrack:"]) |
| 334 [callerConnectionExpectation fulfill]; |
| 335 }]; |
| 336 caller.defaultPeerConnectionConstraints = |
| 337 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
| 338 optionalConstraints:nil]; |
| 339 |
| 340 // Kick off connection. |
| 341 [caller connectToRoomWithId:roomId |
| 342 isLoopback:NO |
| 343 isAudioOnly:NO |
| 344 shouldMakeAecDump:NO |
| 345 shouldUseLevelControl:NO]; |
| 346 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
| 347 if (error) { |
| 348 EXPECT_TRUE(0); |
| 299 } | 349 } |
| 300 }]; | 350 }]; |
| 301 } | 351 } |
| 302 | 352 |
| 303 @end | 353 @end |
| 304 | 354 |
| 355 @interface NSString (WebRTCTests) |
| 356 - (BOOL) webrtc_containsString: (NSString *)otherString; |
| 357 @end |
| 358 @implementation NSString (WebRTCTests) |
| 359 - (BOOL) webrtc_containsString: (NSString *)otherString |
| 360 { |
| 361 return (otherString && [self rangeOfString: otherString].location != NSNotFoun
d); |
| 362 } |
| 363 @end |
| 364 |
| 305 @interface ARDSDPUtilsTest : ARDTestCase | 365 @interface ARDSDPUtilsTest : ARDTestCase |
| 306 - (void)testPreferVideoCodec; | 366 - (void)testPreferVideoCodec; |
| 307 @end | 367 @end |
| 308 | 368 |
| 309 @implementation ARDSDPUtilsTest | 369 @implementation ARDSDPUtilsTest |
| 310 | 370 |
| 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 NSString *expectedSdp = @("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: expectedSdp]); |
| 322 } | 382 } |
| 323 | 383 |
| 324 @end | 384 @end |
| 325 | 385 |
| 326 class SignalingTest : public ::testing::Test { | 386 class SignalingTest : public ::testing::Test { |
| 327 protected: | 387 protected: |
| 328 static void SetUpTestCase() { | 388 static void SetUpTestCase() { |
| 329 rtc::InitializeSSL(); | 389 rtc::InitializeSSL(); |
| 330 } | 390 } |
| 331 static void TearDownTestCase() { | 391 static void TearDownTestCase() { |
| 332 rtc::CleanupSSL(); | 392 rtc::CleanupSSL(); |
| 333 } | 393 } |
| 334 }; | 394 }; |
| 335 | 395 |
| 336 TEST_F(SignalingTest, SessionTest) { | 396 TEST_F(SignalingTest, SessionTest) { |
| 337 @autoreleasepool { | 397 @autoreleasepool { |
| 338 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; | 398 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; |
| 339 [test testSession]; | 399 [test testSession]; |
| 340 } | 400 } |
| 341 } | 401 } |
| 342 | 402 |
| 403 #if !TARGET_IPHONE_SIMULATOR |
| 404 // Expected fail on iOS Simulator due to no camera support |
| 405 TEST_F(SignalingTest, SessionLocalVideoCallbackTest) { |
| 406 @autoreleasepool { |
| 407 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; |
| 408 [test testSessionShouldGetLocalVideoTrackCallback]; |
| 409 } |
| 410 } |
| 411 #endif |
| 412 |
| 343 TEST_F(SignalingTest, SDPTest) { | 413 TEST_F(SignalingTest, SDPTest) { |
| 344 @autoreleasepool { | 414 @autoreleasepool { |
| 345 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; | 415 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |
| 346 [test testPreferVideoCodec]; | 416 [test testPreferVideoCodec]; |
| 347 } | 417 } |
| 348 } | 418 } |
| 349 | 419 |
| 350 | 420 int main(int argc, char **argv) { |
| 421 ::testing::InitGoogleTest(&argc, argv); |
| 422 return RUN_ALL_TESTS(); |
| 423 } |
| OLD | NEW |