FIRInstanceIDWithFCMTest.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <FirebaseMessaging/FIRMessaging.h>
  21. #import "Firebase/Messaging/FIRMessaging_Private.h"
  22. #import "Example/Messaging/Tests/FIRMessagingTestUtilities.h"
  23. @interface FIRInstanceID (ExposedForTest)
  24. - (BOOL)isFCMAutoInitEnabled;
  25. - (instancetype)initPrivately;
  26. - (void)start;
  27. @end
  28. @interface FIRMessaging (ExposedForTest)
  29. @property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
  30. + (FIRMessaging *)messagingForTests;
  31. @end
  32. @interface FIRInstanceIDTest : XCTestCase
  33. @property(nonatomic, readwrite, strong) FIRInstanceID *instanceID;
  34. @property(nonatomic, readwrite, strong) id mockFirebaseApp;
  35. @end
  36. @implementation FIRInstanceIDTest
  37. - (void)setUp {
  38. [super setUp];
  39. _mockFirebaseApp = OCMClassMock([FIRApp class]);
  40. OCMStub([_mockFirebaseApp defaultApp]).andReturn(_mockFirebaseApp);
  41. }
  42. - (void)tearDown {
  43. self.instanceID = nil;
  44. [_mockFirebaseApp stopMocking];
  45. [super tearDown];
  46. }
  47. // TODO: Disabled until #4198 is fixed.
  48. - (void)DISABLED_testFCMAutoInitEnabled {
  49. // Use the standardUserDefaults since that's what IID expects and depends on.
  50. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  51. FIRMessaging *messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
  52. OCMStub([_mockFirebaseApp isDataCollectionDefaultEnabled]).andReturn(YES);
  53. messaging.autoInitEnabled = YES;
  54. XCTAssertTrue(
  55. [messaging.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([messaging.instanceID isFCMAutoInitEnabled]);
  63. }
  64. @end