FIRMessagingLinkHandlingTest.m 3.1 KB

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