@@ -99,6 +99,7 @@ class SpecialUrlDetectorImplTest {
99
99
whenever(mockAIChatQueryDetectionFeatureToggle.isEnabled()).thenReturn(false )
100
100
whenever(mockAIChatQueryDetectionFeature.self()).thenReturn(mockAIChatQueryDetectionFeatureToggle)
101
101
androidBrowserConfigFeature.handleIntentScheme().setRawStoredState(State (true ))
102
+ androidBrowserConfigFeature.validateIntentResolution().setRawStoredState(State (true ))
102
103
}
103
104
104
105
@Test
@@ -293,21 +294,64 @@ class SpecialUrlDetectorImplTest {
293
294
@Test
294
295
fun whenUrlIsCustomUriSchemeThenNonHttpAppLinkTypeDetectedWithAdditionalIntentFlags () {
295
296
externalAppIntentFlagsFeature.self().setRawStoredState(State (true ))
297
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
296
298
val type = testee.determineType(" myapp:foo bar" ) as NonHttpAppLink
297
299
assertEquals(" myapp:foo bar" , type.uriString)
298
300
assertEquals(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TOP , type.intent.flags)
299
301
assertEquals(Intent .CATEGORY_BROWSABLE , type.intent.categories.first())
300
302
}
301
303
304
+ @Test
305
+ fun whenUrlIsCustomUriSchemeAndRedirectThenNonHttpAppLinkTypeDetectedWithAdditionalIntentFlags () {
306
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (true ))
307
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
308
+ val actual = testee.determineType(" https://www.example.com" , " myapp:foo bar" .toUri()) as NonHttpAppLink
309
+ assertEquals(" myapp:foo bar" , actual.uriString)
310
+ assertEquals(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TOP , actual.intent.flags)
311
+ assertEquals(Intent .CATEGORY_BROWSABLE , actual.intent.categories.first())
312
+ }
313
+
314
+ @Test
315
+ fun whenUrlIsCustomUriSchemeAndNoResolveInfoThenUnknownTypeDetected () {
316
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (true ))
317
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(null )
318
+ val expected = Unknown ::class
319
+ val actual = testee.determineType(" myapp:foo bar" )
320
+ assertEquals(expected, actual::class )
321
+ }
322
+
323
+ @Test
324
+ fun whenUrlIsCustomUriSchemeAndNoResolveInfoAndRedirectThenNonHttpAppLinkDetected () {
325
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (true ))
326
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(null )
327
+ val expected = NonHttpAppLink ::class
328
+ val actual = testee.determineType(" https://www.example.com" , " myapp:foo bar" .toUri()) as NonHttpAppLink
329
+ assertEquals(expected, actual::class )
330
+ assertEquals(" myapp:foo bar" , actual.uriString)
331
+ assertEquals(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TOP , actual.intent.flags)
332
+ assertEquals(Intent .CATEGORY_BROWSABLE , actual.intent.categories.first())
333
+ }
334
+
302
335
@Test
303
336
fun whenUrlIsCustomUriSchemeThenNonHttpAppLinkTypeDetectedWithoutAdditionalIntentFlags () {
304
337
externalAppIntentFlagsFeature.self().setRawStoredState(State (false ))
338
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
305
339
val type = testee.determineType(" myapp:foo bar" ) as NonHttpAppLink
306
340
assertEquals(" myapp:foo bar" , type.uriString)
307
341
assertEquals(0 , type.intent.flags)
308
342
assertNull(type.intent.categories)
309
343
}
310
344
345
+ @Test
346
+ fun whenUrlIsCustomUriSchemeAndRedirectThenNonHttpAppLinkTypeDetectedWithoutAdditionalIntentFlags () {
347
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (false ))
348
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
349
+ val actual = testee.determineType(" https://www.example.com" , " myapp:foo bar" .toUri()) as NonHttpAppLink
350
+ assertEquals(" myapp:foo bar" , actual.uriString)
351
+ assertEquals(0 , actual.intent.flags)
352
+ assertNull(actual.intent.categories)
353
+ }
354
+
311
355
@Test
312
356
fun whenUrlIsNotPrivacyProThenQueryTypeDetected () {
313
357
whenever(subscriptions.shouldLaunchPrivacyProForUrl(any())).thenReturn(false )
@@ -520,7 +564,7 @@ class SpecialUrlDetectorImplTest {
520
564
521
565
testee.determineType(" intent://path#Intent;scheme=testscheme;package=com.example.app;end" )
522
566
523
- verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_INTENT_SCHEME ))
567
+ verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_INTENT_SCHEME ), eq( true ) )
524
568
}
525
569
526
570
@Test
@@ -529,7 +573,50 @@ class SpecialUrlDetectorImplTest {
529
573
530
574
testee.determineType(" intent://path#Intent;scheme=testscheme;package=com.example.app;end" )
531
575
532
- verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_ANDROID_APP_SCHEME ))
576
+ verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_ANDROID_APP_SCHEME ), eq(true ))
577
+ }
578
+
579
+ @Test
580
+ fun whenValidateIntentResolutionEnabledAndNoResolveInfoThenReturnUnknownType () {
581
+ androidBrowserConfigFeature.validateIntentResolution().setRawStoredState(State (true ))
582
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(null )
583
+
584
+ val result = testee.determineType(" myapp:foo bar" )
585
+
586
+ assertTrue(result is Unknown )
587
+ }
588
+
589
+ @Test
590
+ fun whenValidateIntentResolutionDisabledAndNoResolveInfoThenReturnNonHttpAppLinkType () {
591
+ androidBrowserConfigFeature.validateIntentResolution().setRawStoredState(State (false ))
592
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(null )
593
+
594
+ val result = testee.determineType(" myapp:foo bar" )
595
+
596
+ assertTrue(result is NonHttpAppLink )
597
+ assertEquals(" myapp:foo bar" , (result as NonHttpAppLink ).uriString)
598
+ }
599
+
600
+ @Test
601
+ fun whenValidateIntentResolutionEnabledAndResolveInfoExistsThenReturnNonHttpAppLinkType () {
602
+ androidBrowserConfigFeature.validateIntentResolution().setRawStoredState(State (true ))
603
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
604
+
605
+ val result = testee.determineType(" myapp:foo bar" )
606
+
607
+ assertTrue(result is NonHttpAppLink )
608
+ assertEquals(" myapp:foo bar" , (result as NonHttpAppLink ).uriString)
609
+ }
610
+
611
+ @Test
612
+ fun whenValidateIntentResolutionDisabledAndResolveInfoExistsThenReturnNonHttpAppLinkType () {
613
+ androidBrowserConfigFeature.validateIntentResolution().setRawStoredState(State (false ))
614
+ whenever(mockPackageManager.resolveActivity(any(), anyInt())).thenReturn(ResolveInfo ())
615
+
616
+ val result = testee.determineType(" myapp:foo bar" )
617
+
618
+ assertTrue(result is NonHttpAppLink )
619
+ assertEquals(" myapp:foo bar" , (result as NonHttpAppLink ).uriString)
533
620
}
534
621
535
622
private fun randomString (length : Int ): String {
0 commit comments