Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit 17a8f77

Browse files
csadilekjonalmeida
authored andcommitted
Closes #2174: ReaderViewFeature crashes with SystemEngine
1 parent a24b3dd commit 17a8f77

File tree

2 files changed

+10
-31
lines changed
  • components/concept/engine/src

2 files changed

+10
-31
lines changed

components/concept/engine/src/main/java/mozilla/components/concept/engine/Engine.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ interface Engine {
6464
* @param ext the [WebExtension] to install.
6565
* @param onSuccess (optional) callback invoked if the extension was installed successfully.
6666
* @param onError (optional) callback invoked if there was an error installing the extension.
67-
* @throws UnsupportedOperationException if this engine doesn't support web extensions.
67+
* This callback is invoked with an [UnsupportedOperationException] in case the engine doesn't
68+
* have web extension support.
6869
*/
6970
fun installWebExtension(
7071
ext: WebExtension,
7172
onSuccess: ((WebExtension) -> Unit) = { },
7273
onError: ((WebExtension, Throwable) -> Unit) = { _, _ -> }
73-
): Unit = throw UnsupportedOperationException("Web extension support is not available in this engine")
74+
): Unit = onError(ext, UnsupportedOperationException("Web extension support is not available in this engine"))
7475

7576
/**
7677
* Provides access to the settings of this engine.

components/concept/engine/src/test/java/mozilla/components/concept/engine/EngineTest.kt

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import android.content.Context
88
import android.util.AttributeSet
99
import mozilla.components.concept.engine.webextension.WebExtension
1010
import org.json.JSONObject
11-
import org.junit.Assert.fail
11+
import org.junit.Assert.assertNotNull
12+
import org.junit.Assert.assertTrue
1213
import org.junit.Test
1314
import java.lang.UnsupportedOperationException
1415

1516
class EngineTest {
1617

1718
@Test
18-
fun `throws exception if webextensions not supported`() {
19+
fun `invokes error callback if webextensions not supported`() {
1920
val engine = object : Engine {
2021
override fun createView(context: Context, attrs: AttributeSet?): EngineView {
2122
throw NotImplementedError("Not needed for test")
@@ -41,32 +42,9 @@ class EngineTest {
4142
get() = throw NotImplementedError("Not needed for test")
4243
}
4344

44-
try {
45-
engine.installWebExtension(WebExtension("my-ext", "resource://path"))
46-
fail("Expected UnsupportedOperationException")
47-
} catch (_: UnsupportedOperationException) {
48-
// expected
49-
}
50-
51-
try {
52-
engine.installWebExtension(WebExtension("my-ext", "resource://path")) { _, _ -> }
53-
fail("Expected UnsupportedOperationException")
54-
} catch (_: UnsupportedOperationException) {
55-
// expected
56-
}
57-
58-
try {
59-
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { })
60-
fail("Expected UnsupportedOperationException")
61-
} catch (_: UnsupportedOperationException) {
62-
// expected
63-
}
64-
65-
try {
66-
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { }) { _, _ -> }
67-
fail("Expected UnsupportedOperationException")
68-
} catch (_: UnsupportedOperationException) {
69-
// expected
70-
}
45+
var exception: Throwable? = null
46+
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onError = { _, e -> exception = e })
47+
assertNotNull(exception)
48+
assertTrue(exception is UnsupportedOperationException)
7149
}
7250
}

0 commit comments

Comments
 (0)