Skip to content
Snippets Groups Projects
Commit 608cc56b authored by Arturo Mejia's avatar Arturo Mejia Committed by mergify[bot]
Browse files

Bug 1838321 - Address NullPointerException when trying to setAllowedInPrivateBrowsing.

(cherry picked from commit 94e4d18528569421b7435626ae625a028166959f)
parent da36b477
No related branches found
No related tags found
No related merge requests found
......@@ -458,10 +458,19 @@ class GeckoEngine(
(extension as GeckoWebExtension).nativeExtension,
allowed,
).then(
{
val ext = GeckoWebExtension(it!!, runtime)
webExtensionDelegate?.onAllowedInPrivateBrowsingChanged(ext)
onSuccess(ext)
{ geckoExtension ->
if (geckoExtension == null) {
onError(
Exception(
"Gecko extension was not returned after trying to" +
" setAllowedInPrivateBrowsing with value $allowed",
),
)
} else {
val ext = GeckoWebExtension(geckoExtension, runtime)
webExtensionDelegate?.onAllowedInPrivateBrowsingChanged(ext)
onSuccess(ext)
}
GeckoResult<Void>()
},
{ throwable ->
......
......@@ -1758,6 +1758,43 @@ class GeckoEngineTest {
verify(webExtensionsDelegate, never()).onAllowedInPrivateBrowsingChanged(any())
}
@Test
fun `GIVEN null native extension WHEN calling setAllowedInPrivateBrowsing THEN call onError`() {
val runtime = mock<GeckoRuntime>()
val extensionController: WebExtensionController = mock()
val allowedInPrivateBrowsingExtensionResult = GeckoResult<GeckoWebExtension>()
whenever(extensionController.setAllowedInPrivateBrowsing(any(), anyBoolean())).thenReturn(
allowedInPrivateBrowsingExtensionResult,
)
whenever(runtime.webExtensionController).thenReturn(extensionController)
val engine = GeckoEngine(context, runtime = runtime)
val webExtensionsDelegate: WebExtensionDelegate = mock()
engine.registerWebExtensionDelegate(webExtensionsDelegate)
val extension = mozilla.components.browser.engine.gecko.webextension.GeckoWebExtension(
mockNativeWebExtension(),
runtime,
)
var result: WebExtension? = null
var throwable: Throwable? = null
engine.setAllowedInPrivateBrowsing(
extension,
true,
onSuccess = { ext -> result = ext },
onError = { throwable = it },
)
allowedInPrivateBrowsingExtensionResult.complete(null)
shadowOf(getMainLooper()).idle()
assertNotNull(throwable)
assertNull(result)
verify(webExtensionsDelegate, never()).onAllowedInPrivateBrowsingChanged(any())
}
@Test(expected = RuntimeException::class)
fun `WHEN GeckoRuntime is shutting down THEN GeckoEngine throws runtime exception`() {
val runtime: GeckoRuntime = mock()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment