GIDSignInInternalOptionsTest.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/GIDTokenClaim.h"
  18. #ifdef SWIFT_PACKAGE
  19. @import OCMock;
  20. #else
  21. #import <OCMock/OCMock.h>
  22. #endif
  23. @interface GIDSignInInternalOptionsTest : XCTestCase
  24. @end
  25. @implementation GIDSignInInternalOptionsTest
  26. - (void)testDefaultOptions {
  27. id configuration = OCMStrictClassMock([GIDConfiguration class]);
  28. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  29. id presentingViewController = OCMStrictClassMock([UIViewController class]);
  30. #elif TARGET_OS_OSX
  31. id presentingWindow = OCMStrictClassMock([NSWindow class]);
  32. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  33. NSString *loginHint = @"login_hint";
  34. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  35. NSError * _Nullable error) {};
  36. GIDSignInInternalOptions *options =
  37. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  38. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  39. presentingViewController:presentingViewController
  40. #elif TARGET_OS_OSX
  41. presentingWindow:presentingWindow
  42. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  43. loginHint:loginHint
  44. addScopesFlow:NO
  45. completion:completion];
  46. XCTAssertTrue(options.interactive);
  47. XCTAssertFalse(options.continuation);
  48. XCTAssertFalse(options.addScopesFlow);
  49. XCTAssertNil(options.extraParams);
  50. OCMVerifyAll(configuration);
  51. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  52. OCMVerifyAll(presentingViewController);
  53. #elif TARGET_OS_OSX
  54. OCMVerifyAll(presentingWindow);
  55. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  56. }
  57. - (void)testAdvanceDefaultOptions {
  58. id configuration = OCMStrictClassMock([GIDConfiguration class]);
  59. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  60. id presentingViewController = OCMStrictClassMock([UIViewController class]);
  61. #elif TARGET_OS_OSX
  62. id presentingWindow = OCMStrictClassMock([NSWindow class]);
  63. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  64. NSString *loginHint = @"login_hint";
  65. NSArray<NSString *> *scopes = @[@"scope1", @"scope2"];
  66. NSString *nonce = @"test_nonce";
  67. NSSet<GIDTokenClaim *> *tokenClaims = [NSSet setWithObject:[GIDTokenClaim authTimeClaim]];
  68. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  69. NSError * _Nullable error) {};
  70. GIDSignInInternalOptions *options =
  71. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  72. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  73. presentingViewController:presentingViewController
  74. #elif TARGET_OS_OSX
  75. presentingWindow:presentingWindow
  76. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  77. loginHint:loginHint
  78. addScopesFlow:NO
  79. scopes:scopes
  80. nonce:nonce
  81. tokenClaims:tokenClaims
  82. completion:completion];
  83. XCTAssertTrue(options.interactive);
  84. XCTAssertFalse(options.continuation);
  85. XCTAssertFalse(options.addScopesFlow);
  86. XCTAssertNil(options.extraParams);
  87. XCTAssertTrue(options.scopes);
  88. XCTAssertTrue(options.nonce);
  89. XCTAssertTrue(options.tokenClaims);
  90. XCTAssertFalse(options.tokenClaimsAsJSON);
  91. OCMVerifyAll(configuration);
  92. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  93. OCMVerifyAll(presentingViewController);
  94. #elif TARGET_OS_OSX
  95. OCMVerifyAll(presentingWindow);
  96. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  97. }
  98. - (void)testSilentOptions {
  99. GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,
  100. NSError * _Nullable error) {};
  101. GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCompletion:completion];
  102. XCTAssertFalse(options.interactive);
  103. XCTAssertFalse(options.continuation);
  104. XCTAssertNil(options.extraParams);
  105. XCTAssertEqual(options.completion, completion);
  106. }
  107. @end