From 79f788e5778350ee38ae362a3bc6b462040986a6 Mon Sep 17 00:00:00 2001 From: Elise Richards Date: Fri, 18 Sep 2020 14:03:51 -0500 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/13812: add ETP category for redirect trackers (https://github.com/mozilla-mobile/fenix/pull/15139) * Feature flag for ETP cookie purging * Strings for new ETP description * Remove icons from ETP info screeen and add category for redirect trackers * ETP policy factory tests * Remove icons from ETP panel and add cross tracking allowed field. * Remove icons on ETP panel. Add blocked category for redirect trackers to panel. * Add margins to tracking protection settings --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 + .../TrackingProtectionPolicyFactory.kt | 3 +- .../TrackingProtectionBlockingFragment.kt | 2 + .../TrackingProtectionCategoryItem.kt | 6 - .../TrackingProtectionPanelView.kt | 16 +- .../component_tracking_protection_panel.xml | 20 +-- .../fragment_tracking_protection_blocking.xml | 16 +- .../layout/tracking_protection_category.xml | 28 +-- app/src/main/res/values/attrs.xml | 1 - app/src/main/res/values/strings.xml | 4 + .../TrackingProtectionPolicyFactoryTest.kt | 166 ++++++++++-------- .../TrackingProtectionPanelViewTest.kt | 10 ++ 12 files changed, 155 insertions(+), 122 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index ef763bc977..01fd6d64c9 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -45,4 +45,9 @@ object FeatureFlags { * Enables swipe to delete in bookmarks */ val bookmarkSwipeToDelete = Config.channel.isNightlyOrDebug + + /** + * Enables ETP cookie purging + */ + val etpCookiePurging = Config.channel.isNightlyOrDebug } 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 9a0853e43d..bc614aef1a 100644 --- a/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt +++ b/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt @@ -8,6 +8,7 @@ import androidx.annotation.VisibleForTesting import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicyForSessionTypes import org.mozilla.fenix.Config +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.utils.Settings /** @@ -102,6 +103,6 @@ internal fun TrackingProtectionPolicyForSessionTypes.adaptPolicyToChannel(): Tra trackingCategories = trackingCategories, cookiePolicy = cookiePolicy, strictSocialTrackingProtection = strictSocialTrackingProtection, - cookiePurging = Config.channel.isNightlyOrDebug + cookiePurging = FeatureFlags.etpCookiePurging ) } 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 0bacaebfdd..bbc8832f46 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt @@ -10,6 +10,7 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.fragment.navArgs import kotlinx.android.synthetic.main.fragment_tracking_protection_blocking.* +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar @@ -22,6 +23,7 @@ class TrackingProtectionBlockingFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + category_redirect_trackers.isVisible = FeatureFlags.etpCookiePurging when (args.protectionMode) { TrackingProtectionMode.STANDARD -> { 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 15d4a52bb9..9a40e612a9 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionCategoryItem.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.trackingprotection import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater -import androidx.appcompat.content.res.AppCompatResources import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.withStyledAttributes import kotlinx.android.synthetic.main.tracking_protection_category.view.* @@ -27,11 +26,6 @@ class TrackingProtectionCategoryItem @JvmOverloads constructor( defStyleAttr, 0 ) { - val id = getResourceId( - R.styleable.TrackingProtectionCategory_categoryItemIcon, - R.drawable.ic_cryptominers - ) - trackingProtectionCategoryIcon?.background = AppCompatResources.getDrawable(context, id) trackingProtectionCategoryTitle?.text = resources.getString( getResourceId( R.styleable.TrackingProtectionCategory_categoryItemTitle, 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 79e42c13af..624a76526e 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt @@ -149,9 +149,14 @@ class TrackingProtectionPanelView( } } + /** + * Checks whether the permission was allowed or blocked when they were last used based on + * visibility, where "..._loaded" titles correspond to "Allowed" permissions and the other + * corresponds to "Blocked" permissions for each category. + */ private fun getLastUsedCategoryView(categoryTitle: String) = when (categoryTitle) { CROSS_SITE_TRACKING_COOKIES.name -> { - cross_site_tracking + if (cross_site_tracking.isGone) cross_site_tracking_loaded else cross_site_tracking } SOCIAL_MEDIA_TRACKERS.name -> { if (social_media_trackers.isGone) social_media_trackers_loaded else social_media_trackers @@ -171,11 +176,14 @@ class TrackingProtectionPanelView( private fun updateCategoryVisibility() { cross_site_tracking.isGone = bucketedTrackers.get(CROSS_SITE_TRACKING_COOKIES, true).isEmpty() - social_media_trackers.isGone = bucketedTrackers.get(SOCIAL_MEDIA_TRACKERS, true).isEmpty() + social_media_trackers.isGone = + bucketedTrackers.get(SOCIAL_MEDIA_TRACKERS, true).isEmpty() fingerprinters.isGone = bucketedTrackers.get(FINGERPRINTERS, true).isEmpty() tracking_content.isGone = bucketedTrackers.get(TRACKING_CONTENT, true).isEmpty() cryptominers.isGone = bucketedTrackers.get(CRYPTOMINERS, true).isEmpty() + cross_site_tracking_loaded.isGone = + bucketedTrackers.get(CROSS_SITE_TRACKING_COOKIES, false).isEmpty() social_media_trackers_loaded.isGone = bucketedTrackers.get(SOCIAL_MEDIA_TRACKERS, false).isEmpty() fingerprinters_loaded.isGone = bucketedTrackers.get(FINGERPRINTERS, false).isEmpty() @@ -189,6 +197,7 @@ class TrackingProtectionPanelView( cross_site_tracking.setOnClickListener(this) tracking_content.setOnClickListener(this) cryptominers.setOnClickListener(this) + cross_site_tracking_loaded.setOnClickListener(this) social_media_trackers_loaded.setOnClickListener(this) fingerprinters_loaded.setOnClickListener(this) tracking_content_loaded.setOnClickListener(this) @@ -251,7 +260,7 @@ class TrackingProtectionPanelView( private fun getCategory(v: View) = when (v.id) { R.id.social_media_trackers, R.id.social_media_trackers_loaded -> SOCIAL_MEDIA_TRACKERS R.id.fingerprinters, R.id.fingerprinters_loaded -> FINGERPRINTERS - R.id.cross_site_tracking -> CROSS_SITE_TRACKING_COOKIES + R.id.cross_site_tracking, R.id.cross_site_tracking_loaded -> CROSS_SITE_TRACKING_COOKIES R.id.tracking_content, R.id.tracking_content_loaded -> TRACKING_CONTENT R.id.cryptominers, R.id.cryptominers_loaded -> CRYPTOMINERS else -> null @@ -262,6 +271,7 @@ class TrackingProtectionPanelView( */ private fun isLoaded(v: View) = when (v.id) { R.id.social_media_trackers_loaded, + R.id.cross_site_tracking_loaded, R.id.fingerprinters_loaded, R.id.tracking_content_loaded, R.id.cryptominers_loaded -> true diff --git a/app/src/main/res/layout/component_tracking_protection_panel.xml b/app/src/main/res/layout/component_tracking_protection_panel.xml index 27383a4664..e363deb9fe 100644 --- a/app/src/main/res/layout/component_tracking_protection_panel.xml +++ b/app/src/main/res/layout/component_tracking_protection_panel.xml @@ -61,7 +61,6 @@ android:layout_height="@dimen/tracking_protection_item_height" android:text="@string/etp_cookies_title" android:visibility="gone" - app:drawableStartCompat="@drawable/ic_cookies" app:layout_constraintTop_toBottomOf="@id/blocking_header" /> + + + app:layout_constraintTop_toBottomOf="@id/cross_site_tracking_loaded" /> + + diff --git a/app/src/main/res/layout/tracking_protection_category.xml b/app/src/main/res/layout/tracking_protection_category.xml index 324f4d0282..a7ca6623f4 100644 --- a/app/src/main/res/layout/tracking_protection_category.xml +++ b/app/src/main/res/layout/tracking_protection_category.xml @@ -9,25 +9,11 @@ android:layout_height="wrap_content" tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"> - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/trackingProtectionCategoryTitle" /> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 2edab8d151..73450133e9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -72,7 +72,6 @@ - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d575051b0a..79fbfe7c7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1255,6 +1255,10 @@ %s | OSS Libraries + + Redirect Trackers + + Clears cookies set by redirects to known tracking websites. Support diff --git a/app/src/test/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactoryTest.kt b/app/src/test/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactoryTest.kt index 9289859d2e..518690cc30 100644 --- a/app/src/test/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactoryTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactoryTest.kt @@ -3,7 +3,6 @@ package org.mozilla.fenix.components import io.mockk.every import io.mockk.mockk import io.mockk.mockkObject -import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertArrayEquals @@ -13,6 +12,7 @@ import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.Config +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ReleaseChannel import org.mozilla.fenix.utils.Settings @@ -23,7 +23,7 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `WHEN useStrictMode is true then SHOULD return strict mode`() { - val expected = EngineSession.TrackingProtectionPolicy.strict() + val expected = TrackingProtectionPolicy.strict() val factory = TrackingProtectionPolicyFactory(mockSettings(useStrict = true)) @@ -35,12 +35,12 @@ class TrackingProtectionPolicyFactoryTest { expected.assertPolicyEquals(privateOnly, checkPrivacy = false) expected.assertPolicyEquals(normalOnly, checkPrivacy = false) expected.assertPolicyEquals(always, checkPrivacy = false) - EngineSession.TrackingProtectionPolicy.none().assertPolicyEquals(none, checkPrivacy = false) + TrackingProtectionPolicy.none().assertPolicyEquals(none, checkPrivacy = false) } @Test fun `WHEN neither use strict nor use custom is true SHOULD return recommended mode`() { - val expected = EngineSession.TrackingProtectionPolicy.recommended() + val expected = TrackingProtectionPolicy.recommended() val factory = TrackingProtectionPolicyFactory(mockSettings(useStrict = false, useCustom = false)) @@ -52,13 +52,13 @@ class TrackingProtectionPolicyFactoryTest { expected.assertPolicyEquals(privateOnly, checkPrivacy = false) expected.assertPolicyEquals(normalOnly, checkPrivacy = false) expected.assertPolicyEquals(always, checkPrivacy = false) - EngineSession.TrackingProtectionPolicy.none().assertPolicyEquals(none, checkPrivacy = false) + TrackingProtectionPolicy.none().assertPolicyEquals(none, checkPrivacy = false) } @Test fun `GIVEN custom policy WHEN should not block cookies THEN tracking policy should not block cookies`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_ALL, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_ALL, trackingCategories = allTrackingCategories ) @@ -75,8 +75,8 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN cookie policy block all THEN tracking policy should have cookie policy allow none`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, trackingCategories = allTrackingCategories ) @@ -91,34 +91,6 @@ class TrackingProtectionPolicyFactoryTest { expected.assertPolicyEquals(always, checkPrivacy = false) } - @Test - fun `cookiePurging must be available ONLY in nightly or debug`() { - mockkObject(Config) - for (channel in ReleaseChannel.values()) { - every { Config.channel } returns channel - - val shouldCookiePurgingActive = channel.isNightlyOrDebug - val customSetting = - settingsForCustom(shouldBlockCookiesInCustom = true, blockCookiesSelection = "all") - val stringSetting = mockSettings(useStrict = true) - val recommendedSetting = mockSettings(useTrackingProtection = true) - - for (setting in arrayOf(recommendedSetting, stringSetting, customSetting)) { - val factory = TrackingProtectionPolicyFactory(setting) - val privateOnly = - factory.createTrackingProtectionPolicy(normalMode = false, privateMode = true) - val normalOnly = - factory.createTrackingProtectionPolicy(normalMode = true, privateMode = false) - val always = - factory.createTrackingProtectionPolicy(normalMode = true, privateMode = true) - - assertEquals(shouldCookiePurgingActive, privateOnly.cookiePurging) - assertEquals(shouldCookiePurgingActive, normalOnly.cookiePurging) - assertEquals(shouldCookiePurgingActive, always.cookiePurging) - } - } - } - @Test fun `adaptPolicyToChannel MUST only update properties that have changed per given channel`() { mockkObject(Config) @@ -131,20 +103,17 @@ class TrackingProtectionPolicyFactoryTest { for (channel in ReleaseChannel.values()) { every { Config.channel } returns channel - val shouldCookiePurgingActive = channel.isNightlyOrDebug - for (policy in policies) { val adaptedPolicy = policy.adaptPolicyToChannel() policy.assertPolicyEquals(adaptedPolicy, checkPrivacy = false) - assertEquals(shouldCookiePurgingActive, adaptedPolicy.cookiePurging) } } } @Test fun `GIVEN custom policy WHEN cookie policy social THEN tracking policy should have cookie policy allow non-trackers`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NON_TRACKERS, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NON_TRACKERS, trackingCategories = allTrackingCategories ) @@ -161,8 +130,8 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN cookie policy accept visited THEN tracking policy should have cookie policy allow visited`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_VISITED, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_VISITED, trackingCategories = allTrackingCategories ) @@ -179,8 +148,8 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN cookie policy block third party THEN tracking policy should have cookie policy allow first party`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_ONLY_FIRST_PARTY, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_ONLY_FIRST_PARTY, trackingCategories = allTrackingCategories ) @@ -197,8 +166,8 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN cookie policy unrecognized THEN tracking policy should have cookie policy block all`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, trackingCategories = allTrackingCategories ) @@ -261,7 +230,7 @@ class TrackingProtectionPolicyFactoryTest { useETPFactory = TrackingProtectionPolicyFactory(mockSettings(useTrackingProtection = false)) policy = useETPFactory.createTrackingProtectionPolicy() - assertEquals(policy, EngineSession.TrackingProtectionPolicy.none()) + assertEquals(policy, TrackingProtectionPolicy.none()) } @Test @@ -306,14 +275,14 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN default tracking policies THEN tracking policies should match default`() { val defaultTrackingCategories = arrayOf( - EngineSession.TrackingProtectionPolicy.TrackingCategory.AD, - EngineSession.TrackingProtectionPolicy.TrackingCategory.ANALYTICS, - EngineSession.TrackingProtectionPolicy.TrackingCategory.SOCIAL, - EngineSession.TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL + TrackingProtectionPolicy.TrackingCategory.AD, + TrackingProtectionPolicy.TrackingCategory.ANALYTICS, + TrackingProtectionPolicy.TrackingCategory.SOCIAL, + TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL ) - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, trackingCategories = defaultTrackingCategories ) @@ -332,8 +301,8 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN all tracking policies THEN tracking policies should match all`() { - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, trackingCategories = allTrackingCategories ) @@ -353,15 +322,15 @@ class TrackingProtectionPolicyFactoryTest { @Test fun `GIVEN custom policy WHEN some tracking policies THEN tracking policies should match passed policies`() { val someTrackingCategories = arrayOf( - EngineSession.TrackingProtectionPolicy.TrackingCategory.AD, - EngineSession.TrackingProtectionPolicy.TrackingCategory.ANALYTICS, - EngineSession.TrackingProtectionPolicy.TrackingCategory.SOCIAL, - EngineSession.TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL, - EngineSession.TrackingProtectionPolicy.TrackingCategory.FINGERPRINTING + TrackingProtectionPolicy.TrackingCategory.AD, + TrackingProtectionPolicy.TrackingCategory.ANALYTICS, + TrackingProtectionPolicy.TrackingCategory.SOCIAL, + TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL, + TrackingProtectionPolicy.TrackingCategory.FINGERPRINTING ) - val expected = EngineSession.TrackingProtectionPolicy.select( - cookiePolicy = EngineSession.TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, trackingCategories = someTrackingCategories ) @@ -377,6 +346,55 @@ class TrackingProtectionPolicyFactoryTest { expected.assertPolicyEquals(actual, checkPrivacy = false) } + + @Test + fun `GIVEN custom policy WHEN some tracking policies THEN purge cookies`() { + val expected = TrackingProtectionPolicy.select( + cookiePolicy = TrackingProtectionPolicy.CookiePolicy.ACCEPT_NONE, + trackingCategories = allTrackingCategories, + cookiePurging = FeatureFlags.etpCookiePurging + ) + + val factory = TrackingProtectionPolicyFactory(settingsForCustom(shouldBlockCookiesInCustom = true)) + + val privateOnly = factory.createTrackingProtectionPolicy(normalMode = false, privateMode = true) + val normalOnly = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = false) + val always = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = true) + + expected.assertPolicyEquals(privateOnly, checkPrivacy = false) + expected.assertPolicyEquals(normalOnly, checkPrivacy = false) + expected.assertPolicyEquals(always, checkPrivacy = false) + } + + @Test + fun `GIVEN strict policy WHEN some tracking policies THEN purge cookies`() { + val expected = TrackingProtectionPolicy.strict() + + val factory = TrackingProtectionPolicyFactory(mockSettings(useStrict = true, useTrackingProtection = true)) + + val privateOnly = factory.createTrackingProtectionPolicy(normalMode = false, privateMode = true) + val normalOnly = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = false) + val always = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = true) + + assertEquals(privateOnly.cookiePurging, expected.cookiePurging) + assertEquals(normalOnly.cookiePurging, expected.cookiePurging) + assertEquals(always.cookiePurging, expected.cookiePurging) + } + + @Test + fun `GIVEN standard policy WHEN some tracking policies THEN purge cookies`() { + val expected = TrackingProtectionPolicy.recommended() + + val factory = TrackingProtectionPolicyFactory(mockSettings(useStrict = false, useCustom = false, useTrackingProtection = true)) + + val privateOnly = factory.createTrackingProtectionPolicy(normalMode = false, privateMode = true) + val normalOnly = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = false) + val always = factory.createTrackingProtectionPolicy(normalMode = true, privateMode = true) + + assertEquals(privateOnly.cookiePurging, expected.cookiePurging) + assertEquals(normalOnly.cookiePurging, expected.cookiePurging) + assertEquals(always.cookiePurging, expected.cookiePurging) + } } private fun mockSettings( @@ -408,8 +426,8 @@ private fun settingsForCustom( every { blockCryptominersInCustomTrackingProtection } returns blockCryptominers } -private fun EngineSession.TrackingProtectionPolicy.assertPolicyEquals( - actual: EngineSession.TrackingProtectionPolicy, +private fun TrackingProtectionPolicy.assertPolicyEquals( + actual: TrackingProtectionPolicy, checkPrivacy: Boolean ) { assertEquals(this.cookiePolicy, actual.cookiePolicy) @@ -426,16 +444,16 @@ private fun EngineSession.TrackingProtectionPolicy.assertPolicyEquals( } } -private fun Array.toInt(): Int { +private fun Array.toInt(): Int { return fold(initial = 0) { acc, next -> acc + next.id } } private val allTrackingCategories = arrayOf( - EngineSession.TrackingProtectionPolicy.TrackingCategory.AD, - EngineSession.TrackingProtectionPolicy.TrackingCategory.ANALYTICS, - EngineSession.TrackingProtectionPolicy.TrackingCategory.SOCIAL, - EngineSession.TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL, - EngineSession.TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES, - EngineSession.TrackingProtectionPolicy.TrackingCategory.FINGERPRINTING, - EngineSession.TrackingProtectionPolicy.TrackingCategory.CRYPTOMINING + TrackingProtectionPolicy.TrackingCategory.AD, + TrackingProtectionPolicy.TrackingCategory.ANALYTICS, + TrackingProtectionPolicy.TrackingCategory.SOCIAL, + TrackingProtectionPolicy.TrackingCategory.MOZILLA_SOCIAL, + TrackingProtectionPolicy.TrackingCategory.SCRIPTS_AND_SUB_RESOURCES, + TrackingProtectionPolicy.TrackingCategory.FINGERPRINTING, + TrackingProtectionPolicy.TrackingCategory.CRYPTOMINING ) 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 7bcdafe36b..eb56f1a028 100644 --- a/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelViewTest.kt @@ -19,6 +19,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.R 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 @RunWith(FenixRobolectricTestRunner::class) @@ -97,4 +98,13 @@ class TrackingProtectionPanelViewTest { view.social_media_trackers_loaded.performClick() verify { interactor.openDetails(SOCIAL_MEDIA_TRACKERS, categoryBlocked = false) } } + + @Test + fun testCrossSiteTrackerClick() { + view.cross_site_tracking.performClick() + verify { interactor.openDetails(CROSS_SITE_TRACKING_COOKIES, categoryBlocked = true) } + + view.cross_site_tracking_loaded.performClick() + verify { interactor.openDetails(CROSS_SITE_TRACKING_COOKIES, categoryBlocked = false) } + } }