GIDSignInInternalOptionsTest.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <XCTest/XCTest.h>
  15. #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
  16. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
  18. #ifdef SWIFT_PACKAGE
  19. @import OCMock;
  20. #else
  21. #import <OCMock/OCMock.h>
  22. #endif
  23. static NSString * const kClientId = @"FakeClientID";
  24. static NSString * const kOpenIDRealm = @"FakeRealm";
  25. @interface GIDSignInInternalOptionsTest : XCTestCase
  26. @end
  27. @implementation GIDSignInInternalOptionsTest
  28. #if TARGET_OS_IOS
  29. - (void)testDefaultOptionsForVerificationFlow {
  30. GIDConfiguration *configuration = [[GIDConfiguration alloc] initWithClientID:kClientId
  31. serverClientID:nil
  32. hostedDomain:nil
  33. openIDRealm:kOpenIDRealm];
  34. UIViewController *presentingViewController = [[UIViewController alloc] init];
  35. GIDVerifiableAccountDetail *ageOver18Detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
  36. NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify = @[ageOver18Detail];
  37. NSString *loginHint = @"login_hint";
  38. GIDSignInInternalOptions *options =
  39. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  40. presentingViewController:presentingViewController
  41. loginHint:loginHint
  42. addScopesFlow:YES
  43. accountDetailsToVerify:accountDetailsToVerify
  44. verifyCompletion:nil];
  45. XCTAssertTrue(options.interactive);
  46. XCTAssertFalse(options.continuation);
  47. XCTAssertTrue(options.addScopesFlow);
  48. XCTAssertEqual(options.configuration, configuration);
  49. XCTAssertEqual(options.presentingViewController, presentingViewController);
  50. XCTAssertEqual(options.accountDetailsToVerify, accountDetailsToVerify);
  51. }
  52. #endif // TARGET_OS_IOS
  53. - (void)testDefaultOptions {
  54. id configuration = OCMStrictClassMock([GIDConfiguration class]);
  55. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  56. id presentingViewController = OCMStrictClassMock([UIViewController class]);
  57. #elif TARGET_OS_OSX
  58. id presentingWindow = OCMStrictClassMock([NSWindow class]);
  59. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  60. NSString *loginHint = @"login_hint";
  61. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  62. NSError * _Nullable error) {};
  63. GIDSignInInternalOptions *options =
  64. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  65. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  66. presentingViewController:presentingViewController
  67. #elif TARGET_OS_OSX
  68. presentingWindow:presentingWindow
  69. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  70. loginHint:loginHint
  71. addScopesFlow:NO
  72. completion:completion];
  73. XCTAssertTrue(options.interactive);
  74. XCTAssertFalse(options.continuation);
  75. XCTAssertFalse(options.addScopesFlow);
  76. XCTAssertNil(options.extraParams);
  77. OCMVerifyAll(configuration);
  78. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  79. OCMVerifyAll(presentingViewController);
  80. #elif TARGET_OS_OSX
  81. OCMVerifyAll(presentingWindow);
  82. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  83. }
  84. - (void)testSilentOptions {
  85. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  86. NSError * _Nullable error) {};
  87. GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCompletion:completion];
  88. XCTAssertFalse(options.interactive);
  89. XCTAssertFalse(options.continuation);
  90. XCTAssertNil(options.extraParams);
  91. XCTAssertEqual(options.completion, completion);
  92. }
  93. @end