GIDSignInInternalOptionsTest.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 && !TARGET_OS_MACCATALYST
  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 *testAccountDetail =
  36. [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];
  37. NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify = @[testAccountDetail];
  38. NSString *loginHint = @"login_hint";
  39. GIDSignInInternalOptions *options =
  40. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  41. presentingViewController:presentingViewController
  42. loginHint:loginHint
  43. addScopesFlow:YES
  44. accountDetailsToVerify:accountDetailsToVerify
  45. verifyCompletion:nil];
  46. XCTAssertTrue(options.interactive);
  47. XCTAssertFalse(options.continuation);
  48. XCTAssertTrue(options.addScopesFlow);
  49. XCTAssertEqual(options.configuration, configuration);
  50. XCTAssertEqual(options.presentingViewController, presentingViewController);
  51. XCTAssertEqual(options.accountDetailsToVerify, accountDetailsToVerify);
  52. }
  53. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  54. - (void)testDefaultOptions {
  55. id configuration = OCMStrictClassMock([GIDConfiguration class]);
  56. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  57. id presentingViewController = OCMStrictClassMock([UIViewController class]);
  58. #elif TARGET_OS_OSX
  59. id presentingWindow = OCMStrictClassMock([NSWindow class]);
  60. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  61. NSString *loginHint = @"login_hint";
  62. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  63. NSError * _Nullable error) {};
  64. GIDSignInInternalOptions *options =
  65. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  66. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  67. presentingViewController:presentingViewController
  68. #elif TARGET_OS_OSX
  69. presentingWindow:presentingWindow
  70. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  71. loginHint:loginHint
  72. addScopesFlow:NO
  73. completion:completion];
  74. XCTAssertTrue(options.interactive);
  75. XCTAssertFalse(options.continuation);
  76. XCTAssertFalse(options.addScopesFlow);
  77. XCTAssertNil(options.extraParams);
  78. OCMVerifyAll(configuration);
  79. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  80. OCMVerifyAll(presentingViewController);
  81. #elif TARGET_OS_OSX
  82. OCMVerifyAll(presentingWindow);
  83. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  84. }
  85. - (void)testSilentOptions {
  86. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  87. NSError * _Nullable error) {};
  88. GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCompletion:completion];
  89. XCTAssertFalse(options.interactive);
  90. XCTAssertFalse(options.continuation);
  91. XCTAssertNil(options.extraParams);
  92. XCTAssertEqual(options.completion, completion);
  93. }
  94. @end