Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
[components] Closes mozilla-mobile/android-components#8113: Remove lo…
Browse files Browse the repository at this point in the history
…gic to reset private browsing setting for extensions
  • Loading branch information
csadilek authored and mergify[bot] committed Dec 3, 2020
1 parent a3e8840 commit 70941b7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class GeckoEngine(
) : Engine, WebExtensionRuntime {
private val executor by lazy { executorProvider.invoke() }
private val localeUpdater = LocaleSettingUpdater(context, runtime)
private val sharedPref = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
@VisibleForTesting internal val speculativeConnectionFactory = SpeculativeSessionFactory()
private var webExtensionDelegate: WebExtensionDelegate? = null
private val webExtensionActionHandler = object : ActionHandler {
Expand Down Expand Up @@ -331,23 +330,11 @@ class GeckoEngine(
extension -> GeckoWebExtension(extension, runtime)
} ?: emptyList()

val privateBrowsingMigrated = sharedPref.getBoolean(MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT, false)
extensions.forEach { extension ->
// As a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1621385,
// we set all installed extensions to be allowed in private browsing mode.
// We need to revert back to false which is now the default.
if (!extension.isBuiltIn() && extension.isAllowedInPrivateBrowsing() && !privateBrowsingMigrated) {
setAllowedInPrivateBrowsing(extension, false)
}

extension.registerActionHandler(webExtensionActionHandler)
extension.registerTabHandler(webExtensionTabHandler)
}

if (!privateBrowsingMigrated) {
sharedPref.edit().putBoolean(MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT, true).apply()
}

onSuccess(extensions)
GeckoResult<Void>()
}, { throwable ->
Expand Down Expand Up @@ -720,13 +707,6 @@ class GeckoEngine(
cookiesHasBeenBlocked = cookiesHasBeenBlocked
)
}

companion object {
private const val PREFERENCE_NAME =
"MOZAC_GECKO_ENGINE"
private const val MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT =
"MOZAC_HAS_RESET_WEBEXT_PRIVATE_BROWSING_DEFAULT"
}
}

internal fun ContentBlockingController.LogEntry.BlockingData.hasBlockedCookies(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,49 +1352,6 @@ class GeckoEngineTest {
assertNotNull(extensions)
}

@Test
fun `migrate private browsing default`() {
val bundle = GeckoBundle()
bundle.putString("webExtensionId", "id")
bundle.putString("locationURI", "uri")
val metaDataBundle = GeckoBundle()
metaDataBundle.putBoolean("privateBrowsingAllowed", true)
metaDataBundle.putStringArray("disabledFlags", emptyArray())
bundle.putBundle("metaData", metaDataBundle)
val installedExtension = MockWebExtension(bundle)

val installedExtensions = listOf<GeckoWebExtension>(installedExtension)
val installedExtensionResult = GeckoResult<List<GeckoWebExtension>>()

val runtime = mock<GeckoRuntime>()
val extensionController: WebExtensionController = mock()
whenever(extensionController.list()).thenReturn(installedExtensionResult)
whenever(runtime.webExtensionController).thenReturn(extensionController)

val allowedInPrivateBrowsingExtensionResult = GeckoResult<GeckoWebExtension>()
whenever(extensionController.setAllowedInPrivateBrowsing(any(), anyBoolean())).thenReturn(allowedInPrivateBrowsingExtensionResult)

val engine = spy(GeckoEngine(testContext, runtime = runtime))
var extensions: List<WebExtension>? = null
var onErrorCalled = false

engine.listInstalledWebExtensions(
onSuccess = { extensions = it },
onError = { onErrorCalled = true }
)
installedExtensionResult.complete(installedExtensions)
assertFalse(onErrorCalled)
assertNotNull(extensions)
val installedWebExtension = extensions!![0]
verify(engine, times(1)).setAllowedInPrivateBrowsing(eq(installedWebExtension), eq(false), any(), any())

engine.listInstalledWebExtensions(
onSuccess = { extensions = it },
onError = { onErrorCalled = true }
)
verify(engine, times(1)).setAllowedInPrivateBrowsing(eq(installedWebExtension), eq(false), any(), any())
}

@Test
fun `list web extensions failure`() {
val installedExtensionResult = GeckoResult<List<GeckoWebExtension>>()
Expand Down

0 comments on commit 70941b7

Please sign in to comment.