2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

Bug 1844557 - Disable the switch control when the add-on is blockedlisted.

This commit is contained in:
Arturo Mejia 2023-09-25 12:59:58 -04:00 committed by mergify[bot]
parent 6e813a62c7
commit 9740f5ed0a
2 changed files with 51 additions and 3 deletions

View File

@ -118,11 +118,24 @@ class InstalledAddonDetailsFragment : Fragment() {
bindRemoveButton()
}
@VisibleForTesting
internal fun provideEnableSwitch() = binding.enableSwitch
@VisibleForTesting
internal fun providePrivateBrowsingSwitch() = binding.allowInPrivateBrowsingSwitch
@VisibleForTesting
@SuppressWarnings("LongMethod")
private fun bindEnableSwitch() {
val switch = binding.enableSwitch
val privateBrowsingSwitch = binding.allowInPrivateBrowsingSwitch
internal fun bindEnableSwitch() {
val switch = provideEnableSwitch()
val privateBrowsingSwitch = providePrivateBrowsingSwitch()
switch.setState(addon.isEnabled())
// When the ad-on is blocklisted, we do not want to enable the toggle switch
// because users shouldn't be able to re-enable a blocklisted add-on.
if (addon.isDisabledAsBlocklisted()) {
switch.isEnabled = false
return
}
switch.setOnCheckedChangeListener { v, isChecked ->
val addonManager = v.context.components.addonManager
switch.isClickable = false

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.addons
import com.google.android.material.switchmaterial.SwitchMaterial
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
@ -62,4 +63,38 @@ class InstalledAddonDetailsFragmentTest {
verify { addonManager.enableAddon(addon, EnableSource.APP_SUPPORT, any(), any()) }
verify { addonManager.enableAddon(capturedAddon.captured, EnableSource.USER, any(), any()) }
}
@Test
fun `GIVEN blocklisted addon WHEN biding the enable switch THEN disable the switch`() {
val addon = mockk<Addon>()
val enableSwitch = mockk<SwitchMaterial>(relaxed = true)
val privateBrowsingSwitch = mockk<SwitchMaterial>(relaxed = true)
every { fragment.provideEnableSwitch() } returns enableSwitch
every { fragment.providePrivateBrowsingSwitch() } returns privateBrowsingSwitch
every { addon.isEnabled() } returns true
every { addon.isDisabledAsBlocklisted() } returns true
every { fragment.addon } returns addon
fragment.bindEnableSwitch()
verify { enableSwitch.isEnabled = false }
}
@Test
fun `GIVEN enabled addon WHEN biding the enable switch THEN do not disable the switch`() {
val addon = mockk<Addon>()
val enableSwitch = mockk<SwitchMaterial>(relaxed = true)
val privateBrowsingSwitch = mockk<SwitchMaterial>(relaxed = true)
every { fragment.provideEnableSwitch() } returns enableSwitch
every { fragment.providePrivateBrowsingSwitch() } returns privateBrowsingSwitch
every { addon.isDisabledAsBlocklisted() } returns false
every { addon.isEnabled() } returns true
every { fragment.addon } returns addon
fragment.bindEnableSwitch()
verify(exactly = 0) { enableSwitch.isEnabled = false }
}
}