diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/examples/objc/AppRTCMobile/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/examples/objc/AppRTCMobile/tests')
4 files changed, 445 insertions, 0 deletions
diff --git a/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm new file mode 100644 index 0000000000..2694e49914 --- /dev/null +++ b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm @@ -0,0 +1,266 @@ +/* + * Copyright 2014 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#import <OCMock/OCMock.h> +#import <QuartzCore/CoreAnimation.h> +#import <XCTest/XCTest.h> + +#include "rtc_base/ssl_adapter.h" + +#import "sdk/objc/api/peerconnection/RTCMediaConstraints.h" +#import "sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h" + +#import "ARDAppClient+Internal.h" +#import "ARDJoinResponse+Internal.h" +#import "ARDMessageResponse+Internal.h" +#import "ARDSettingsModel.h" + +@interface ARDAppClientTest : XCTestCase +@end + +@implementation ARDAppClientTest + +#pragma mark - Mock helpers + +- (id)mockRoomServerClientForRoomId:(NSString *)roomId + clientId:(NSString *)clientId + isInitiator:(BOOL)isInitiator + messages:(NSArray *)messages + messageHandler: + (void (^)(ARDSignalingMessage *))messageHandler { + id mockRoomServerClient = + [OCMockObject mockForProtocol:@protocol(ARDRoomServerClient)]; + + // Successful join response. + ARDJoinResponse *joinResponse = [[ARDJoinResponse alloc] init]; + joinResponse.result = kARDJoinResultTypeSuccess; + joinResponse.roomId = roomId; + joinResponse.clientId = clientId; + joinResponse.isInitiator = isInitiator; + joinResponse.messages = messages; + + // Successful message response. + ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init]; + messageResponse.result = kARDMessageResultTypeSuccess; + + // Return join response from above on join. + [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { + __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, + NSError *error); + [invocation getArgument:&completionHandler atIndex:4]; + completionHandler(joinResponse, nil); + }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; + + // Return message response from above on join. + [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { + __unsafe_unretained ARDSignalingMessage *message; + __unsafe_unretained void (^completionHandler)(ARDMessageResponse *response, + NSError *error); + [invocation getArgument:&message atIndex:2]; + [invocation getArgument:&completionHandler atIndex:5]; + messageHandler(message); + completionHandler(messageResponse, nil); + }] sendMessage:[OCMArg any] + forRoomId:roomId + clientId:clientId + completionHandler:[OCMArg any]]; + + // Do nothing on leave. + [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { + __unsafe_unretained void (^completionHandler)(NSError *error); + [invocation getArgument:&completionHandler atIndex:4]; + if (completionHandler) { + completionHandler(nil); + } + }] leaveRoomWithRoomId:roomId + clientId:clientId + completionHandler:[OCMArg any]]; + + return mockRoomServerClient; +} + +- (id)mockSignalingChannelForRoomId:(NSString *)roomId + clientId:(NSString *)clientId + messageHandler: + (void (^)(ARDSignalingMessage *message))messageHandler { + id mockSignalingChannel = + [OCMockObject niceMockForProtocol:@protocol(ARDSignalingChannel)]; + [[mockSignalingChannel stub] registerForRoomId:roomId clientId:clientId]; + [[[mockSignalingChannel stub] andDo:^(NSInvocation *invocation) { + __unsafe_unretained ARDSignalingMessage *message; + [invocation getArgument:&message atIndex:2]; + messageHandler(message); + }] sendMessage:[OCMArg any]]; + return mockSignalingChannel; +} + +- (id)mockTURNClient { + id mockTURNClient = + [OCMockObject mockForProtocol:@protocol(ARDTURNClient)]; + [[[mockTURNClient stub] andDo:^(NSInvocation *invocation) { + // Don't return anything in TURN response. + __unsafe_unretained void (^completionHandler)(NSArray *turnServers, + NSError *error); + [invocation getArgument:&completionHandler atIndex:2]; + completionHandler([NSArray array], nil); + }] requestServersWithCompletionHandler:[OCMArg any]]; + return mockTURNClient; +} + +- (id)mockSettingsModel { + ARDSettingsModel *model = [[ARDSettingsModel alloc] init]; + id partialMock = [OCMockObject partialMockForObject:model]; + [[[partialMock stub] andReturn:@[ @"640x480", @"960x540", @"1280x720" ]] + availableVideoResolutions]; + + return model; +} + +- (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId + clientId:(NSString *)clientId + isInitiator:(BOOL)isInitiator + messages:(NSArray *)messages + messageHandler: + (void (^)(ARDSignalingMessage *message))messageHandler + connectedHandler:(void (^)(void))connectedHandler + localVideoTrackHandler:(void (^)(void))localVideoTrackHandler { + id turnClient = [self mockTURNClient]; + id signalingChannel = [self mockSignalingChannelForRoomId:roomId + clientId:clientId + messageHandler:messageHandler]; + id roomServerClient = + [self mockRoomServerClientForRoomId:roomId + clientId:clientId + isInitiator:isInitiator + messages:messages + messageHandler:messageHandler]; + id delegate = + [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; + [[[delegate stub] andDo:^(NSInvocation *invocation) { + connectedHandler(); + }] appClient:[OCMArg any] + didChangeConnectionState:RTCIceConnectionStateConnected]; + [[[delegate stub] andDo:^(NSInvocation *invocation) { + localVideoTrackHandler(); + }] appClient:[OCMArg any] + didReceiveLocalVideoTrack:[OCMArg any]]; + + return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient + signalingChannel:signalingChannel + turnClient:turnClient + delegate:delegate]; +} + +#pragma mark - Cases + +// Tests that an ICE connection is established between two ARDAppClient objects +// where one is set up as a caller and the other the answerer. Network +// components are mocked out and messages are relayed directly from object to +// object. It's expected that both clients reach the +// RTCIceConnectionStateConnected state within a reasonable amount of time. +- (void)testSession { + // Need block arguments here because we're setting up a callbacks before we + // create the clients. + ARDAppClient *caller = nil; + ARDAppClient *answerer = nil; + __block __weak ARDAppClient *weakCaller = nil; + __block __weak ARDAppClient *weakAnswerer = nil; + NSString *roomId = @"testRoom"; + NSString *callerId = @"testCallerId"; + NSString *answererId = @"testAnswererId"; + + XCTestExpectation *callerConnectionExpectation = + [self expectationWithDescription:@"Caller PC connected"]; + XCTestExpectation *answererConnectionExpectation = + [self expectationWithDescription:@"Answerer PC connected"]; + + caller = [self createAppClientForRoomId:roomId + clientId:callerId + isInitiator:YES + messages:[NSArray array] + messageHandler:^(ARDSignalingMessage *message) { + ARDAppClient *strongAnswerer = weakAnswerer; + [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; + } connectedHandler:^{ + [callerConnectionExpectation fulfill]; + } localVideoTrackHandler:^{ + }]; + // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion + // crash in Debug. + caller.defaultPeerConnectionConstraints = + [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:nil + optionalConstraints:nil]; + weakCaller = caller; + + answerer = [self createAppClientForRoomId:roomId + clientId:answererId + isInitiator:NO + messages:[NSArray array] + messageHandler:^(ARDSignalingMessage *message) { + ARDAppClient *strongCaller = weakCaller; + [strongCaller channel:strongCaller.channel didReceiveMessage:message]; + } connectedHandler:^{ + [answererConnectionExpectation fulfill]; + } localVideoTrackHandler:^{ + }]; + // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion + // crash in Debug. + answerer.defaultPeerConnectionConstraints = + [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:nil + optionalConstraints:nil]; + weakAnswerer = answerer; + + // Kick off connection. + [caller connectToRoomWithId:roomId settings:[self mockSettingsModel] isLoopback:NO]; + [answerer connectToRoomWithId:roomId settings:[self mockSettingsModel] isLoopback:NO]; + [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { + if (error) { + XCTFail(@"Expectation failed with error %@.", error); + } + }]; +} + +// 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...) +#if !TARGET_IPHONE_SIMULATOR // Expect to fail on simulator due to no camera support +- (void)testSessionShouldGetLocalVideoTrackCallback { + ARDAppClient *caller = nil; + NSString *roomId = @"testRoom"; + NSString *callerId = @"testCallerId"; + + XCTestExpectation *localVideoTrackExpectation = + [self expectationWithDescription:@"Caller got local video."]; + + caller = [self createAppClientForRoomId:roomId + clientId:callerId + isInitiator:YES + messages:[NSArray array] + messageHandler:^(ARDSignalingMessage *message) {} + connectedHandler:^{} + localVideoTrackHandler:^{ [localVideoTrackExpectation fulfill]; }]; + caller.defaultPeerConnectionConstraints = + [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:nil + optionalConstraints:nil]; + + // Kick off connection. + [caller connectToRoomWithId:roomId + settings:[self mockSettingsModel] + isLoopback:NO]; + [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { + if (error) { + XCTFail("Expectation timed out with error: %@.", error); + } + }]; +} +#endif + +@end diff --git a/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDFileCaptureController_xctest.mm b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDFileCaptureController_xctest.mm new file mode 100644 index 0000000000..2e39834190 --- /dev/null +++ b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDFileCaptureController_xctest.mm @@ -0,0 +1,62 @@ +/* + * Copyright 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#import <OCMock/OCMock.h> +#import <XCTest/XCTest.h> + +#import "ARDFileCaptureController.h" + +#import "sdk/objc/components/capturer/RTCFileVideoCapturer.h" + +NS_CLASS_AVAILABLE_IOS(10) +@interface ARDFileCaptureControllerTests : XCTestCase + +@property(nonatomic, strong) ARDFileCaptureController *fileCaptureController; +@property(nonatomic, strong) id fileCapturerMock; + +@end + +@implementation ARDFileCaptureControllerTests + +@synthesize fileCaptureController = _fileCaptureController; +@synthesize fileCapturerMock = _fileCapturerMock; + +- (void)setUp { + [super setUp]; + self.fileCapturerMock = OCMClassMock([RTC_OBJC_TYPE(RTCFileVideoCapturer) class]); + self.fileCaptureController = + [[ARDFileCaptureController alloc] initWithCapturer:self.fileCapturerMock]; +} + +- (void)tearDown { + self.fileCaptureController = nil; + [self.fileCapturerMock stopMocking]; + self.fileCapturerMock = nil; + [super tearDown]; +} + +- (void)testCaptureIsStarted { + [[self.fileCapturerMock expect] startCapturingFromFileNamed:[OCMArg any] onError:[OCMArg any]]; + + [self.fileCaptureController startCapture]; + + [self.fileCapturerMock verify]; +} + +- (void)testCaptureIsStoped { + [[self.fileCapturerMock expect] stopCapture]; + + [self.fileCaptureController stopCapture]; + + [self.fileCapturerMock verify]; +} + +@end diff --git a/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDSettingsModel_xctest.mm b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDSettingsModel_xctest.mm new file mode 100644 index 0000000000..dc62798963 --- /dev/null +++ b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/ARDSettingsModel_xctest.mm @@ -0,0 +1,96 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <Foundation/Foundation.h> +#import <OCMock/OCMock.h> +#import <XCTest/XCTest.h> + +#import "sdk/objc/api/peerconnection/RTCMediaConstraints.h" + +#import "ARDSettingsModel+Private.h" +#import "ARDSettingsStore.h" + + +@interface ARDSettingsModelTests : XCTestCase { + ARDSettingsModel *_model; +} +@end + +@implementation ARDSettingsModelTests + +- (id)setupMockStore { + id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; + + id partialMock = [OCMockObject partialMockForObject:_model]; + [[[partialMock stub] andReturn:storeMock] settingsStore]; + [[[partialMock stub] andReturn:@[ @"640x480", @"960x540", @"1280x720" ]] + availableVideoResolutions]; + + return storeMock; +} + +- (void)setUp { + _model = [[ARDSettingsModel alloc] init]; +} + +- (void)testRetrievingSetting { + id storeMock = [self setupMockStore]; + [[[storeMock expect] andReturn:@"640x480"] videoResolution]; + NSString *string = [_model currentVideoResolutionSettingFromStore]; + + XCTAssertEqualObjects(string, @"640x480"); +} + +- (void)testStoringInvalidConstraintReturnsNo { + id storeMock = [self setupMockStore]; + [([[storeMock stub] andReturn:@"960x480"])videoResolution]; + XCTAssertFalse([_model storeVideoResolutionSetting:@"960x480"]); +} + +- (void)testWidthConstraintFromStore { + id storeMock = [self setupMockStore]; + [([[storeMock stub] andReturn:@"1270x480"])videoResolution]; + int width = [_model currentVideoResolutionWidthFromStore]; + + XCTAssertEqual(width, 1270); +} + +- (void)testHeightConstraintFromStore { + id storeMock = [self setupMockStore]; + [([[storeMock stub] andReturn:@"960x540"])videoResolution]; + int height = [_model currentVideoResolutionHeightFromStore]; + + XCTAssertEqual(height, 540); +} + +- (void)testConstraintComponentIsNilWhenInvalidConstraintString { + id storeMock = [self setupMockStore]; + [([[storeMock stub] andReturn:@"invalid"])videoResolution]; + int width = [_model currentVideoResolutionWidthFromStore]; + + XCTAssertEqual(width, 0); +} + +- (void)testStoringAudioSetting { + id storeMock = [self setupMockStore]; + [[storeMock expect] setAudioOnly:YES]; + + [_model storeAudioOnlySetting:YES]; + [storeMock verify]; +} + +- (void)testReturningDefaultCallOption { + id storeMock = [self setupMockStore]; + [[[storeMock stub] andReturnValue:@YES] useManualAudioConfig]; + + XCTAssertTrue([_model currentUseManualAudioConfigSettingFromStore]); +} + +@end diff --git a/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/main.mm b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/main.mm new file mode 100644 index 0000000000..3625ffd7bf --- /dev/null +++ b/third_party/libwebrtc/examples/objc/AppRTCMobile/tests/main.mm @@ -0,0 +1,21 @@ +/* + * Copyright 2018 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import <UIKit/UIKit.h> + +#include "test/ios/coverage_util_ios.h" + +int main(int argc, char* argv[]) { + rtc::test::ConfigureCoverageReportPath(); + + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, nil); + } +} |