FIRInstanceIDWithFCMTest.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "OCMock.h"
  18. #import <GoogleUtilities/GULUserDefaults.h>
  19. #import "Firebase/InstanceID/Public/FirebaseInstanceID.h"
  20. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  21. #import "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h"
  22. #import "FirebaseMessaging/Sources/FIRMessaging_Private.h"
  23. #import "FirebaseMessaging/Tests/UnitTests/FIRMessagingTestUtilities.h"
  24. @interface FIRInstanceID (ExposedForTest)
  25. - (BOOL)isFCMAutoInitEnabled;
  26. - (instancetype)initPrivately;
  27. @end
  28. @interface FIRInstanceIDTest : XCTestCase
  29. #pragma clang diagnostic push
  30. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  31. @property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
  32. #pragma clang diagnostic pop
  33. @property(nonatomic, readwrite, strong) id mockFirebaseApp;
  34. @property(nonatomic, readwrite, strong) FIRMessagingTestUtilities *testUtil;
  35. @property(nonatomic, strong) FIRMessaging *messaging;
  36. @end
  37. @implementation FIRInstanceIDTest
  38. - (void)setUp {
  39. [super setUp];
  40. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  41. _testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
  42. _instanceID = _testUtil.instanceID;
  43. _messaging = _testUtil.messaging;
  44. _mockFirebaseApp = OCMClassMock([FIRApp class]);
  45. OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
  46. }
  47. - (void)tearDown {
  48. [_testUtil cleanupAfterTest:self];
  49. _instanceID = nil;
  50. _messaging = nil;
  51. [_mockFirebaseApp stopMocking];
  52. [super tearDown];
  53. }
  54. - (void)testFCMAutoInitEnabled {
  55. OCMStub([_mockFirebaseApp isDataCollectionDefaultEnabled]).andReturn(YES);
  56. _messaging.autoInitEnabled = YES;
  57. XCTAssertTrue(
  58. [_instanceID isFCMAutoInitEnabled],
  59. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  60. _messaging.autoInitEnabled = NO;
  61. XCTAssertFalse(
  62. [_instanceID isFCMAutoInitEnabled],
  63. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  64. _messaging.autoInitEnabled = YES;
  65. XCTAssertTrue([_instanceID isFCMAutoInitEnabled]);
  66. }
  67. @end