Skip to content

Commit

Permalink
Closes mozilla-mobile#9109 update tracking protection status
Browse files Browse the repository at this point in the history
when removing an exception by url.
  • Loading branch information
Amejia481 committed Dec 3, 2020
1 parent 80bf71b commit 78b6bf1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/feature/session/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation project(':support-ktx')

implementation Dependencies.kotlin_stdlib
implementation Dependencies.androidx_core_ktx
implementation Dependencies.google_material
implementation Dependencies.androidx_swiperefreshlayout

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package mozilla.components.feature.session

import mozilla.components.browser.state.action.TrackingProtectionAction
import androidx.core.net.toUri
import mozilla.components.browser.state.selector.findTabOrCustomTabOrSelectedTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
Expand Down Expand Up @@ -71,6 +73,15 @@ class TrackingProtectionUseCases(
*/
operator fun invoke(exception: TrackingProtectionException) {
engine.trackingProtectionExceptionStore.remove(exception)
// Find all tabs that need to update their tracking protection status.
val tabs = (store.state.tabs + store.state.customTabs).filter { tab ->
val tabDomain = tab.content.url.toUri().host
val exceptionDomain = exception.url.toUri().host
tabDomain == exceptionDomain
}
tabs.forEach {
store.dispatch(TrackingProtectionAction.ToggleExclusionListAction(it.id, false))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

package mozilla.components.feature.session

import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.state.action.CustomTabListAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ContentState
import mozilla.components.browser.state.state.EngineState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.TrackingProtectionState
import mozilla.components.browser.state.state.createCustomTab
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.engine.EngineSession
Expand All @@ -17,6 +25,7 @@ import mozilla.components.concept.engine.content.blocking.TrackingProtectionExce
import mozilla.components.concept.engine.content.blocking.TrackingProtectionExceptionStorage
import mozilla.components.support.test.any
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.mock
import mozilla.components.support.test.whenever
import org.junit.Assert.assertFalse
Expand All @@ -25,9 +34,11 @@ import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.never
import org.mockito.Mockito.verify

@RunWith(AndroidJUnit4::class)
class TrackingProtectionUseCasesTest {
private lateinit var exceptionStore: TrackingProtectionExceptionStorage
private lateinit var engine: Engine
Expand Down Expand Up @@ -146,10 +157,47 @@ class TrackingProtectionUseCasesTest {

@Test
fun `remove a tracking protection exception`() {
val exception: TrackingProtectionException = mock()
val tab1 = createTab("https://www.mozilla.org")
.copy(trackingProtection = TrackingProtectionState(ignoredOnTrackingProtection = true))

val tab2 = createTab("https://wiki.mozilla.org/")
.copy(trackingProtection = TrackingProtectionState(ignoredOnTrackingProtection = true))

val tab3 = createTab("https://www.mozilla.org/en-CA/")
.copy(trackingProtection = TrackingProtectionState(ignoredOnTrackingProtection = true))

val customTab = createCustomTab("https://www.mozilla.org/en-CA/")
.copy(trackingProtection = TrackingProtectionState(ignoredOnTrackingProtection = true))

val exception = object : TrackingProtectionException {
override val url: String = tab1.content.url
}

store.dispatch(TabListAction.AddTabAction(tab1)).joinBlocking()
store.dispatch(TabListAction.AddTabAction(tab2)).joinBlocking()
store.dispatch(TabListAction.AddTabAction(tab3)).joinBlocking()
store.dispatch(CustomTabListAction.AddCustomTabAction(customTab)).joinBlocking()
store.waitUntilIdle()

assertTrue(store.state.findTab(tab1.id)!!.trackingProtection.ignoredOnTrackingProtection)
assertTrue(store.state.findTab(tab2.id)!!.trackingProtection.ignoredOnTrackingProtection)
assertTrue(store.state.findTab(tab3.id)!!.trackingProtection.ignoredOnTrackingProtection)
assertTrue(store.state.findCustomTab(customTab.id)!!.trackingProtection.ignoredOnTrackingProtection)

useCases.removeException(exception)

verify(exceptionStore).remove(exception)

store.waitUntilIdle()

assertFalse(store.state.findTab(tab1.id)!!.trackingProtection.ignoredOnTrackingProtection)

// Different domain from tab1 MUST not be affected
assertTrue(store.state.findTab(tab2.id)!!.trackingProtection.ignoredOnTrackingProtection)

// Another tabs with the same domain as tab1 MUST be updated
assertFalse(store.state.findTab(tab3.id)!!.trackingProtection.ignoredOnTrackingProtection)
assertFalse(store.state.findCustomTab(customTab.id)!!.trackingProtection.ignoredOnTrackingProtection)
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ permalink: /changelog/
* 🚒 Bug fixed [issue #9033](https://github.com/mozilla-mobile/android-components/issues/9033) - Fix resuming downloads in slow networks more details see the [Fenix issue](https://github.com/mozilla-mobile/fenix/issues/9354#issuecomment-731267368).
* 🚒 Bug fixed [issue #9073](https://github.com/mozilla-mobile/android-components/issues/9073) - Fix crash downloading a file with multiple dots on it, for more details see the [Fenix issue](https://github.com/mozilla-mobile/fenix/issues/16443).

* **feature-session**
* 🚒 Bug fixed [issue #9109](https://github.com/mozilla-mobile/android-components/issues/9109) - Tracking protection shield not getting updated after deleting exception by url [Fenix issue](https://github.com/mozilla-mobile/fenix/issues/16670).

* **feature-app-links**
* Added handling of PackageItemInfo.packageName NullPointerException on some Xiaomi and TCL devices

Expand Down

0 comments on commit 78b6bf1

Please sign in to comment.