@@ -77,6 +77,7 @@ - (BOOL)setUpWithLaunchOptions:(nullable NSDictionary *)launchOptions
77
77
clientID : (NSString *)clientID
78
78
urlScheme : (nullable NSString *)urlScheme
79
79
userDefaults : (nullable NSUserDefaults *)userDefaults ;
80
+ - (BOOL )canParseUniversalLinkURL : (nullable NSURL *)url ;
80
81
@end
81
82
82
83
@interface FakeShortLinkResolver : FIRDynamicLinkNetworking
@@ -774,13 +775,90 @@ - (void)testUniversalLinkWithSubdomain_DeepLinkWithParameters {
774
775
XCTAssertEqualObjects (dynamicLink.url .absoluteString , parsedDeepLinkString);
775
776
}
776
777
777
- - (void )testMatchesUnversalLinkWithLongDurableLink {
778
- NSString *urlString =
779
- @" https://sample.page.link?link=https://google.com/test&ibi=com.google.sample&ius=79306483" ;
780
- NSURL *url = [NSURL URLWithString: urlString];
781
- BOOL matchesShort = [self .service matchesShortLinkFormat: url];
778
+ - (void )testMatchesShortLinkFormat {
779
+ NSArray <NSString *> *urlStrings =
780
+ @[ @" https://test.app.goo.gl/xyz" , @" https://test.app.goo.gl/xyz?link=" ];
781
+
782
+ for (NSString *urlString in urlStrings) {
783
+ NSURL *url = [NSURL URLWithString: urlString];
784
+ BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
785
+
786
+ XCTAssertTrue (matchesShortLinkFormat,
787
+ @" Non-DDL domain URL matched short link format with URL: %@ " , url);
788
+ }
789
+ }
790
+
791
+ // Custom domain entries in plist file:
792
+ // https://google.com
793
+ // https://google.com/one
794
+ // https://a.firebase.com/mypath
795
+ - (void )testFailMatchesShortLinkFormatForCustomDomains {
796
+ NSArray <NSString *> *urlStrings = @[
797
+ @" https://google.com" ,
798
+ @" https://google.com?link=" ,
799
+ @" https://a.firebase.com" ,
800
+ @" https://a.firebase.com/mypath?link=" ,
801
+ ];
802
+
803
+ for (NSString *urlString in urlStrings) {
804
+ NSURL *url = [NSURL URLWithString: urlString];
805
+ BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
806
+
807
+ XCTAssertFalse (matchesShortLinkFormat,
808
+ @" Non-DDL domain URL matched short link format with URL: %@ " , url);
809
+ }
810
+ }
811
+
812
+ // Custom domain entries in plist file:
813
+ // https://google.com
814
+ // https://google.com/one
815
+ // https://a.firebase.com/mypath
816
+ - (void )testPassMatchesShortLinkFormatForCustomDomains {
817
+ NSArray <NSString *> *urlStrings = @[
818
+ @" https://google.com/xyz" , @" https://google.com/xyz/?link=" , @" https://google.com/xyz?link=" ,
819
+ @" https://google.com/one/xyz" , @" https://google.com/one/xyz?link=" ,
820
+ @" https://google.com/one?utm_campaignlink=" , @" https://google.com/mylink" ,
821
+ @" https://google.com/one/mylink" , @" https://a.firebase.com/mypath/mylink"
822
+ ];
823
+
824
+ for (NSString *urlString in urlStrings) {
825
+ NSURL *url = [NSURL URLWithString: urlString];
826
+ BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
827
+
828
+ XCTAssertTrue (matchesShortLinkFormat,
829
+ @" Non-DDL domain URL matched short link format with URL: %@ " , url);
830
+ }
831
+ }
782
832
783
- XCTAssertFalse (matchesShort, @" Long Durable Link should not match short link format" );
833
+ - (void )testPassMatchesShortLinkFormat {
834
+ NSArray <NSString *> *urlStrings = @[
835
+ @" https://test.app.goo.gl/xyz" ,
836
+ @" https://test.app.goo.gl/xyz?link=" ,
837
+ ];
838
+
839
+ for (NSString *urlString in urlStrings) {
840
+ NSURL *url = [NSURL URLWithString: urlString];
841
+ BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
842
+
843
+ XCTAssertTrue (matchesShortLinkFormat,
844
+ @" Non-DDL domain URL matched short link format with URL: %@ " , url);
845
+ }
846
+ }
847
+
848
+ - (void )testFailMatchesShortLinkFormat {
849
+ NSArray <NSString *> *urlStrings = @[
850
+ @" https://test.app.goo.gl" , @" https://test.app.goo.gl?link=" , @" https://test.app.goo.gl/" ,
851
+ @" https://sample.page.link?link=https://google.com/test&ibi=com.google.sample&ius=79306483"
852
+ @" https://sample.page.link/?link=https://google.com/test&ibi=com.google.sample&ius=79306483"
853
+ ];
854
+
855
+ for (NSString *urlString in urlStrings) {
856
+ NSURL *url = [NSURL URLWithString: urlString];
857
+ BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
858
+
859
+ XCTAssertFalse (matchesShortLinkFormat,
860
+ @" Non-DDL domain URL matched short link format with URL: %@ " , url);
861
+ }
784
862
}
785
863
786
864
- (void )testMatchesUnversalLinkWithShortDurableLink {
@@ -1073,19 +1151,26 @@ - (void)testValidCustomDomainNames {
1073
1151
NSArray <NSString *> *urlStrings = @[
1074
1152
@" https://google.com/mylink" , // Short FDL starting with 'https://google.com'
1075
1153
@" https://google.com/one" , // Short FDL starting with 'https://google.com'
1076
- @" https://google.com/?link=abcd" , // Long FDL starting with 'https://google.com'
1077
- @" https://google.com/one/mylink" , // Long FDL starting with 'https://google.com/one'
1154
+ @" https://google.com/one/mylink" , // Short FDL starting with 'https://google.com/one'
1078
1155
@" https://a.firebase.com/mypath/mylink" , // Short FDL starting https://a.firebase.com/mypath
1156
+ ];
1157
+
1158
+ NSArray <NSString *> *longFDLURLStrings = @[
1079
1159
@" https://a.firebase.com/mypath/?link=abcd&test=1" , // Long FDL starting with
1080
1160
// https://a.firebase.com/mypath
1161
+ @" https://google.com/?link=abcd" , // Long FDL starting with 'https://google.com'
1081
1162
];
1082
-
1083
1163
for (NSString *urlString in urlStrings) {
1084
1164
NSURL *url = [NSURL URLWithString: urlString];
1085
1165
BOOL matchesShortLinkFormat = [self .service matchesShortLinkFormat: url];
1086
1166
1087
- XCTAssertTrue (matchesShortLinkFormat,
1088
- @" Non-DDL domain URL matched short link format with URL: %@ " , url);
1167
+ XCTAssertTrue (matchesShortLinkFormat, @" URL did not validate as short link: %@ " , url);
1168
+ }
1169
+ for (NSString *urlString in longFDLURLStrings) {
1170
+ NSURL *url = [NSURL URLWithString: urlString];
1171
+ BOOL matchesLongLinkFormat = [self .service canParseUniversalLinkURL: url];
1172
+
1173
+ XCTAssertTrue (matchesLongLinkFormat, @" URL did not validate as long link: %@ " , url);
1089
1174
}
1090
1175
}
1091
1176
0 commit comments