FIRInstanceIDWithFCMTest.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <OCMock/OCMock.h>
  17. #import <XCTest/XCTest.h>
  18. #import <FirebaseCore/FIRAppInternal.h>
  19. #import <FirebaseInstanceID/FirebaseInstanceID.h>
  20. #import <GoogleUtilities/GULUserDefaults.h>
  21. #import <FirebaseMessaging/FIRMessaging.h>
  22. #import "Example/Messaging/Tests/FIRMessagingTestUtilities.h"
  23. #import "Firebase/Messaging/FIRMessaging_Private.h"
  24. @interface FIRInstanceID (ExposedForTest)
  25. - (BOOL)isFCMAutoInitEnabled;
  26. - (instancetype)initPrivately;
  27. @end
  28. @interface FIRInstanceIDTest : XCTestCase
  29. @property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
  30. @property(nonatomic, readwrite, strong) id mockFirebaseApp;
  31. @property(nonatomic, readwrite, strong) FIRMessagingTestUtilities *testUtil;
  32. @property(nonatomic, strong) FIRMessaging *messaging;
  33. @end
  34. @implementation FIRInstanceIDTest
  35. - (void)setUp {
  36. [super setUp];
  37. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  38. _testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
  39. _instanceID = _testUtil.instanceID;
  40. _messaging = _testUtil.messaging;
  41. _mockFirebaseApp = OCMClassMock([FIRApp class]);
  42. OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
  43. }
  44. - (void)tearDown {
  45. [_testUtil cleanupAfterTest:self];
  46. _instanceID = nil;
  47. _messaging = nil;
  48. [_mockFirebaseApp stopMocking];
  49. [super tearDown];
  50. }
  51. - (void)testFCMAutoInitEnabled {
  52. OCMStub([_mockFirebaseApp isDataCollectionDefaultEnabled]).andReturn(YES);
  53. _messaging.autoInitEnabled = YES;
  54. XCTAssertTrue(
  55. [_instanceID isFCMAutoInitEnabled],
  56. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  57. _messaging.autoInitEnabled = NO;
  58. XCTAssertFalse(
  59. [_instanceID isFCMAutoInitEnabled],
  60. @"When FCM is available, FCM Auto Init Enabled should be FCM's autoInitEnable property.");
  61. _messaging.autoInitEnabled = YES;
  62. XCTAssertTrue([_instanceID isFCMAutoInitEnabled]);
  63. }
  64. @end