2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/18367 run SupportedAddonsChecker only for users with unsupported extensions

This commit is contained in:
Arturo Mejia 2021-03-12 08:21:34 -05:00
parent 6fff411a12
commit d296d0c9c2
2 changed files with 55 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import android.os.Build.VERSION.SDK_INT
import android.os.StrictMode
import android.util.Log.INFO
import androidx.annotation.CallSuper
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.getSystemService
import androidx.work.Configuration.Builder
@ -23,7 +24,10 @@ import mozilla.appservices.Megazord
import mozilla.components.browser.state.action.SystemAction
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.concept.base.crash.Breadcrumb
import mozilla.components.concept.engine.webextension.WebExtension
import mozilla.components.concept.engine.webextension.isUnsupported
import mozilla.components.concept.push.PushProcessor
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.service.glean.Glean
@ -447,7 +451,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
},
onExtensionsLoaded = { extensions ->
components.addonUpdater.registerForFutureUpdates(extensions)
components.supportedAddonsChecker.registerForChecks()
subscribeForNewAddonsIfNeeded(components.supportedAddonsChecker, extensions)
},
onUpdatePermissionRequest = components.addonUpdater::onUpdatePermissionRequest
)
@ -456,6 +460,21 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
}
}
@VisibleForTesting
internal fun subscribeForNewAddonsIfNeeded(
checker: DefaultSupportedAddonsChecker,
installedExtensions: List<WebExtension>
) {
val hasUnsupportedAddons = installedExtensions.any { it.isUnsupported() }
if (hasUnsupportedAddons) {
checker.registerForChecks()
} else {
// As checks are a persistent subscriptions, we have to make sure
// we remove any previous subscriptions.
checker.unregisterForChecks()
}
}
protected fun recordOnInit() {
// This gets called by more than one process. Ideally we'd only run this in the main process
// but the code to check which process we're in crashes because the Context isn't valid yet.

View File

@ -5,6 +5,13 @@
package org.mozilla.fenix
import androidx.test.core.app.ApplicationProvider
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.concept.engine.webextension.DisabledFlags
import mozilla.components.concept.engine.webextension.Metadata
import mozilla.components.concept.engine.webextension.WebExtension
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
import mozilla.components.service.glean.testing.GleanTestRule
import org.junit.Assert.assertTrue
import org.junit.Before
@ -34,4 +41,32 @@ class FenixApplicationTest {
// https://robolectric.blogspot.com/2013/04/the-test-lifecycle-in-20.html
assertTrue(PerfStartup.applicationOnCreate.testHasValue())
}
@Test
fun `GIVEN there are unsupported addons installed WHEN subscribing for new add-ons checks THEN register for checks`() {
val checker = mockk<DefaultSupportedAddonsChecker>(relaxed = true)
val unSupportedExtension: WebExtension = mockk()
val metadata: Metadata = mockk()
every { unSupportedExtension.getMetadata() } returns metadata
every { metadata.disabledFlags } returns DisabledFlags.select(DisabledFlags.APP_SUPPORT)
application.subscribeForNewAddonsIfNeeded(checker, listOf(unSupportedExtension))
verify { checker.registerForChecks() }
}
@Test
fun `GIVEN there are no unsupported addons installed WHEN subscribing for new add-ons checks THEN unregister for checks`() {
val checker = mockk<DefaultSupportedAddonsChecker>(relaxed = true)
val unSupportedExtension: WebExtension = mockk()
val metadata: Metadata = mockk()
every { unSupportedExtension.getMetadata() } returns metadata
every { metadata.disabledFlags } returns DisabledFlags.select(DisabledFlags.USER)
application.subscribeForNewAddonsIfNeeded(checker, listOf(unSupportedExtension))
verify { checker.unregisterForChecks() }
}
}