Skip to content

FF remove synchronized from EmailEncryptedSharedPreferences #6009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ class BrowserTabViewModelTest {
}

@Test
fun whenDuckDuckGoUrlContainingQueryLoadedThenAtbRefreshed() {
fun whenDuckDuckGoUrlContainingQueryLoadedThenAtbRefreshed() = runTest {
loadUrl("http://duckduckgo.com?q=test")
verify(mockStatisticsUpdater).refreshSearchRetentionAtb()
}
Expand Down Expand Up @@ -3489,7 +3489,7 @@ class BrowserTabViewModelTest {
}

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

testee.consumeAliasAndCopyToClipboard()
Expand All @@ -3498,7 +3498,7 @@ class BrowserTabViewModelTest {
}

@Test
fun whenConsumeAliasAndCopyToClipboardThenSetNewLastUsedDateCalled() {
fun whenConsumeAliasAndCopyToClipboardThenSetNewLastUsedDateCalled() = runTest {
whenever(mockEmailManager.getAlias()).thenReturn("alias")

testee.consumeAliasAndCopyToClipboard()
Expand All @@ -3507,7 +3507,7 @@ class BrowserTabViewModelTest {
}

@Test
fun whenConsumeAliasAndCopyToClipboardThenPixelSent() {
fun whenConsumeAliasAndCopyToClipboardThenPixelSent() = runTest {
whenever(mockEmailManager.getAlias()).thenReturn("alias")
whenever(mockEmailManager.getCohort()).thenReturn("cohort")
whenever(mockEmailManager.getLastUsedDate()).thenReturn("2021-01-01")
Expand Down Expand Up @@ -3550,7 +3550,7 @@ class BrowserTabViewModelTest {
}

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

testee.usePrivateDuckAddress("", "alias")
Expand All @@ -3561,7 +3561,7 @@ class BrowserTabViewModelTest {
}

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

testee.usePersonalDuckAddress("", "address")
Expand All @@ -3572,7 +3572,7 @@ class BrowserTabViewModelTest {
}

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

testee.showEmailProtectionChooseEmailPrompt()
Expand All @@ -3583,7 +3583,7 @@ class BrowserTabViewModelTest {
}

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

testee.showEmailProtectionChooseEmailPrompt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class StubStatisticsModule {
fun stubStatisticsUpdater(): StatisticsUpdater {
return object : StatisticsUpdater {

override fun initializeAtb() {
override suspend fun initializeAtb() {
}

override fun refreshAppRetentionAtb() {
override suspend fun refreshAppRetentionAtb() {
}

override fun refreshSearchRetentionAtb() {
override suspend fun refreshSearchRetentionAtb() {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.app.email
import android.annotation.SuppressLint
import android.webkit.WebView
import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.autofill.DefaultEmailProtectionJavascriptInjector
Expand All @@ -28,14 +29,19 @@ import com.duckduckgo.app.browser.R
import com.duckduckgo.autofill.api.Autofill
import com.duckduckgo.autofill.api.AutofillFeature
import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.feature.toggles.api.FakeFeatureToggleFactory
import com.duckduckgo.feature.toggles.api.Toggle
import java.io.BufferedReader
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.*

@RunWith(AndroidJUnit4::class)
class EmailInjectorJsTest {

private val mockEmailManager: EmailManager = mock()
Expand All @@ -46,6 +52,9 @@ class EmailInjectorJsTest {

lateinit var testee: EmailInjectorJs

@get:Rule
var coroutineRule = CoroutineTestRule()

@Before
fun setup() {
testee =
Expand All @@ -56,6 +65,7 @@ class EmailInjectorJsTest {
autofillFeature,
javascriptInjector,
mockAutofill,
coroutineRule.testScope,
)
whenever(mockAutofill.isAnException(any())).thenReturn(false)
}
Expand Down Expand Up @@ -107,7 +117,7 @@ class EmailInjectorJsTest {
@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenNotifyWebAppSignEventAndUrlIsNotFromDuckDuckGoAndEmailIsSignedInThenDoNotEvaluateJsCode() {
fun whenNotifyWebAppSignEventAndUrlIsNotFromDuckDuckGoAndEmailIsSignedInThenDoNotEvaluateJsCode() = runTest {
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
val jsToEvaluate = getNotifySignOutJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -120,7 +130,7 @@ class EmailInjectorJsTest {
@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenNotifyWebAppSignEventAndUrlIsNotFromDuckDuckGoAndEmailIsNotSignedInThenDoNotEvaluateJsCode() {
fun whenNotifyWebAppSignEventAndUrlIsNotFromDuckDuckGoAndEmailIsNotSignedInThenDoNotEvaluateJsCode() = runTest {
whenever(mockEmailManager.isSignedIn()).thenReturn(false)
val jsToEvaluate = getNotifySignOutJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -134,7 +144,7 @@ class EmailInjectorJsTest {
@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenNotifyWebAppSignEventAndUrlIsFromDuckDuckGoAndFeatureIsDisabledAndEmailIsNotSignedInThenDoNotEvaluateJsCode() {
fun whenNotifyWebAppSignEventAndUrlIsFromDuckDuckGoAndFeatureIsDisabledAndEmailIsNotSignedInThenDoNotEvaluateJsCode() = runTest {
whenever(mockEmailManager.isSignedIn()).thenReturn(false)
autofillFeature.self().setRawStoredState(Toggle.State(enable = false))

Expand All @@ -150,7 +160,7 @@ class EmailInjectorJsTest {
@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenNotifyWebAppSignEventAndUrlIsFromDuckDuckGoAndFeatureIsEnabledAndEmailIsNotSignedInThenEvaluateJsCode() {
fun whenNotifyWebAppSignEventAndUrlIsFromDuckDuckGoAndFeatureIsEnabledAndEmailIsNotSignedInThenEvaluateJsCode() = runTest {
whenever(mockEmailManager.isSignedIn()).thenReturn(false)
autofillFeature.self().setRawStoredState(Toggle.State(enable = true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.app.email.db
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.common.test.CoroutineTestRule
import javax.inject.Provider
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
Expand All @@ -36,23 +37,34 @@ class EmailEncryptedSharedPreferencesTest {

private val mockPixel: Pixel = mock()
lateinit var testee: EmailEncryptedSharedPreferences
private val createPreferencesAsyncProvider = object : Provider<Boolean> {
override fun get(): Boolean {
return true
}
}

@Before
fun before() {
testee = EmailEncryptedSharedPreferences(InstrumentationRegistry.getInstrumentation().targetContext, mockPixel)
testee = EmailEncryptedSharedPreferences(
InstrumentationRegistry.getInstrumentation().targetContext,
mockPixel,
coroutineRule.testScope,
coroutineRule.testDispatcherProvider,
createPreferencesAsyncProvider,
)
}

@Test
fun whenNextAliasEqualsValueThenValueIsSentToNextAliasChannel() = runTest {
testee.nextAlias = "test"
testee.setNextAlias("test")

assertEquals("test", testee.nextAlias)
assertEquals("test", testee.getNextAlias())
}

@Test
fun whenNextAliasEqualsNullThenNullIsSentToNextAliasChannel() = runTest {
testee.nextAlias = null
testee.setNextAlias(null)

assertNull(testee.nextAlias)
assertNull(testee.getNextAlias())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.duckduckgo.common.test.InstantSchedulersRule
import com.duckduckgo.common.utils.plugins.PluginPoint
import com.duckduckgo.experiments.api.VariantManager
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -85,7 +86,7 @@ class AtbIntegrationTest {
}

@Test
fun whenNoStatisticsStoredThenAtbInitializationSuccessfullyStoresAtb() {
fun whenNoStatisticsStoredThenAtbInitializationSuccessfullyStoresAtb() = runTest {
testee.initializeAtb()
assertTrue(statisticsStore.hasInstallationStatistics)
val atb = statisticsStore.atb
Expand All @@ -94,7 +95,7 @@ class AtbIntegrationTest {
}

@Test
fun whenStatisticsAlreadyStoredThenRefreshSearchSuccessfullyUpdatesSearchRetentionAtbOnly() {
fun whenStatisticsAlreadyStoredThenRefreshSearchSuccessfullyUpdatesSearchRetentionAtbOnly() = runTest {
statisticsStore.saveAtb(Atb("v100-1"))
assertTrue(statisticsStore.hasInstallationStatistics)

Expand All @@ -111,7 +112,7 @@ class AtbIntegrationTest {
}

@Test
fun whenStatisticsAlreadyStoredThenRefreshAppSuccessfullyUpdatesAppRetentionAtbOnly() {
fun whenStatisticsAlreadyStoredThenRefreshAppSuccessfullyUpdatesAppRetentionAtbOnly() = runTest {
statisticsStore.saveAtb(Atb("v100-1"))
assertTrue(statisticsStore.hasInstallationStatistics)

Expand Down
Loading
Loading