GIDFakeSignIn.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "GoogleSignIn/Tests/Unit/GIDFakeSignIn.h"
  15. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
  16. #import "GoogleSignIn/Sources/GIDSignIn_Private.h"
  17. #import <GoogleUtilities/GULSwizzler.h>
  18. #import <GoogleUtilities/GULSwizzler+Unswizzle.h>
  19. static NSString * const kClientId = @"FakeClientID";
  20. static NSString * const kScope = @"FakeScope";
  21. @implementation GIDFakeSignIn
  22. - (instancetype) init {
  23. self = [super initPrivate];
  24. if (self) {
  25. self.clientID = kClientId;
  26. self.scopes = [NSArray arrayWithObject:kScope];
  27. }
  28. return self;
  29. }
  30. - (void)startMocking {
  31. __weak id weakSelf = self;
  32. [GULSwizzler swizzleClass:[GIDSignIn class]
  33. selector:@selector(sharedInstance)
  34. isClassSelector:YES
  35. withBlock:^{ return weakSelf; }];
  36. [[NSNotificationCenter defaultCenter] addObserver:self
  37. selector:@selector(applicationDidBecomeActive:)
  38. name:UIApplicationDidBecomeActiveNotification
  39. object:nil];
  40. }
  41. - (void)stopMocking {
  42. [GULSwizzler unswizzleClass:[GIDSignIn class]
  43. selector:@selector(sharedInstance)
  44. isClassSelector:YES];
  45. [[NSNotificationCenter defaultCenter] removeObserver:self
  46. name:UIApplicationDidBecomeActiveNotification
  47. object:nil];
  48. }
  49. @end