FIRMessagingReceiverTest.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2018 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/OCMock.h>
  18. #import <FirebaseInstanceID/FirebaseInstanceID.h>
  19. #import "FIRMessaging.h"
  20. #import "FIRMessaging_Private.h"
  21. #import "FIRMessagingTestUtilities.h"
  22. NSString *const kFIRMessagingTestsReceiverSuiteName = @"com.messaging.test_receiverTest";
  23. @interface FIRMessagingReceiverTest : XCTestCase
  24. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  25. @end
  26. @implementation FIRMessagingReceiverTest
  27. - (void)setUp {
  28. [super setUp];
  29. NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsReceiverSuiteName];
  30. _messaging = [FIRMessagingTestUtilities messagingForTestsWithUserDefaults:defaults];
  31. }
  32. - (void)tearDown {
  33. [self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingTestsReceiverSuiteName];
  34. _messaging = nil;
  35. [super tearDown];
  36. }
  37. - (void)testUseMessagingDelegate {
  38. #pragma clang diagnostic push
  39. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  40. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  41. _messaging.useMessagingDelegateForDirectChannel = YES;
  42. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  43. }
  44. - (void)testUseMessagingDelegateFlagOverridedByPlistWithFalseValue {
  45. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  46. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  47. .andReturn(nil);
  48. XCTAssertFalse(_messaging.useMessagingDelegateForDirectChannel);
  49. [bundleMock stopMocking];
  50. }
  51. - (void)testUseMessagingDelegateFlagOverridedByPlistWithTrueValue {
  52. id bundleMock = OCMPartialMock([NSBundle mainBundle]);
  53. OCMStub([bundleMock objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate])
  54. .andReturn(@YES);
  55. XCTAssertTrue(_messaging.useMessagingDelegateForDirectChannel);
  56. #pragma clang diagnostic pop
  57. [bundleMock stopMocking];
  58. }
  59. @end