Commit 17a8f777 authored by Christian Sadilek's avatar Christian Sadilek Committed by Jonathan Almeida
Browse files

Closes #2174: ReaderViewFeature crashes with SystemEngine

parent a24b3dd7
......@@ -64,13 +64,14 @@ interface Engine {
* @param ext the [WebExtension] to install.
* @param onSuccess (optional) callback invoked if the extension was installed successfully.
* @param onError (optional) callback invoked if there was an error installing the extension.
* @throws UnsupportedOperationException if this engine doesn't support web extensions.
* This callback is invoked with an [UnsupportedOperationException] in case the engine doesn't
* have web extension support.
*/
fun installWebExtension(
ext: WebExtension,
onSuccess: ((WebExtension) -> Unit) = { },
onError: ((WebExtension, Throwable) -> Unit) = { _, _ -> }
): Unit = throw UnsupportedOperationException("Web extension support is not available in this engine")
): Unit = onError(ext, UnsupportedOperationException("Web extension support is not available in this engine"))
/**
* Provides access to the settings of this engine.
......
......@@ -8,14 +8,15 @@ import android.content.Context
import android.util.AttributeSet
import mozilla.components.concept.engine.webextension.WebExtension
import org.json.JSONObject
import org.junit.Assert.fail
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
import java.lang.UnsupportedOperationException
class EngineTest {
@Test
fun `throws exception if webextensions not supported`() {
fun `invokes error callback if webextensions not supported`() {
val engine = object : Engine {
override fun createView(context: Context, attrs: AttributeSet?): EngineView {
throw NotImplementedError("Not needed for test")
......@@ -41,32 +42,9 @@ class EngineTest {
get() = throw NotImplementedError("Not needed for test")
}
try {
engine.installWebExtension(WebExtension("my-ext", "resource://path"))
fail("Expected UnsupportedOperationException")
} catch (_: UnsupportedOperationException) {
// expected
}
try {
engine.installWebExtension(WebExtension("my-ext", "resource://path")) { _, _ -> }
fail("Expected UnsupportedOperationException")
} catch (_: UnsupportedOperationException) {
// expected
}
try {
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { })
fail("Expected UnsupportedOperationException")
} catch (_: UnsupportedOperationException) {
// expected
}
try {
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { }) { _, _ -> }
fail("Expected UnsupportedOperationException")
} catch (_: UnsupportedOperationException) {
// expected
}
var exception: Throwable? = null
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onError = { _, e -> exception = e })
assertNotNull(exception)
assertTrue(exception is UnsupportedOperationException)
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment