FIRMessagingLinkHandlingTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2017 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 <GoogleUtilities/GULUserDefaults.h>
  19. #import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
  20. #import "FirebaseMessaging/Sources/Public/FirebaseMessaging/FIRMessaging.h"
  21. #import "FirebaseMessaging/Tests/UnitTests/FIRMessagingTestNotificationUtilities.h"
  22. #import "FirebaseMessaging/Tests/UnitTests/FIRMessagingTestUtilities.h"
  23. NSString *const kFIRMessagingTestsLinkHandlingSuiteName = @"com.messaging.test_linkhandling";
  24. @interface FIRMessaging ()
  25. - (NSURL *)linkURLFromMessage:(NSDictionary *)message;
  26. @end
  27. @interface FIRMessagingLinkHandlingTest : XCTestCase
  28. @property(nonatomic, readonly, strong) FIRMessaging *messaging;
  29. @property(nonatomic, strong) FIRMessagingTestUtilities *testUtil;
  30. @end
  31. @implementation FIRMessagingLinkHandlingTest
  32. - (void)setUp {
  33. [super setUp];
  34. NSUserDefaults *defaults =
  35. [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsLinkHandlingSuiteName];
  36. _testUtil = [[FIRMessagingTestUtilities alloc] initWithUserDefaults:defaults withRMQManager:NO];
  37. _messaging = _testUtil.messaging;
  38. }
  39. - (void)tearDown {
  40. [_testUtil cleanupAfterTest:self];
  41. _messaging = nil;
  42. [[[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingTestsLinkHandlingSuiteName]
  43. removePersistentDomainForName:kFIRMessagingTestsLinkHandlingSuiteName];
  44. [super tearDown];
  45. }
  46. #pragma mark - Link Handling Testing
  47. - (void)testNonExistentLinkInMessage {
  48. NSMutableDictionary *notification =
  49. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  50. NSURL *url = [_messaging linkURLFromMessage:notification];
  51. XCTAssertNil(url);
  52. }
  53. - (void)testEmptyLinkInMessage {
  54. NSMutableDictionary *notification =
  55. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  56. notification[kFIRMessagingMessageLinkKey] = @"";
  57. NSURL *url = [_messaging linkURLFromMessage:notification];
  58. XCTAssertNil(url);
  59. }
  60. - (void)testNonStringLinkInMessage {
  61. NSMutableDictionary *notification =
  62. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  63. notification[kFIRMessagingMessageLinkKey] = @(5);
  64. NSURL *url = [_messaging linkURLFromMessage:notification];
  65. XCTAssertNil(url);
  66. }
  67. - (void)testValidURLStringLinkInMessage {
  68. NSMutableDictionary *notification =
  69. [FIRMessagingTestNotificationUtilities createBasicNotificationWithUniqueMessageID];
  70. notification[kFIRMessagingMessageLinkKey] = @"https://www.google.com/";
  71. NSURL *url = [_messaging linkURLFromMessage:notification];
  72. XCTAssertTrue([url.absoluteString isEqualToString:@"https://www.google.com/"]);
  73. }
  74. @end