From 733dce16d6286bb14720eb5ba8ddb13265a08ac4 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Thu, 9 Dec 2021 17:00:18 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/18175 - Add a new total protection ETP cookies policy This should only add the new option in settings based on a Nimbus experiment. --- ...sSubMenuEnhancedTrackingProtectionRobot.kt | 2 +- .../TrackingProtectionPolicyFactory.kt | 1 + ...EtpCookiesOptionsDropDownListPreference.kt | 47 +++++++++ .../fenix/settings/DropDownListPreference.kt | 2 +- .../TrackingProtectionBlockingFragment.kt | 14 ++- .../TrackingProtectionCategoryItem.kt | 20 +++- .../TrackingProtectionPanelView.kt | 19 +++- .../java/org/mozilla/fenix/utils/Settings.kt | 11 ++- app/src/main/res/values/arrays.xml | 3 + app/src/main/res/values/strings.xml | 6 ++ .../xml/tracking_protection_preferences.xml | 2 +- .../TrackingProtectionPolicyFactoryTest.kt | 24 +++++ ...ookiesOptionsDropDownListPreferenceTest.kt | 86 +++++++++++++++++ .../TrackingProtectionBlockingFragmentTest.kt | 79 +++++++++++++++ .../TrackingProtectionPanelViewTest.kt | 95 +++++++++++++++++-- 15 files changed, 392 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/settings/CustomEtpCookiesOptionsDropDownListPreference.kt create mode 100644 app/src/test/java/org/mozilla/fenix/settings/CustomEtpCookiesOptionsDropDownListPreferenceTest.kt create mode 100644 app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragmentTest.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuEnhancedTrackingProtectionRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuEnhancedTrackingProtectionRobot.kt index 4d42b2684e..b857c0136f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuEnhancedTrackingProtectionRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuEnhancedTrackingProtectionRobot.kt @@ -219,7 +219,7 @@ private fun assertCustomTrackingProtectionSettings() { private fun cookiesCheckbox() = onView(withText("Cookies")) -private fun cookiesDropDownMenuDefault() = onView(withText("Cross-site and social media trackers")) +private fun cookiesDropDownMenuDefault() = onView(withText("Isolate cross-site cookies")) private fun trackingContentCheckbox() = onView(withText("Tracking content")) diff --git a/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt b/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt index 29b6134fa7..7ceca624ce 100644 --- a/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt +++ b/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt @@ -78,6 +78,7 @@ class TrackingProtectionPolicyFactory( resources.getString(R.string.social) -> CookiePolicy.ACCEPT_NON_TRACKERS resources.getString(R.string.unvisited) -> CookiePolicy.ACCEPT_VISITED resources.getString(R.string.third_party) -> CookiePolicy.ACCEPT_ONLY_FIRST_PARTY + resources.getString(R.string.total_protection) -> CookiePolicy.ACCEPT_FIRST_PARTY_AND_ISOLATE_OTHERS else -> CookiePolicy.ACCEPT_NONE } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/CustomEtpCookiesOptionsDropDownListPreference.kt b/app/src/main/java/org/mozilla/fenix/settings/CustomEtpCookiesOptionsDropDownListPreference.kt new file mode 100644 index 0000000000..a57504f6b0 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/settings/CustomEtpCookiesOptionsDropDownListPreference.kt @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.settings + +import android.content.Context +import android.util.AttributeSet +import org.mozilla.fenix.R +import org.mozilla.fenix.ext.settings + +/** + * Custom [DropDownListPreference] that automatically builds the list of available options for the + * custom Enhanced Tracking Protection option depending on the current Nimbus experiments. + */ +class CustomEtpCookiesOptionsDropDownListPreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null +) : DropDownListPreference(context, attrs) { + init { + with(context) { + entries = arrayOf( + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_1), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_2), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_3), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_4), + ) + + entryValues = arrayOf( + getString(R.string.social), + getString(R.string.unvisited), + getString(R.string.third_party), + getString(R.string.all), + ) + + @Suppress("UNCHECKED_CAST") + if (context.settings().enabledTotalCookieProtectionSetting) { + // If the new "Total cookie protection" should be shown it must be first item. + entries = arrayOf(getString(R.string.preference_enhanced_tracking_protection_custom_cookies_5)) + + entries as Array + entryValues = arrayOf(getString(R.string.total_protection)) + entryValues as Array + } + } + + setDefaultValue(entryValues.first()) + } +} diff --git a/app/src/main/java/org/mozilla/fenix/settings/DropDownListPreference.kt b/app/src/main/java/org/mozilla/fenix/settings/DropDownListPreference.kt index 159cb4752e..0b413fad0b 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/DropDownListPreference.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/DropDownListPreference.kt @@ -11,7 +11,7 @@ import androidx.preference.DropDownPreference import androidx.preference.ListPreference import org.mozilla.fenix.R -class DropDownListPreference @JvmOverloads constructor( +open class DropDownListPreference @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : DropDownPreference(context, attrs) { diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt index cd0dd0e9bf..32933745a3 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.trackingprotection import android.os.Bundle import android.view.View +import androidx.annotation.VisibleForTesting import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.fragment.navArgs @@ -19,11 +20,22 @@ class TrackingProtectionBlockingFragment : private val args: TrackingProtectionBlockingFragmentArgs by navArgs() private val settings by lazy { requireContext().settings() } + @VisibleForTesting + internal lateinit var binding: FragmentTrackingProtectionBlockingBinding override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val binding = FragmentTrackingProtectionBlockingBinding.bind(view) + binding = FragmentTrackingProtectionBlockingBinding.bind(view) + + // Text for the updated "Total cookie protection" option should be updated as part of a staged rollout + if (requireContext().settings().enabledTotalCookieProtectionSetting) { + binding.categoryCookies.apply { + trackingProtectionCategoryTitle.text = getText(R.string.etp_cookies_title_2) + trackingProtectionCategoryItemDescription.text = getText(R.string.etp_cookies_description_2) + } + } + when (args.protectionMode) { TrackingProtectionMode.STANDARD -> { binding.categoryTrackingContent.isVisible = false diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt index fb6d8a965b..dd7d7868fd 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt @@ -17,12 +17,12 @@ class TrackingProtectionCategoryItem @JvmOverloads constructor( attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr) { - init { - val binding = TrackingProtectionCategoryBinding.inflate( - LayoutInflater.from(context), - this - ) + private val binding = TrackingProtectionCategoryBinding.inflate( + LayoutInflater.from(context), + this + ) + init { context.withStyledAttributes( attrs, R.styleable.TrackingProtectionCategory, @@ -43,4 +43,14 @@ class TrackingProtectionCategoryItem @JvmOverloads constructor( ) } } + + /** + * The displayed title of this item. + */ + val trackingProtectionCategoryTitle = binding.trackingProtectionCategoryTitle + + /** + * The displayed description of this item. + */ + val trackingProtectionCategoryItemDescription = binding.trackingProtectionCategoryItemDescription } diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt index 6c157d6eb1..7f64da0cf9 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt @@ -25,6 +25,7 @@ import org.mozilla.fenix.GleanMetrics.TrackingProtection import org.mozilla.fenix.R import org.mozilla.fenix.databinding.ComponentTrackingProtectionPanelBinding import org.mozilla.fenix.ext.addUnderline +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CRYPTOMINERS import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.FINGERPRINTERS @@ -128,6 +129,11 @@ class TrackingProtectionPanelView( binding.notBlockingHeader.isGone = bucketedTrackers.loadedIsEmpty() binding.blockingHeader.isGone = bucketedTrackers.blockedIsEmpty() + if (containerView.context.settings().enabledTotalCookieProtectionSetting) { + binding.crossSiteTracking.text = containerView.context.getString(R.string.etp_cookies_title_2) + binding.crossSiteTrackingLoaded.text = containerView.context.getString(R.string.etp_cookies_title_2) + } + updateCategoryVisibility() focusAccessibilityLastUsedCategory(state.lastAccessedCategory) } @@ -139,7 +145,16 @@ class TrackingProtectionPanelView( val containASmartBlockItem = bucketedTrackers.get(category, categoryBlocked).any { it.unBlockedBySmartBlock } binding.normalMode.visibility = View.GONE binding.detailsMode.visibility = View.VISIBLE - binding.categoryTitle.setText(category.title) + + if (category == CROSS_SITE_TRACKING_COOKIES && + containerView.context.settings().enabledTotalCookieProtectionSetting + ) { + binding.categoryTitle.setText(R.string.etp_cookies_title_2) + binding.categoryDescription.setText(R.string.etp_cookies_description_2) + } else { + binding.categoryTitle.setText(category.title) + binding.categoryDescription.setText(category.description) + } binding.smartblockDescription.isVisible = containASmartBlockItem binding.smartblockLearnMore.isVisible = containASmartBlockItem @@ -158,7 +173,7 @@ class TrackingProtectionPanelView( setOnClickListener { interactor.onLearnMoreClicked() } } } - binding.categoryDescription.setText(category.description) + binding.detailsBlockingHeader.setText( if (categoryBlocked) { R.string.enhanced_tracking_protection_blocked diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index ad2ebcd210..bb8e9b4ddc 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -571,9 +571,16 @@ class Settings(private val appContext: Context) : PreferencesHolder { val enabledTotalCookieProtection: Boolean get() = FxNimbus.features.engineSettings.value().totalCookieProtectionEnabled + val enabledTotalCookieProtectionSetting: Boolean + get() = mr2022Sections[Mr2022Section.TCP_CFR] == true + val blockCookiesSelectionInCustomTrackingProtection by stringPreference( - appContext.getPreferenceKey(R.string.pref_key_tracking_protection_custom_cookies_select), - appContext.getString(R.string.social) + key = appContext.getPreferenceKey(R.string.pref_key_tracking_protection_custom_cookies_select), + default = if (enabledTotalCookieProtectionSetting) { + appContext.getString(R.string.total_protection) + } else { + appContext.getString(R.string.social) + } ) val blockTrackingContentInCustomTrackingProtection by booleanPreference( diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 530e2380ac..5839f16e78 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -3,6 +3,7 @@ - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + total-protection social unvisited third-party @@ -10,6 +11,7 @@ private + @string/preference_enhanced_tracking_protection_custom_cookies_5 @string/preference_enhanced_tracking_protection_custom_cookies_1 @string/preference_enhanced_tracking_protection_custom_cookies_2 @string/preference_enhanced_tracking_protection_custom_cookies_3 @@ -17,6 +19,7 @@ + @string/total_protection @string/social @string/unvisited @string/third_party diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e92c152415..d4f8cfb72b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1275,6 +1275,8 @@ All third-party cookies (may cause websites to break) All cookies (will cause websites to break) + + Isolate cross-site cookies Tracking content @@ -1297,8 +1299,12 @@ Limits the ability of social networks to track your browsing activity around the web. Cross-Site Tracking Cookies + + Cross-Site Cookies Blocks cookies that ad networks and analytics companies use to compile your browsing data across many sites. + + Total Cookie Protection isolates cookies to the site you\'re on so trackers like ad networks can\'t use them to follow you across sites. Cryptominers diff --git a/app/src/main/res/xml/tracking_protection_preferences.xml b/app/src/main/res/xml/tracking_protection_preferences.xml index f53ca38e67..d6d9366985 100644 --- a/app/src/main/res/xml/tracking_protection_preferences.xml +++ b/app/src/main/res/xml/tracking_protection_preferences.xml @@ -38,7 +38,7 @@ android:key="@string/pref_key_tracking_protection_custom_cookies" android:layout="@layout/checkbox_left_preference_etp" android:title="@string/preference_enhanced_tracking_protection_custom_cookies" /> - ().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns true + } + + val preference = CustomEtpCookiesOptionsDropDownListPreference(testContext) + + assertArrayEquals(expectedEntries, preference.entries) + assertArrayEquals(expectedValues, preference.entryValues) + assertEquals(expectedValues[0], preference.getDefaultValue()) + } + } + + @Test + fun `GIVEN total cookie protection is disabled WHEN using this preference THEN don't show the total cookie protection option`() { + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns false + } + + val preference = CustomEtpCookiesOptionsDropDownListPreference(testContext) + + assertArrayEquals(defaultEntries, preference.entries) + assertArrayEquals(defaultValues, preference.entryValues) + assertEquals(defaultValues[0], preference.getDefaultValue()) + } + } + + /** + * Use reflection to get the private member holding the default value set for this preference. + */ + private fun CustomEtpCookiesOptionsDropDownListPreference.getDefaultValue(): String { + return Preference::class.java + .getDeclaredField("mDefaultValue").let { field -> + field.isAccessible = true + return@let field.get(this) as String + } + } + + private val defaultEntries = with(testContext) { + arrayOf( + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_1), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_2), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_3), + getString(R.string.preference_enhanced_tracking_protection_custom_cookies_4), + ) + } + + private val defaultValues = with(testContext) { + arrayOf( + getString(R.string.social), + getString(R.string.unvisited), + getString(R.string.third_party), + getString(R.string.all), + ) + } +} diff --git a/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragmentTest.kt new file mode 100644 index 0000000000..c5de49c987 --- /dev/null +++ b/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragmentTest.kt @@ -0,0 +1,79 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.trackingprotection + +import android.content.Context +import androidx.fragment.app.FragmentActivity +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.mozilla.fenix.R +import org.mozilla.fenix.ext.settings +import org.mozilla.fenix.helpers.FenixRobolectricTestRunner +import org.mozilla.fenix.trackingprotection.TrackingProtectionMode.CUSTOM +import org.robolectric.Robolectric + +@RunWith(FenixRobolectricTestRunner::class) +class TrackingProtectionBlockingFragmentTest { + @Test + fun `GIVEN total cookie protection is enabled WHEN showing details about the protection options THEN show update details for tracking protection`() { + val expectedTitle = testContext.getString(R.string.etp_cookies_title_2) + val expectedDescription = testContext.getString(R.string.etp_cookies_description_2) + + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk(relaxed = true) { + every { enabledTotalCookieProtectionSetting } returns true + } + + val fragment = createFragment() + + val cookiesCategory = fragment.binding.categoryCookies + assertEquals(expectedTitle, cookiesCategory.trackingProtectionCategoryTitle.text) + assertEquals(expectedDescription, cookiesCategory.trackingProtectionCategoryItemDescription.text) + } + } + + @Test + fun `GIVEN total cookie protection is not enabled WHEN showing details about the protection options THEN show the default details for tracking protection`() { + val expectedTitle = testContext.getString(R.string.etp_cookies_title) + val expectedDescription = testContext.getString(R.string.etp_cookies_description) + + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk(relaxed = true) { + every { enabledTotalCookieProtectionSetting } returns false + } + + val fragment = createFragment() + + val cookiesCategory = fragment.binding.categoryCookies + assertEquals(expectedTitle, cookiesCategory.trackingProtectionCategoryTitle.text) + assertEquals(expectedDescription, cookiesCategory.trackingProtectionCategoryItemDescription.text) + } + } + + private fun createFragment(): TrackingProtectionBlockingFragment { + // Create and attach the fragment ourself instead of using "createAddedTestFragment" + // to prevent having "onResume -> showToolbar" called. + + val activity = Robolectric.buildActivity(FragmentActivity::class.java) + .create() + .start() + .get() + val fragment = TrackingProtectionBlockingFragment().apply { + arguments = TrackingProtectionBlockingFragmentArgs( + protectionMode = CUSTOM + ).toBundle() + } + activity.supportFragmentManager.beginTransaction() + .add(fragment, "test") + .commitNow() + + return fragment + } +} diff --git a/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt b/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt index a9f40a3fa9..0c1cec2a9f 100644 --- a/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt @@ -4,11 +4,13 @@ package org.mozilla.fenix.trackingprotection +import android.content.Context import android.view.ViewGroup import android.widget.FrameLayout import androidx.core.view.isVisible import io.mockk.every import io.mockk.mockk +import io.mockk.mockkStatic import io.mockk.verify import mozilla.components.service.glean.testing.GleanTestRule import mozilla.components.support.test.robolectric.testContext @@ -24,6 +26,7 @@ import org.junit.runner.RunWith import org.mozilla.fenix.GleanMetrics.TrackingProtection import org.mozilla.fenix.R import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS @@ -55,12 +58,46 @@ class TrackingProtectionPanelViewTest { @Test fun testNormalModeUi() { - view.update(baseState.copy(mode = TrackingProtectionState.Mode.Normal)) - assertFalse(view.binding.detailsMode.isVisible) - assertTrue(view.binding.normalMode.isVisible) - assertTrue(view.binding.protectionSettings.isVisible) - assertFalse(view.binding.notBlockingHeader.isVisible) - assertFalse(view.binding.blockingHeader.isVisible) + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk(relaxed = true) + + view.update(baseState.copy(mode = TrackingProtectionState.Mode.Normal)) + assertFalse(view.binding.detailsMode.isVisible) + assertTrue(view.binding.normalMode.isVisible) + assertTrue(view.binding.protectionSettings.isVisible) + assertFalse(view.binding.notBlockingHeader.isVisible) + assertFalse(view.binding.blockingHeader.isVisible) + } + } + + @Test + fun testNormalModeUiCookiesWithTotalCookieProtectionEnabled() { + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns true + } + val expectedTitle = testContext.getString(R.string.etp_cookies_title_2) + + view.update(baseState.copy(mode = TrackingProtectionState.Mode.Normal)) + + assertEquals(expectedTitle, view.binding.crossSiteTracking.text) + assertEquals(expectedTitle, view.binding.crossSiteTrackingLoaded.text) + } + } + + @Test + fun testNormalModeUiCookiesWithTotalCookieProtectionDisabled() { + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns false + } + val expectedTitle = testContext.getString(R.string.etp_cookies_title) + + view.update(baseState.copy(mode = TrackingProtectionState.Mode.Normal)) + + assertEquals(expectedTitle, view.binding.crossSiteTracking.text) + assertEquals(expectedTitle, view.binding.crossSiteTrackingLoaded.text) + } } @Test @@ -89,6 +126,52 @@ class TrackingProtectionPanelViewTest { ) } + @Test + fun testPrivateModeUiCookiesWithTotalCookieProtectionEnabled() { + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns true + } + val expectedTitle = testContext.getString(R.string.etp_cookies_title_2) + val expectedDescription = testContext.getString(R.string.etp_cookies_description_2) + + view.update( + baseState.copy( + mode = TrackingProtectionState.Mode.Details( + selectedCategory = CROSS_SITE_TRACKING_COOKIES, + categoryBlocked = false + ) + ) + ) + + assertEquals(expectedTitle, view.binding.categoryTitle.text) + assertEquals(expectedDescription, view.binding.categoryDescription.text) + } + } + + @Test + fun testPrivateModeUiCookiesWithTotalCookieProtectionDisabled() { + mockkStatic("org.mozilla.fenix.ext.ContextKt") { + every { any().settings() } returns mockk { + every { enabledTotalCookieProtectionSetting } returns false + } + val expectedTitle = testContext.getString(R.string.etp_cookies_title) + val expectedDescription = testContext.getString(R.string.etp_cookies_description) + + view.update( + baseState.copy( + mode = TrackingProtectionState.Mode.Details( + selectedCategory = CROSS_SITE_TRACKING_COOKIES, + categoryBlocked = false + ) + ) + ) + + assertEquals(expectedTitle, view.binding.categoryTitle.text) + assertEquals(expectedDescription, view.binding.categoryDescription.text) + } + } + @Test fun testProtectionSettings() { view.binding.protectionSettings.performClick()