Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm

Issue 2050153003: Update Unit test for AppRTCMobile app (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More styling Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/examples/objc/AppRTCMobile/ARDAppClient.m ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #import <Foundation/Foundation.h> 11 #import <Foundation/Foundation.h>
12 #import <OCMock/OCMock.h> 12 #import <OCMock/OCMock.h>
13 #import <QuartzCore/CoreAnimation.h>
13 14
14 #include "webrtc/base/gunit.h" 15 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/ssladapter.h" 16 #include "webrtc/base/ssladapter.h"
16 17
17 #import "WebRTC/RTCMediaConstraints.h" 18 #import "WebRTC/RTCMediaConstraints.h"
18 #import "WebRTC/RTCPeerConnectionFactory.h" 19 #import "WebRTC/RTCPeerConnectionFactory.h"
19 #import "WebRTC/RTCSessionDescription.h" 20 #import "WebRTC/RTCSessionDescription.h"
20 21
21 #import "ARDAppClient+Internal.h" 22 #import "ARDAppClient+Internal.h"
22 #import "ARDJoinResponse+Internal.h" 23 #import "ARDJoinResponse+Internal.h"
23 #import "ARDMessageResponse+Internal.h" 24 #import "ARDMessageResponse+Internal.h"
24 #import "ARDSDPUtils.h" 25 #import "ARDSDPUtils.h"
25 26
27 static NSString *kARDAppClientTestsDomain = @"org.webrtc.ARDAppClientTests";
28 static NSInteger kARDAppClientTestsExpectationTimeoutError = 100;
29
26 // These classes mimic XCTest APIs, to make eventual conversion to XCTest 30 // These classes mimic XCTest APIs, to make eventual conversion to XCTest
27 // easier. Conversion will happen once XCTest is supported well on build bots. 31 // easier. Conversion will happen once XCTest is supported well on build bots.
28 @interface ARDTestExpectation : NSObject 32 @interface ARDTestExpectation : NSObject
29 33
30 @property(nonatomic, readonly) NSString *description; 34 @property(nonatomic, readonly) NSString *description;
31 @property(nonatomic, readonly) BOOL isFulfilled; 35 @property(nonatomic, readonly) BOOL isFulfilled;
32 36
33 - (instancetype)initWithDescription:(NSString *)description; 37 - (instancetype)initWithDescription:(NSString *)description;
34 - (void)fulfill; 38 - (void)fulfill;
35 39
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 78
75 - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { 79 - (ARDTestExpectation *)expectationWithDescription:(NSString *)description {
76 ARDTestExpectation *expectation = 80 ARDTestExpectation *expectation =
77 [[ARDTestExpectation alloc] initWithDescription:description]; 81 [[ARDTestExpectation alloc] initWithDescription:description];
78 [_expectations addObject:expectation]; 82 [_expectations addObject:expectation];
79 return expectation; 83 return expectation;
80 } 84 }
81 85
82 - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout 86 - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout
83 handler:(void (^)(NSError *error))handler { 87 handler:(void (^)(NSError *error))handler {
84 NSDate *startDate = [NSDate date]; 88 CFTimeInterval startTime = CACurrentMediaTime();
89 NSError *error = nil;
85 while (![self areExpectationsFulfilled]) { 90 while (![self areExpectationsFulfilled]) {
86 NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; 91 CFTimeInterval duration = CACurrentMediaTime() - startTime;
87 if (duration > timeout) { 92 if (duration > timeout) {
88 NSAssert(NO, @"Expectation timed out."); 93 error = [NSError errorWithDomain:kARDAppClientTestsDomain
94 code:kARDAppClientTestsExpectationTimeoutError
95 userInfo:@{}];
89 break; 96 break;
90 } 97 }
91 [[NSRunLoop currentRunLoop] 98 [[NSRunLoop currentRunLoop]
92 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; 99 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
93 } 100 }
94 handler(nil); 101 handler(error);
95 } 102 }
96 103
97 - (BOOL)areExpectationsFulfilled { 104 - (BOOL)areExpectationsFulfilled {
98 for (ARDTestExpectation *expectation in _expectations) { 105 for (ARDTestExpectation *expectation in _expectations) {
99 if (!expectation.isFulfilled) { 106 if (!expectation.isFulfilled) {
100 return NO; 107 return NO;
101 } 108 }
102 } 109 }
103 return YES; 110 return YES;
104 } 111 }
(...skipping 25 matching lines...) Expand all
130 joinResponse.messages = messages; 137 joinResponse.messages = messages;
131 138
132 // Successful message response. 139 // Successful message response.
133 ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init]; 140 ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init];
134 messageResponse.result = kARDMessageResultTypeSuccess; 141 messageResponse.result = kARDMessageResultTypeSuccess;
135 142
136 // Return join response from above on join. 143 // Return join response from above on join.
137 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { 144 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) {
138 __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, 145 __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response,
139 NSError *error); 146 NSError *error);
140 [invocation getArgument:&completionHandler atIndex:3]; 147 [invocation getArgument:&completionHandler atIndex:4];
141 completionHandler(joinResponse, nil); 148 completionHandler(joinResponse, nil);
142 }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; 149 }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]];
143 150
144 // Return message response from above on join. 151 // Return message response from above on join.
145 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { 152 [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) {
146 __unsafe_unretained ARDSignalingMessage *message; 153 __unsafe_unretained ARDSignalingMessage *message;
147 __unsafe_unretained void (^completionHandler)(ARDMessageResponse *response, 154 __unsafe_unretained void (^completionHandler)(ARDMessageResponse *response,
148 NSError *error); 155 NSError *error);
149 [invocation getArgument:&message atIndex:2]; 156 [invocation getArgument:&message atIndex:2];
150 [invocation getArgument:&completionHandler atIndex:5]; 157 [invocation getArgument:&completionHandler atIndex:5];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 }] requestServersWithCompletionHandler:[OCMArg any]]; 203 }] requestServersWithCompletionHandler:[OCMArg any]];
197 return mockTURNClient; 204 return mockTURNClient;
198 } 205 }
199 206
200 - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId 207 - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId
201 clientId:(NSString *)clientId 208 clientId:(NSString *)clientId
202 isInitiator:(BOOL)isInitiator 209 isInitiator:(BOOL)isInitiator
203 messages:(NSArray *)messages 210 messages:(NSArray *)messages
204 messageHandler: 211 messageHandler:
205 (void (^)(ARDSignalingMessage *message))messageHandler 212 (void (^)(ARDSignalingMessage *message))messageHandler
206 connectedHandler:(void (^)(void))connectedHandler { 213 connectedHandler:(void (^)(void))connectedHandler
214 localVideoTrackHandler:(void (^)(void))localVideoTrackHandle r {
207 id turnClient = [self mockTURNClient]; 215 id turnClient = [self mockTURNClient];
208 id signalingChannel = [self mockSignalingChannelForRoomId:roomId 216 id signalingChannel = [self mockSignalingChannelForRoomId:roomId
209 clientId:clientId 217 clientId:clientId
210 messageHandler:messageHandler]; 218 messageHandler:messageHandler];
211 id roomServerClient = 219 id roomServerClient =
212 [self mockRoomServerClientForRoomId:roomId 220 [self mockRoomServerClientForRoomId:roomId
213 clientId:clientId 221 clientId:clientId
214 isInitiator:isInitiator 222 isInitiator:isInitiator
215 messages:messages 223 messages:messages
216 messageHandler:messageHandler]; 224 messageHandler:messageHandler];
217 id delegate = 225 id delegate =
218 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; 226 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)];
219 [[[delegate stub] andDo:^(NSInvocation *invocation) { 227 [[[delegate stub] andDo:^(NSInvocation *invocation) {
220 connectedHandler(); 228 connectedHandler();
221 }] appClient:[OCMArg any] 229 }] appClient:[OCMArg any]
222 didChangeConnectionState:RTCIceConnectionStateConnected]; 230 didChangeConnectionState:RTCIceConnectionStateConnected];
231 [[[delegate stub] andDo:^(NSInvocation *invocation) {
232 localVideoTrackHandler();
233 }] appClient:[OCMArg any]
234 didReceiveLocalVideoTrack:[OCMArg any]];
223 235
224 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient 236 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient
225 signalingChannel:signalingChannel 237 signalingChannel:signalingChannel
226 turnClient:turnClient 238 turnClient:turnClient
227 delegate:delegate]; 239 delegate:delegate];
228 } 240 }
229 241
230 // Tests that an ICE connection is established between two ARDAppClient objects 242 // 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 243 // 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 244 // components are mocked out and messages are relayed directly from object to
(...skipping 15 matching lines...) Expand all
248 ARDTestExpectation *answererConnectionExpectation = 260 ARDTestExpectation *answererConnectionExpectation =
249 [self expectationWithDescription:@"Answerer PC connected."]; 261 [self expectationWithDescription:@"Answerer PC connected."];
250 262
251 caller = [self createAppClientForRoomId:roomId 263 caller = [self createAppClientForRoomId:roomId
252 clientId:callerId 264 clientId:callerId
253 isInitiator:YES 265 isInitiator:YES
254 messages:[NSArray array] 266 messages:[NSArray array]
255 messageHandler:^(ARDSignalingMessage *message) { 267 messageHandler:^(ARDSignalingMessage *message) {
256 ARDAppClient *strongAnswerer = weakAnswerer; 268 ARDAppClient *strongAnswerer = weakAnswerer;
257 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; 269 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message];
258 } connectedHandler:^{ 270 } connectedHandler:^{
259 [callerConnectionExpectation fulfill]; 271 [callerConnectionExpectation fulfill];
272 } localVideoTrackHandler:^{
260 }]; 273 }];
261 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion 274 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion
262 // crash in Debug. 275 // crash in Debug.
263 caller.defaultPeerConnectionConstraints = 276 caller.defaultPeerConnectionConstraints =
264 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil 277 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
265 optionalConstraints:nil]; 278 optionalConstraints:nil];
266 weakCaller = caller; 279 weakCaller = caller;
267 280
268 answerer = [self createAppClientForRoomId:roomId 281 answerer = [self createAppClientForRoomId:roomId
269 clientId:answererId 282 clientId:answererId
270 isInitiator:NO 283 isInitiator:NO
271 messages:[NSArray array] 284 messages:[NSArray array]
272 messageHandler:^(ARDSignalingMessage *message) { 285 messageHandler:^(ARDSignalingMessage *message) {
273 ARDAppClient *strongCaller = weakCaller; 286 ARDAppClient *strongCaller = weakCaller;
274 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; 287 [strongCaller channel:strongCaller.channel didReceiveMessage:message];
275 } connectedHandler:^{ 288 } connectedHandler:^{
276 [answererConnectionExpectation fulfill]; 289 [answererConnectionExpectation fulfill];
290 } localVideoTrackHandler:^{
277 }]; 291 }];
278 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion 292 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion
279 // crash in Debug. 293 // crash in Debug.
280 answerer.defaultPeerConnectionConstraints = 294 answerer.defaultPeerConnectionConstraints =
281 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil 295 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
282 optionalConstraints:nil]; 296 optionalConstraints:nil];
283 weakAnswerer = answerer; 297 weakAnswerer = answerer;
284 298
285 // Kick off connection. 299 // Kick off connection.
286 [caller connectToRoomWithId:roomId 300 [caller connectToRoomWithId:roomId
287 isLoopback:NO 301 isLoopback:NO
288 isAudioOnly:NO 302 isAudioOnly:NO
289 shouldMakeAecDump:NO 303 shouldMakeAecDump:NO
290 shouldUseLevelControl:NO]; 304 shouldUseLevelControl:NO];
291 [answerer connectToRoomWithId:roomId 305 [answerer connectToRoomWithId:roomId
292 isLoopback:NO 306 isLoopback:NO
293 isAudioOnly:NO 307 isAudioOnly:NO
294 shouldMakeAecDump:NO 308 shouldMakeAecDump:NO
295 shouldUseLevelControl:NO]; 309 shouldUseLevelControl:NO];
296 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { 310 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) {
297 if (error) { 311 if (error) {
298 NSLog(@"Expectations error: %@", error); 312 EXPECT_TRUE(0);
299 } 313 }
300 }]; 314 }];
301 } 315 }
316
317 // Test to see that we get a local video connection
318 // Note this will currently pass even when no camera is connected as a local
319 // video track is created regardless (Perhaps there should be a test for that... )
320 - (void)testSessionShouldGetLocalVideoTrackCallback {
321 ARDAppClient *caller = nil;
322 NSString *roomId = @"testRoom";
323 NSString *callerId = @"testCallerId";
324
325 ARDTestExpectation *localVideoTrackExpectation =
326 [self expectationWithDescription:@"Caller got local video."];
327
328 caller = [self createAppClientForRoomId:roomId
329 clientId:callerId
330 isInitiator:YES
331 messages:[NSArray array]
332 messageHandler:^(ARDSignalingMessage *message) {
333 } connectedHandler:^{
334 } localVideoTrackHandler:^{
335 [localVideoTrackExpectation fulfill];
336 }];
337 caller.defaultPeerConnectionConstraints =
338 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
339 optionalConstraints:nil];
340
341 // Kick off connection.
342 [caller connectToRoomWithId:roomId
343 isLoopback:NO
344 isAudioOnly:NO
345 shouldMakeAecDump:NO
346 shouldUseLevelControl:NO];
347 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) {
348 if (error) {
349 EXPECT_TRUE(0);
350 }
351 }];
352 }
302 353
303 @end 354 @end
304 355
305 @interface ARDSDPUtilsTest : ARDTestCase 356 @interface ARDSDPUtilsTest : ARDTestCase
306 - (void)testPreferVideoCodec; 357 - (void)testPreferVideoCodec;
307 @end 358 @end
308 359
309 @implementation ARDSDPUtilsTest 360 @implementation ARDSDPUtilsTest
310 361
311 - (void)testPreferVideoCodec { 362 - (void)testPreferVideoCodec {
312 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" 363 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n"
313 "a=rtpmap:120 H264/90000\n"); 364 "a=rtpmap:120 H264/90000\n");
314 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" 365 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n"
315 "a=rtpmap:120 H264/90000\n"); 366 "a=rtpmap:120 H264/90000\n");
316 RTCSessionDescription* desc = 367 RTCSessionDescription* desc =
317 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; 368 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp];
318 RTCSessionDescription *h264Desc = 369 RTCSessionDescription *h264Desc =
319 [ARDSDPUtils descriptionForDescription:desc 370 [ARDSDPUtils descriptionForDescription:desc
320 preferredVideoCodec:@"H264"]; 371 preferredVideoCodec:@"H264"];
321 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); 372 EXPECT_TRUE([h264Desc.description rangeOfString:expectedSdp].location != NSNot Found);
322 } 373 }
323 374
324 @end 375 @end
325 376
326 class SignalingTest : public ::testing::Test { 377 class SignalingTest : public ::testing::Test {
327 protected: 378 protected:
328 static void SetUpTestCase() { 379 static void SetUpTestCase() {
329 rtc::InitializeSSL(); 380 rtc::InitializeSSL();
330 } 381 }
331 static void TearDownTestCase() { 382 static void TearDownTestCase() {
332 rtc::CleanupSSL(); 383 rtc::CleanupSSL();
333 } 384 }
334 }; 385 };
335 386
336 TEST_F(SignalingTest, SessionTest) { 387 TEST_F(SignalingTest, SessionTest) {
337 @autoreleasepool { 388 @autoreleasepool {
338 ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; 389 ARDAppClientTest *test = [[ARDAppClientTest alloc] init];
339 [test testSession]; 390 [test testSession];
340 } 391 }
341 } 392 }
342 393
394 #if !TARGET_IPHONE_SIMULATOR
395 // Expected fail on iOS Simulator due to no camera support
396 TEST_F(SignalingTest, SessionLocalVideoCallbackTest) {
397 @autoreleasepool {
398 ARDAppClientTest *test = [[ARDAppClientTest alloc] init];
399 [test testSessionShouldGetLocalVideoTrackCallback];
400 }
401 }
402 #endif
403
343 TEST_F(SignalingTest, SDPTest) { 404 TEST_F(SignalingTest, SDPTest) {
344 @autoreleasepool { 405 @autoreleasepool {
345 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; 406 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init];
346 [test testPreferVideoCodec]; 407 [test testPreferVideoCodec];
347 } 408 }
348 } 409 }
349 410
350 411 int main(int argc, char **argv) {
412 ::testing::InitGoogleTest(&argc, argv);
413 return RUN_ALL_TESTS();
414 }
OLDNEW
« no previous file with comments | « webrtc/examples/objc/AppRTCMobile/ARDAppClient.m ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698