Chromium Code Reviews| Index: webrtc/examples/objc/AppRTCDemo/tests/ARDAppClientTest.mm |
| diff --git a/webrtc/examples/objc/AppRTCDemo/tests/ARDAppClientTest.mm b/webrtc/examples/objc/AppRTCDemo/tests/ARDAppClientTest.mm |
| index 169f9991e1ab5cb2221ef3bdb6941432f6a7bb7f..8aa67be00f03a0e4a392f2b788e84bce138cc81b 100644 |
| --- a/webrtc/examples/objc/AppRTCDemo/tests/ARDAppClientTest.mm |
| +++ b/webrtc/examples/objc/AppRTCDemo/tests/ARDAppClientTest.mm |
| @@ -82,16 +82,19 @@ - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { |
| - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout |
| handler:(void (^)(NSError *error))handler { |
| NSDate *startDate = [NSDate date]; |
|
tkchin_webrtc
2016/09/29 11:14:40
Probably better to use media timing here for accur
|
| + NSError *error = nil; |
| while (![self areExpectationsFulfilled]) { |
| NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; |
| if (duration > timeout) { |
| - NSAssert(NO, @"Expectation timed out."); |
| + error = [NSError errorWithDomain:@"ARDAppClient" |
|
tkchin_webrtc
2016/09/29 11:14:40
Not sure we need this error. We'd want to just do
tkchin_webrtc
2016/09/29 11:14:40
make domain a global constant. org.webrtc.ARDAppCl
|
| + code:101 |
|
tkchin_webrtc
2016/09/29 11:14:40
likewise, global constant
kARDAppClientTestsExpect
|
| + userInfo:@{NSLocalizedDescriptionKey : @"Expectation timed out"}]; |
| break; |
| } |
| [[NSRunLoop currentRunLoop] |
| runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
| } |
| - handler(nil); |
| + handler(error); |
| } |
| - (BOOL)areExpectationsFulfilled { |
| @@ -137,7 +140,7 @@ - (id)mockRoomServerClientForRoomId:(NSString *)roomId |
| [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { |
| __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, |
| NSError *error); |
| - [invocation getArgument:&completionHandler atIndex:3]; |
| + [invocation getArgument:&completionHandler atIndex:4]; |
| completionHandler(joinResponse, nil); |
| }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; |
| @@ -203,7 +206,7 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
| messages:(NSArray *)messages |
| messageHandler: |
| (void (^)(ARDSignalingMessage *message))messageHandler |
| - connectedHandler:(void (^)(void))connectedHandler { |
| + connectedHandler:(void (^)(NSInvocation *))connectedHandler { |
|
tkchin_webrtc
2016/09/29 11:14:40
would rather not be passing NSInvocation around to
afedor
2016/11/02 14:11:02
How about just passing back the selector name?
|
| id turnClient = [self mockTURNClient]; |
| id signalingChannel = [self mockSignalingChannelForRoomId:roomId |
| clientId:clientId |
| @@ -217,9 +220,13 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
| id delegate = |
| [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
| [[[delegate stub] andDo:^(NSInvocation *invocation) { |
| - connectedHandler(); |
| + connectedHandler(invocation); |
| }] appClient:[OCMArg any] |
| didChangeConnectionState:RTCIceConnectionStateConnected]; |
| + [[[delegate stub] andDo:^(NSInvocation *invocation) { |
| + connectedHandler(invocation); |
|
tkchin_webrtc
2016/09/29 11:14:40
I feel like this should be a different handler ins
|
| + }] appClient:[OCMArg any] |
| + didReceiveLocalVideoTrack:[OCMArg any]]; |
| return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
| signalingChannel:signalingChannel |
| @@ -255,8 +262,10 @@ - (void)testSession { |
| messageHandler:^(ARDSignalingMessage *message) { |
| ARDAppClient *strongAnswerer = weakAnswerer; |
| [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
| - } connectedHandler:^{ |
| - [callerConnectionExpectation fulfill]; |
| + } connectedHandler:^(NSInvocation *invocation){ |
| + if ([NSStringFromSelector([invocation selector]) |
| + isEqualToString:@"appClient:didChangeConnectionState:"]) |
| + [callerConnectionExpectation fulfill]; |
| }]; |
| // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
| // crash in Debug. |
| @@ -272,8 +281,10 @@ - (void)testSession { |
| messageHandler:^(ARDSignalingMessage *message) { |
| ARDAppClient *strongCaller = weakCaller; |
| [strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
| - } connectedHandler:^{ |
| - [answererConnectionExpectation fulfill]; |
| + } connectedHandler:^(NSInvocation *invocation){ |
| + if ([NSStringFromSelector([invocation selector]) |
| + isEqualToString:@"appClient:didChangeConnectionState:"]) |
| + [answererConnectionExpectation fulfill]; |
| }]; |
| // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
| // crash in Debug. |
| @@ -292,6 +303,50 @@ - (void)testSession { |
| }]; |
| } |
| +// Test to see that we get a local video connection |
| +// Note this will currently pass even when no camera is connected as a local |
| +// video track is created regardless (Perhaps there should be a test for that...) |
| +- (void)testSession_ShouldGetLocalVideoTrackCallback { |
| + ARDAppClient *caller = nil; |
| + NSString *roomId = @"testRoom"; |
| + NSString *callerId = @"testCallerId"; |
| + |
| + ARDTestExpectation *callerConnectionExpectation = |
| + [self expectationWithDescription:@"Caller PC connected."]; |
| + |
| + caller = [self createAppClientForRoomId:roomId |
| + clientId:callerId |
| + isInitiator:YES |
| + messages:[NSArray array] |
| + messageHandler:^(ARDSignalingMessage *message) { |
|
tkchin_webrtc
2016/09/29 11:14:40
fix indentation
|
| + } connectedHandler:^(NSInvocation *invocation){ |
| + if ([NSStringFromSelector([invocation selector]) |
| + isEqualToString:@"appClient:didReceiveLocalVideoTrack:"]) |
| + [callerConnectionExpectation fulfill]; |
| + }]; |
| + caller.defaultPeerConnectionConstraints = |
| + [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
| + optionalConstraints:nil]; |
| + |
| + // Kick off connection. |
| + [caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; |
| + [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
| + if (error) { |
| + EXPECT_TRUE(0); |
| + } |
| + }]; |
| +} |
| + |
| +@end |
| + |
| +@interface NSString (WebRTCTests) |
|
tkchin_webrtc
2016/09/29 11:14:40
I don't think we need an extra category for this s
|
| +- (BOOL) webrtc_containsString: (NSString *)otherString; |
| +@end |
| +@implementation NSString (WebRTCTests) |
| +- (BOOL) webrtc_containsString: (NSString *)otherString |
| +{ |
| + return (otherString && [self rangeOfString: otherString].location != NSNotFound); |
| +} |
| @end |
| @interface ARDSDPUtilsTest : ARDTestCase |
| @@ -300,17 +355,19 @@ - (void)testPreferVideoCodec; |
| @implementation ARDSDPUtilsTest |
| + |
| - (void)testPreferVideoCodec { |
| NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" |
| "a=rtpmap:120 H264/90000\n"); |
| - NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" |
|
tkchin_webrtc
2016/09/29 11:14:40
don't know how this got here but it's intended to
|
| - "a=rtpmap:120 H264/90000\n"); |
| + NSArray *expectedSdpLines = @[@"m=video 9 RTP/SAVPF 120 100 116 117 96\n", |
| + @"a=rtpmap:120 H264/90000\n"]; |
| RTCSessionDescription* desc = |
| [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; |
| RTCSessionDescription *h264Desc = |
| [ARDSDPUtils descriptionForDescription:desc |
| preferredVideoCodec:@"H264"]; |
| - EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); |
| + EXPECT_TRUE([h264Desc.description webrtc_containsString: expectedSdpLines[0]] |
| + && [h264Desc.description webrtc_containsString: expectedSdpLines[1]]); |
| } |
| @end |
| @@ -332,6 +389,13 @@ static void TearDownTestCase() { |
| } |
| } |
| +TEST_F(SignalingTest, SessionLocalVideoCallbackTest) { |
| + @autoreleasepool { |
| + ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; |
| + [test testSession_ShouldGetLocalVideoTrackCallback]; |
| + } |
| +} |
| + |
| TEST_F(SignalingTest, SDPTest) { |
| @autoreleasepool { |
| ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |