Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ dependencies {
// Lottie
implementation "com.airbnb.android:lottie:_"

// Security crypto
implementation AndroidX.security.crypto

// Play Store referrer library
playImplementation("com.android.installreferrer:installreferrer:_")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.duckduckgo.app.cta.db.DismissedCtaDao
import com.duckduckgo.app.cta.model.CtaId
import com.duckduckgo.app.cta.model.DismissedCta
import com.duckduckgo.app.cta.ui.*
import com.duckduckgo.app.email.EmailManager
import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteDao
import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteEntity
import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteRepository
Expand Down Expand Up @@ -113,9 +114,12 @@ import dagger.Lazy
import io.reactivex.Observable
import io.reactivex.Single
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.runBlocking
Expand All @@ -134,6 +138,7 @@ import java.io.File
import java.util.*
import java.util.concurrent.TimeUnit

@FlowPreview
@ExperimentalCoroutinesApi
class BrowserTabViewModelTest {

Expand Down Expand Up @@ -237,6 +242,9 @@ class BrowserTabViewModelTest {
@Mock
private lateinit var fireproofDialogsEventHandler: FireproofDialogsEventHandler

@Mock
private lateinit var mockEmailManager: EmailManager

private val lazyFaviconManager = Lazy { mockFaviconManager }

private lateinit var mockAutoCompleteApi: AutoCompleteApi
Expand Down Expand Up @@ -266,6 +274,8 @@ class BrowserTabViewModelTest {

private val childClosedTabsFlow = childClosedTabsSharedFlow.asSharedFlow()

private val emailStateFlow = MutableStateFlow(false)

@Before
fun before() {
MockitoAnnotations.openMocks(this)
Expand All @@ -280,6 +290,7 @@ class BrowserTabViewModelTest {

whenever(mockDismissedCtaDao.dismissedCtas()).thenReturn(dismissedCtaDaoChannel.consumeAsFlow())
whenever(mockTabRepository.flowTabs).thenReturn(flowOf(emptyList()))
whenever(mockEmailManager.signedInFlow()).thenReturn(emailStateFlow.asStateFlow())

ctaViewModel = CtaViewModel(
mockAppInstallStore,
Expand Down Expand Up @@ -345,7 +356,8 @@ class BrowserTabViewModelTest {
variantManager = mockVariantManager,
fileDownloader = mockFileDownloader,
globalPrivacyControl = GlobalPrivacyControlManager(mockSettingsStore),
fireproofDialogsEventHandler = fireproofDialogsEventHandler
fireproofDialogsEventHandler = fireproofDialogsEventHandler,
emailManager = mockEmailManager
)

testee.loadData("abc", null, false)
Expand Down Expand Up @@ -3150,6 +3162,98 @@ class BrowserTabViewModelTest {
assertCommandNotIssued<Command.ChildTabClosed>()
}

@Test
fun whenConsumeAliasAndCopyToClipboardThenCopyAliasToClipboardCommandSent() {
whenever(mockEmailManager.getAlias()).thenReturn("alias")

testee.consumeAliasAndCopyToClipboard()

assertCommandIssued<Command.CopyAliasToClipboard>()
}

@Test
fun whenEmailIsSignedOutThenIsEmailSignedInReturnsFalse() = coroutineRule.runBlocking {
emailStateFlow.emit(false)

assertFalse(browserViewState().isEmailSignedIn)
}

@Test
fun whenEmailIsSignedInThenIsEmailSignedInReturnsTrue() = coroutineRule.runBlocking {
emailStateFlow.emit(true)

assertTrue(browserViewState().isEmailSignedIn)
}

@Test
fun whenConsumeAliasThenInjectAddressCommandSent() {
whenever(mockEmailManager.getAlias()).thenReturn("alias")

testee.consumeAlias()

assertCommandIssued<Command.InjectEmailAddress> {
assertEquals("alias", this.address)
}
}

@Test
fun whenConsumeAliasThenPixelSent() {
whenever(mockEmailManager.getAlias()).thenReturn("alias")

testee.consumeAlias()

verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ALIAS)
}

@Test
fun whenCancelAutofillTooltipThenPixelSent() {
whenever(mockEmailManager.getAlias()).thenReturn("alias")

testee.cancelAutofillTooltip()

verify(mockPixel).enqueueFire(AppPixelName.EMAIL_TOOLTIP_DISMISSED)
}

@Test
fun whenUseAddressThenInjectAddressCommandSent() {
whenever(mockEmailManager.getEmailAddress()).thenReturn("address")

testee.useAddress()

assertCommandIssued<Command.InjectEmailAddress> {
assertEquals("address", this.address)
}
}

@Test
fun whenUseAddressThenPixelSent() {
whenever(mockEmailManager.getEmailAddress()).thenReturn("address")

testee.useAddress()

verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ADDRESS)
}

@Test
fun whenShowEmailTooltipIfAddressExistsThenShowEmailTooltipCommandSent() {
whenever(mockEmailManager.getEmailAddress()).thenReturn("address")

testee.showEmailTooltip()

assertCommandIssued<Command.ShowEmailTooltip> {
assertEquals("address", this.address)
}
}

@Test
fun whenShowEmailTooltipIfAddressDoesNotExistThenCommandNotSent() {
whenever(mockEmailManager.getEmailAddress()).thenReturn(null)

testee.showEmailTooltip()

assertCommandNotIssued<Command.ShowEmailTooltip>()
}

private suspend fun givenFireButtonPulsing() {
whenever(mockUserStageStore.getUserAppStage()).thenReturn(AppStage.DAX_ONBOARDING)
dismissedCtaDaoChannel.send(listOf(DismissedCta(CtaId.DAX_DIALOG_TRACKERS_FOUND)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.duckduckgo.app.browser.httpauth.WebViewHttpAuthStore
import com.duckduckgo.app.browser.logindetection.DOMLoginDetector
import com.duckduckgo.app.browser.logindetection.WebNavigationEvent
import com.duckduckgo.app.browser.model.BasicAuthenticationRequest
import com.duckduckgo.app.email.EmailInjector
import com.duckduckgo.app.global.exception.UncaughtExceptionRepository
import com.duckduckgo.app.globalprivacycontrol.GlobalPrivacyControl
import com.duckduckgo.app.runBlocking
Expand Down Expand Up @@ -64,6 +65,7 @@ class BrowserWebViewClientTest {
private val trustedCertificateStore: TrustedCertificateStore = mock()
private val webViewHttpAuthStore: WebViewHttpAuthStore = mock()
private val thirdPartyCookieManager: ThirdPartyCookieManager = mock()
private val emailInjector: EmailInjector = mock()

@UiThreadTest
@Before
Expand All @@ -83,7 +85,8 @@ class BrowserWebViewClientTest {
globalPrivacyControl,
thirdPartyCookieManager,
GlobalScope,
coroutinesTestRule.testDispatcherProvider
coroutinesTestRule.testDispatcherProvider,
emailInjector
)
testee.webViewClientListener = listener
}
Expand Down Expand Up @@ -197,6 +200,20 @@ class BrowserWebViewClientTest {
verify(listener, never()).prefetchFavicon(any())
}

@UiThreadTest
@Test
fun whenOnPageFinishedCalledThenInjectEmailAutofillJsCalled() {
testee.onPageFinished(webView, null)
verify(emailInjector).injectEmailAutofillJs(webView, null)
}

@UiThreadTest
@Test
fun whenOnPageStartedCalledThenResetInjectedJsFlagCalled() {
testee.onPageStarted(webView, null, null)
verify(emailInjector).resetInjectedJsFlag()
}

private class TestWebView(context: Context) : WebView(context)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,23 @@ class DuckDuckGoUrlDetectorTest {
assertFalse(testee.isDuckDuckGoStaticUrl("https://example.com/settings"))
}

@Test
fun whenDomainIsNotDuckDuckGoThenReturnFalse() {
assertFalse(testee.isDuckDuckGoDomain("https://example.com"))
}

@Test
fun whenDomainIsDuckDuckGoThenReturnTrue() {
assertTrue(testee.isDuckDuckGoDomain("https://duckduckgo.com"))
}

@Test
fun whenUrlContainsSubdomainAndIsFromDuckDuckGoDomainThenReturnTrue() {
assertTrue(testee.isDuckDuckGoDomain("https://test.duckduckgo.com"))
}

@Test
fun whenUrlHasNoSchemeAndIsFromDuckDuckGoDomainThenReturnsTrue() {
assertTrue(testee.isDuckDuckGoDomain("duckduckgo.com"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CtaViewModelTest {

@Before
fun before() {
MockitoAnnotations.initMocks(this)
MockitoAnnotations.openMocks(this)
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
.allowMainThreadQueries()
.build()
Expand Down
Loading