| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- // Copyright 2021 Google LLC
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #import <XCTest/XCTest.h>
- #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
- #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
- #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
- #ifdef SWIFT_PACKAGE
- @import OCMock;
- #else
- #import <OCMock/OCMock.h>
- #endif
- static NSString * const kClientId = @"FakeClientID";
- static NSString * const kOpenIDRealm = @"FakeRealm";
- @interface GIDSignInInternalOptionsTest : XCTestCase
- @end
- @implementation GIDSignInInternalOptionsTest
- #if TARGET_OS_IOS
- - (void)testDefaultOptionsForVerificationFlow {
- GIDConfiguration *configuration = [[GIDConfiguration alloc] initWithClientID:kClientId
- serverClientID:nil
- hostedDomain:nil
- openIDRealm:kOpenIDRealm];
- UIViewController *presentingViewController = [[UIViewController alloc] init];
- GIDVerifiableAccountDetail *ageOver18Detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
- NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify = @[ageOver18Detail];
- NSString *loginHint = @"login_hint";
-
- GIDSignInInternalOptions *options =
- [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
- presentingViewController:presentingViewController
- loginHint:loginHint
- addScopesFlow:YES
- accountDetailsToVerify:accountDetailsToVerify
- verifyCompletion:nil];
- XCTAssertTrue(options.interactive);
- XCTAssertFalse(options.continuation);
- XCTAssertTrue(options.addScopesFlow);
- XCTAssertEqual(options.configuration, configuration);
- XCTAssertEqual(options.presentingViewController, presentingViewController);
- XCTAssertEqual(options.accountDetailsToVerify, accountDetailsToVerify);
- }
- #endif // TARGET_OS_IOS
- - (void)testDefaultOptions {
- id configuration = OCMStrictClassMock([GIDConfiguration class]);
- #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
- id presentingViewController = OCMStrictClassMock([UIViewController class]);
- #elif TARGET_OS_OSX
- id presentingWindow = OCMStrictClassMock([NSWindow class]);
- #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
- NSString *loginHint = @"login_hint";
- GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
- NSError * _Nullable error) {};
- GIDSignInInternalOptions *options =
- [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
- #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
- presentingViewController:presentingViewController
- #elif TARGET_OS_OSX
- presentingWindow:presentingWindow
- #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
- loginHint:loginHint
- addScopesFlow:NO
- completion:completion];
- XCTAssertTrue(options.interactive);
- XCTAssertFalse(options.continuation);
- XCTAssertFalse(options.addScopesFlow);
- XCTAssertNil(options.extraParams);
- OCMVerifyAll(configuration);
- #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
- OCMVerifyAll(presentingViewController);
- #elif TARGET_OS_OSX
- OCMVerifyAll(presentingWindow);
- #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
- }
- - (void)testSilentOptions {
- GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
- NSError * _Nullable error) {};
- GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCompletion:completion];
- XCTAssertFalse(options.interactive);
- XCTAssertFalse(options.continuation);
- XCTAssertNil(options.extraParams);
- XCTAssertEqual(options.completion, completion);
- }
- @end
|