@@ -46,6 +46,7 @@ import com.duckduckgo.app.browser.LongPressHandler.RequiredAction.OpenInNewTab
46
46
import com.duckduckgo.app.browser.addtohome.AddToHomeCapabilityDetector
47
47
import com.duckduckgo.app.browser.downloader.FileDownloader
48
48
import com.duckduckgo.app.browser.favicon.FaviconManager
49
+ import com.duckduckgo.app.browser.logindetection.FireproofDialogsEventHandler
49
50
import com.duckduckgo.app.browser.logindetection.LoginDetected
50
51
import com.duckduckgo.app.browser.logindetection.NavigationAwareLoginDetector
51
52
import com.duckduckgo.app.browser.logindetection.NavigationEvent
@@ -233,6 +234,9 @@ class BrowserTabViewModelTest {
233
234
@Mock
234
235
private lateinit var geoLocationPermissions: GeoLocationPermissions
235
236
237
+ @Mock
238
+ private lateinit var fireproofDialogsEventHandler: FireproofDialogsEventHandler
239
+
236
240
private val lazyFaviconManager = Lazy { mockFaviconManager }
237
241
238
242
private lateinit var mockAutoCompleteApi: AutoCompleteApi
@@ -254,6 +258,8 @@ class BrowserTabViewModelTest {
254
258
255
259
private val loginEventLiveData = MutableLiveData <LoginDetected >()
256
260
261
+ private val fireproofDialogsEventHandlerLiveData = MutableLiveData <FireproofDialogsEventHandler .Event >()
262
+
257
263
private val dismissedCtaDaoChannel = Channel <List <DismissedCta >>()
258
264
259
265
@Before
@@ -266,6 +272,7 @@ class BrowserTabViewModelTest {
266
272
locationPermissionsDao = db.locationPermissionsDao()
267
273
268
274
mockAutoCompleteApi = AutoCompleteApi (mockAutoCompleteService, mockBookmarksDao)
275
+ val fireproofWebsiteRepository = FireproofWebsiteRepository (fireproofWebsiteDao, coroutineRule.testDispatcherProvider, lazyFaviconManager)
269
276
270
277
whenever(mockDismissedCtaDao.dismissedCtas()).thenReturn(dismissedCtaDaoChannel.consumeAsFlow())
271
278
whenever(mockTabRepository.flowTabs).thenReturn(flowOf(emptyList()))
@@ -297,6 +304,7 @@ class BrowserTabViewModelTest {
297
304
whenever(mockPrivacyPractices.privacyPracticesFor(any())).thenReturn(PrivacyPractices .UNKNOWN )
298
305
whenever(mockAppInstallStore.installTimestamp).thenReturn(System .currentTimeMillis() - TimeUnit .DAYS .toMillis(1 ))
299
306
whenever(mockUserWhitelistDao.contains(anyString())).thenReturn(false )
307
+ whenever(fireproofDialogsEventHandler.event).thenReturn(fireproofDialogsEventHandlerLiveData)
300
308
301
309
testee = BrowserTabViewModel (
302
310
statisticsUpdater = mockStatisticsUpdater,
@@ -318,7 +326,7 @@ class BrowserTabViewModelTest {
318
326
searchCountDao = mockSearchCountDao,
319
327
pixel = mockPixel,
320
328
dispatchers = coroutineRule.testDispatcherProvider,
321
- fireproofWebsiteRepository = FireproofWebsiteRepository (fireproofWebsiteDao, coroutineRule.testDispatcherProvider, lazyFaviconManager) ,
329
+ fireproofWebsiteRepository = fireproofWebsiteRepository ,
322
330
locationPermissionsRepository = LocationPermissionsRepository (
323
331
locationPermissionsDao,
324
332
lazyFaviconManager,
@@ -331,7 +339,8 @@ class BrowserTabViewModelTest {
331
339
useOurAppDetector = UseOurAppDetector (mockUserEventsStore),
332
340
variantManager = mockVariantManager,
333
341
fileDownloader = mockFileDownloader,
334
- globalPrivacyControl = GlobalPrivacyControlManager (mockSettingsStore)
342
+ globalPrivacyControl = GlobalPrivacyControlManager (mockSettingsStore),
343
+ fireproofDialogsEventHandler = fireproofDialogsEventHandler
335
344
)
336
345
337
346
testee.loadData(" abc" , null , false )
@@ -2093,24 +2102,28 @@ class BrowserTabViewModelTest {
2093
2102
}
2094
2103
2095
2104
@Test
2096
- fun whenUserFireproofsWebsiteFromLoginDialogThenShowConfirmationIsIssuedWithExpectedDomain () {
2097
- loadUrl(" http://mobile.example.com/" , isBrowserShowing = true )
2105
+ fun whenUserFireproofsWebsiteFromLoginDialogThenShowConfirmationIsIssuedWithExpectedDomain () = coroutineRule.runBlocking {
2106
+ whenever(fireproofDialogsEventHandler.onUserConfirmedFireproofDialog(anyString())).doAnswer {
2107
+ val domain = it.arguments.first() as String
2108
+ fireproofDialogsEventHandlerLiveData.postValue(FireproofDialogsEventHandler .Event .FireproofWebSiteSuccess (FireproofWebsiteEntity (domain)))
2109
+ }
2110
+
2098
2111
testee.onUserConfirmedFireproofDialog(" login.example.com" )
2112
+
2099
2113
assertCommandIssued<Command .ShowFireproofWebSiteConfirmation > {
2100
2114
assertEquals(" login.example.com" , this .fireproofWebsiteEntity.domain)
2101
2115
}
2102
2116
}
2103
2117
2104
2118
@Test
2105
- fun whenUserFireproofsWebsiteFromLoginDialogThenPixelSent () {
2106
- testee.onUserConfirmedFireproofDialog( " login.example.com " )
2107
- verify(mockPixel).fire( Pixel . PixelName . FIREPROOF_WEBSITE_LOGIN_ADDED )
2108
- }
2119
+ fun whenAskToDisableLoginDetectionEventReceivedThenAskUserToDisableLoginDetection () = coroutineRule.runBlocking {
2120
+ whenever(fireproofDialogsEventHandler.onUserDismissedFireproofLoginDialog()).doAnswer {
2121
+ fireproofDialogsEventHandlerLiveData.postValue( FireproofDialogsEventHandler . Event . AskToDisableLoginDetection )
2122
+ }
2109
2123
2110
- @Test
2111
- fun whenUserDismissesFireproofWebsiteLoginDialogThenPixelSent () {
2112
2124
testee.onUserDismissedFireproofLoginDialog()
2113
- verify(mockPixel).fire(Pixel .PixelName .FIREPROOF_WEBSITE_LOGIN_DISMISS )
2125
+
2126
+ assertCommandIssued<Command .AskToDisableLoginDetection >()
2114
2127
}
2115
2128
2116
2129
@Test
0 commit comments