| 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 |
| 11 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
| 12 #import <OCMock/OCMock.h> | 12 #import <OCMock/OCMock.h> |
| 13 | 13 |
| 14 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/ssladapter.h" |
| 16 |
| 17 #import "webrtc/api/objc/RTCMediaConstraints.h" |
| 18 #import "webrtc/api/objc/RTCPeerConnectionFactory.h" |
| 19 #import "webrtc/api/objc/RTCSessionDescription.h" |
| 20 |
| 14 #import "ARDAppClient+Internal.h" | 21 #import "ARDAppClient+Internal.h" |
| 15 #import "ARDJoinResponse+Internal.h" | 22 #import "ARDJoinResponse+Internal.h" |
| 16 #import "ARDMessageResponse+Internal.h" | 23 #import "ARDMessageResponse+Internal.h" |
| 17 #import "ARDSDPUtils.h" | 24 #import "ARDSDPUtils.h" |
| 18 #import "RTCMediaConstraints.h" | |
| 19 #import "RTCPeerConnectionFactory.h" | |
| 20 #import "RTCSessionDescription.h" | |
| 21 | |
| 22 #include "webrtc/base/gunit.h" | |
| 23 #include "webrtc/base/ssladapter.h" | |
| 24 | 25 |
| 25 // These classes mimic XCTest APIs, to make eventual conversion to XCTest | 26 // These classes mimic XCTest APIs, to make eventual conversion to XCTest |
| 26 // easier. Conversion will happen once XCTest is supported well on build bots. | 27 // easier. Conversion will happen once XCTest is supported well on build bots. |
| 27 @interface ARDTestExpectation : NSObject | 28 @interface ARDTestExpectation : NSObject |
| 28 | 29 |
| 29 @property(nonatomic, readonly) NSString *description; | 30 @property(nonatomic, readonly) NSString *description; |
| 30 @property(nonatomic, readonly) BOOL isFulfilled; | 31 @property(nonatomic, readonly) BOOL isFulfilled; |
| 31 | 32 |
| 32 - (instancetype)initWithDescription:(NSString *)description; | 33 - (instancetype)initWithDescription:(NSString *)description; |
| 33 - (void)fulfill; | 34 - (void)fulfill; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 id roomServerClient = | 211 id roomServerClient = |
| 211 [self mockRoomServerClientForRoomId:roomId | 212 [self mockRoomServerClientForRoomId:roomId |
| 212 clientId:clientId | 213 clientId:clientId |
| 213 isInitiator:isInitiator | 214 isInitiator:isInitiator |
| 214 messages:messages | 215 messages:messages |
| 215 messageHandler:messageHandler]; | 216 messageHandler:messageHandler]; |
| 216 id delegate = | 217 id delegate = |
| 217 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; | 218 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
| 218 [[[delegate stub] andDo:^(NSInvocation *invocation) { | 219 [[[delegate stub] andDo:^(NSInvocation *invocation) { |
| 219 connectedHandler(); | 220 connectedHandler(); |
| 220 }] appClient:[OCMArg any] didChangeConnectionState:RTCICEConnectionConnected]; | 221 }] appClient:[OCMArg any] |
| 222 didChangeConnectionState:RTCIceConnectionStateConnected]; |
| 221 | 223 |
| 222 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient | 224 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
| 223 signalingChannel:signalingChannel | 225 signalingChannel:signalingChannel |
| 224 turnClient:turnClient | 226 turnClient:turnClient |
| 225 delegate:delegate]; | 227 delegate:delegate]; |
| 226 } | 228 } |
| 227 | 229 |
| 228 // Tests that an ICE connection is established between two ARDAppClient objects | 230 // Tests that an ICE connection is established between two ARDAppClient objects |
| 229 // where one is set up as a caller and the other the answerer. Network | 231 // where one is set up as a caller and the other the answerer. Network |
| 230 // components are mocked out and messages are relayed directly from object to | 232 // components are mocked out and messages are relayed directly from object to |
| 231 // object. It's expected that both clients reach the RTCICEConnectionConnected | 233 // object. It's expected that both clients reach the |
| 232 // state within a reasonable amount of time. | 234 // RTCIceConnectionStateConnected state within a reasonable amount of time. |
| 233 - (void)testSession { | 235 - (void)testSession { |
| 234 // Need block arguments here because we're setting up a callbacks before we | 236 // Need block arguments here because we're setting up a callbacks before we |
| 235 // create the clients. | 237 // create the clients. |
| 236 ARDAppClient *caller = nil; | 238 ARDAppClient *caller = nil; |
| 237 ARDAppClient *answerer = nil; | 239 ARDAppClient *answerer = nil; |
| 238 __block __weak ARDAppClient *weakCaller = nil; | 240 __block __weak ARDAppClient *weakCaller = nil; |
| 239 __block __weak ARDAppClient *weakAnswerer = nil; | 241 __block __weak ARDAppClient *weakAnswerer = nil; |
| 240 NSString *roomId = @"testRoom"; | 242 NSString *roomId = @"testRoom"; |
| 241 NSString *callerId = @"testCallerId"; | 243 NSString *callerId = @"testCallerId"; |
| 242 NSString *answererId = @"testAnswererId"; | 244 NSString *answererId = @"testAnswererId"; |
| 243 | 245 |
| 244 ARDTestExpectation *callerConnectionExpectation = | 246 ARDTestExpectation *callerConnectionExpectation = |
| 245 [self expectationWithDescription:@"Caller PC connected."]; | 247 [self expectationWithDescription:@"Caller PC connected."]; |
| 246 ARDTestExpectation *answererConnectionExpectation = | 248 ARDTestExpectation *answererConnectionExpectation = |
| 247 [self expectationWithDescription:@"Answerer PC connected."]; | 249 [self expectationWithDescription:@"Answerer PC connected."]; |
| 248 | 250 |
| 249 caller = [self createAppClientForRoomId:roomId | 251 caller = [self createAppClientForRoomId:roomId |
| 250 clientId:callerId | 252 clientId:callerId |
| 251 isInitiator:YES | 253 isInitiator:YES |
| 252 messages:[NSArray array] | 254 messages:[NSArray array] |
| 253 messageHandler:^(ARDSignalingMessage *message) { | 255 messageHandler:^(ARDSignalingMessage *message) { |
| 254 ARDAppClient *strongAnswerer = weakAnswerer; | 256 ARDAppClient *strongAnswerer = weakAnswerer; |
| 255 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; | 257 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
| 256 } connectedHandler:^{ | 258 } connectedHandler:^{ |
| 257 [callerConnectionExpectation fulfill]; | 259 [callerConnectionExpectation fulfill]; |
| 258 }]; | 260 }]; |
| 259 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 261 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
| 260 // crash in Debug. | 262 // crash in Debug. |
| 261 caller.defaultPeerConnectionConstraints = [[RTCMediaConstraints alloc] init]; | 263 caller.defaultPeerConnectionConstraints = |
| 264 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
| 265 optionalConstraints:nil]; |
| 262 weakCaller = caller; | 266 weakCaller = caller; |
| 263 | 267 |
| 264 answerer = [self createAppClientForRoomId:roomId | 268 answerer = [self createAppClientForRoomId:roomId |
| 265 clientId:answererId | 269 clientId:answererId |
| 266 isInitiator:NO | 270 isInitiator:NO |
| 267 messages:[NSArray array] | 271 messages:[NSArray array] |
| 268 messageHandler:^(ARDSignalingMessage *message) { | 272 messageHandler:^(ARDSignalingMessage *message) { |
| 269 ARDAppClient *strongCaller = weakCaller; | 273 ARDAppClient *strongCaller = weakCaller; |
| 270 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; | 274 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
| 271 } connectedHandler:^{ | 275 } connectedHandler:^{ |
| 272 [answererConnectionExpectation fulfill]; | 276 [answererConnectionExpectation fulfill]; |
| 273 }]; | 277 }]; |
| 274 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 278 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
| 275 // crash in Debug. | 279 // crash in Debug. |
| 276 answerer.defaultPeerConnectionConstraints = | 280 answerer.defaultPeerConnectionConstraints = |
| 277 [[RTCMediaConstraints alloc] init]; | 281 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
| 282 optionalConstraints:nil]; |
| 278 weakAnswerer = answerer; | 283 weakAnswerer = answerer; |
| 279 | 284 |
| 280 // Kick off connection. | 285 // Kick off connection. |
| 281 [caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; | 286 [caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; |
| 282 [answerer connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; | 287 [answerer connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; |
| 283 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { | 288 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
| 284 if (error) { | 289 if (error) { |
| 285 NSLog(@"Expectations error: %@", error); | 290 NSLog(@"Expectations error: %@", error); |
| 286 } | 291 } |
| 287 }]; | 292 }]; |
| 288 } | 293 } |
| 289 | 294 |
| 290 @end | 295 @end |
| 291 | 296 |
| 292 @interface ARDSDPUtilsTest : ARDTestCase | 297 @interface ARDSDPUtilsTest : ARDTestCase |
| 293 - (void)testPreferVideoCodec; | 298 - (void)testPreferVideoCodec; |
| 294 @end | 299 @end |
| 295 | 300 |
| 296 @implementation ARDSDPUtilsTest | 301 @implementation ARDSDPUtilsTest |
| 297 | 302 |
| 298 - (void)testPreferVideoCodec { | 303 - (void)testPreferVideoCodec { |
| 299 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" | 304 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" |
| 300 "a=rtpmap:120 H264/90000\n"); | 305 "a=rtpmap:120 H264/90000\n"); |
| 301 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" | 306 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" |
| 302 "a=rtpmap:120 H264/90000\n"); | 307 "a=rtpmap:120 H264/90000\n"); |
| 303 RTCSessionDescription* desc = | 308 RTCSessionDescription* desc = |
| 304 [[RTCSessionDescription alloc] initWithType:@"offer" sdp:sdp]; | 309 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; |
| 305 RTCSessionDescription *h264Desc = | 310 RTCSessionDescription *h264Desc = |
| 306 [ARDSDPUtils descriptionForDescription:desc | 311 [ARDSDPUtils descriptionForDescription:desc |
| 307 preferredVideoCodec:@"H264"]; | 312 preferredVideoCodec:@"H264"]; |
| 308 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); | 313 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); |
| 309 } | 314 } |
| 310 | 315 |
| 311 @end | 316 @end |
| 312 | 317 |
| 313 class SignalingTest : public ::testing::Test { | 318 class SignalingTest : public ::testing::Test { |
| 314 protected: | 319 protected: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 328 } | 333 } |
| 329 | 334 |
| 330 TEST_F(SignalingTest, SDPTest) { | 335 TEST_F(SignalingTest, SDPTest) { |
| 331 @autoreleasepool { | 336 @autoreleasepool { |
| 332 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; | 337 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |
| 333 [test testPreferVideoCodec]; | 338 [test testPreferVideoCodec]; |
| 334 } | 339 } |
| 335 } | 340 } |
| 336 | 341 |
| 337 | 342 |
| OLD | NEW |