17
17
package com.duckduckgo.app.browser
18
18
19
19
import android.content.Intent
20
+ import android.content.Intent.URI_ANDROID_APP_SCHEME
21
+ import android.content.Intent.URI_INTENT_SCHEME
20
22
import android.content.IntentFilter
21
23
import android.content.pm.ActivityInfo
22
24
import android.content.pm.PackageManager
@@ -29,9 +31,12 @@ import com.duckduckgo.app.browser.SpecialUrlDetectorImpl.Companion.PHONE_MAX_LEN
29
31
import com.duckduckgo.app.browser.SpecialUrlDetectorImpl.Companion.SMS_MAX_LENGTH
30
32
import com.duckduckgo.app.browser.applinks.ExternalAppIntentFlagsFeature
31
33
import com.duckduckgo.app.browser.duckchat.AIChatQueryDetectionFeature
34
+ import com.duckduckgo.app.pixels.remoteconfig.AndroidBrowserConfigFeature
32
35
import com.duckduckgo.duckchat.api.DuckChat
33
36
import com.duckduckgo.duckplayer.api.DuckPlayer
37
+ import com.duckduckgo.feature.toggles.api.FakeFeatureToggleFactory
34
38
import com.duckduckgo.feature.toggles.api.Toggle
39
+ import com.duckduckgo.feature.toggles.api.Toggle.State
35
40
import com.duckduckgo.privacy.config.api.AmpLinkType
36
41
import com.duckduckgo.privacy.config.api.AmpLinks
37
42
import com.duckduckgo.privacy.config.api.TrackingParameters
@@ -51,7 +56,7 @@ import org.mockito.kotlin.*
51
56
@RunWith(AndroidJUnit4 ::class )
52
57
class SpecialUrlDetectorImplTest {
53
58
54
- lateinit var testee: SpecialUrlDetector
59
+ lateinit var testee: SpecialUrlDetectorImpl
55
60
56
61
val mockPackageManager: PackageManager = mock()
57
62
@@ -61,9 +66,8 @@ class SpecialUrlDetectorImplTest {
61
66
62
67
val subscriptions: Subscriptions = mock()
63
68
64
- val externalAppIntentFlagsFeature: ExternalAppIntentFlagsFeature = mock()
65
-
66
- val mockToggle: Toggle = mock()
69
+ val externalAppIntentFlagsFeature: ExternalAppIntentFlagsFeature =
70
+ FakeFeatureToggleFactory .create(ExternalAppIntentFlagsFeature ::class .java)
67
71
68
72
val mockDuckPlayer: DuckPlayer = mock()
69
73
@@ -73,22 +77,28 @@ class SpecialUrlDetectorImplTest {
73
77
74
78
val mockAIChatQueryDetectionFeatureToggle: Toggle = mock()
75
79
80
+ val androidBrowserConfigFeature: AndroidBrowserConfigFeature = FakeFeatureToggleFactory .create(AndroidBrowserConfigFeature ::class .java)
81
+
76
82
@Before
77
83
fun setup () = runTest {
78
- testee = SpecialUrlDetectorImpl (
79
- packageManager = mockPackageManager,
80
- ampLinks = mockAmpLinks,
81
- trackingParameters = mockTrackingParameters,
82
- subscriptions = subscriptions,
83
- externalAppIntentFlagsFeature = externalAppIntentFlagsFeature,
84
- duckPlayer = mockDuckPlayer,
85
- duckChat = mockDuckChat,
86
- aiChatQueryDetectionFeature = mockAIChatQueryDetectionFeature,
84
+ testee = spy(
85
+ SpecialUrlDetectorImpl (
86
+ packageManager = mockPackageManager,
87
+ ampLinks = mockAmpLinks,
88
+ trackingParameters = mockTrackingParameters,
89
+ subscriptions = subscriptions,
90
+ externalAppIntentFlagsFeature = externalAppIntentFlagsFeature,
91
+ duckPlayer = mockDuckPlayer,
92
+ duckChat = mockDuckChat,
93
+ aiChatQueryDetectionFeature = mockAIChatQueryDetectionFeature,
94
+ androidBrowserConfigFeature = androidBrowserConfigFeature,
95
+ ),
87
96
)
88
97
whenever(mockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(emptyList())
89
98
whenever(mockDuckPlayer.willNavigateToDuckPlayer(any())).thenReturn(false )
90
99
whenever(mockAIChatQueryDetectionFeatureToggle.isEnabled()).thenReturn(false )
91
100
whenever(mockAIChatQueryDetectionFeature.self()).thenReturn(mockAIChatQueryDetectionFeatureToggle)
101
+ androidBrowserConfigFeature.handleIntentScheme().setRawStoredState(State (true ))
92
102
}
93
103
94
104
@Test
@@ -282,8 +292,7 @@ class SpecialUrlDetectorImplTest {
282
292
283
293
@Test
284
294
fun whenUrlIsCustomUriSchemeThenNonHttpAppLinkTypeDetectedWithAdditionalIntentFlags () {
285
- whenever(mockToggle.isEnabled()).thenReturn(true )
286
- whenever(externalAppIntentFlagsFeature.self()).thenReturn(mockToggle)
295
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (true ))
287
296
val type = testee.determineType(" myapp:foo bar" ) as NonHttpAppLink
288
297
assertEquals(" myapp:foo bar" , type.uriString)
289
298
assertEquals(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TOP , type.intent.flags)
@@ -292,8 +301,7 @@ class SpecialUrlDetectorImplTest {
292
301
293
302
@Test
294
303
fun whenUrlIsCustomUriSchemeThenNonHttpAppLinkTypeDetectedWithoutAdditionalIntentFlags () {
295
- whenever(mockToggle.isEnabled()).thenReturn(false )
296
- whenever(externalAppIntentFlagsFeature.self()).thenReturn(mockToggle)
304
+ externalAppIntentFlagsFeature.self().setRawStoredState(State (false ))
297
305
val type = testee.determineType(" myapp:foo bar" ) as NonHttpAppLink
298
306
assertEquals(" myapp:foo bar" , type.uriString)
299
307
assertEquals(0 , type.intent.flags)
@@ -508,6 +516,24 @@ class SpecialUrlDetectorImplTest {
508
516
assertTrue(type !is ShouldLaunchDuckChatLink )
509
517
}
510
518
519
+ @Test
520
+ fun whenIntentSchemeToggleEnabledThenCheckForIntentCalledWithUriIntentScheme () {
521
+ androidBrowserConfigFeature.handleIntentScheme().setRawStoredState(State (true ))
522
+
523
+ testee.determineType(" intent://path#Intent;scheme=testscheme;package=com.example.app;end" )
524
+
525
+ verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_INTENT_SCHEME ))
526
+ }
527
+
528
+ @Test
529
+ fun whenIntentSchemeToggleDisabledThenCheckForIntentCalledWithUriAndroidAppScheme () {
530
+ androidBrowserConfigFeature.handleIntentScheme().setRawStoredState(State (false ))
531
+
532
+ testee.determineType(" intent://path#Intent;scheme=testscheme;package=com.example.app;end" )
533
+
534
+ verify(testee).checkForIntent(eq(" intent" ), any(), eq(URI_ANDROID_APP_SCHEME ))
535
+ }
536
+
511
537
private fun randomString (length : Int ): String {
512
538
val charList: List <Char > = (' a' .. ' z' ) + (' 0' .. ' 9' )
513
539
return List (length) { charList.random() }.joinToString(" " )
0 commit comments