Skip to content

Commit

Permalink
Issue mozilla-mobile#9899: (Merge day) browser-engine-gecko-beta (87)…
Browse files Browse the repository at this point in the history
… -> browser-engine-gecko-release (87)
  • Loading branch information
jonalmeida authored and mergify[bot] committed Mar 16, 2021
1 parent eeaa43b commit 563a918
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 18 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Gecko.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal object GeckoVersions {
/**
* GeckoView Release Version.
*/
const val release_version = "86.0.20210310152336"
const val release_version = "87.0.20210315170302"
}

@Suppress("Unused", "MaxLineLength")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class GeckoEngineSession(
}

geckoSession.load(loader)
Fact(Component.BROWSER_ENGINE_GECKO_NIGHTLY, Action.IMPLEMENTATION_DETAIL, "GeckoSession.load").collect()
Fact(Component.BROWSER_ENGINE_GECKO_BETA, Action.IMPLEMENTATION_DETAIL, "GeckoSession.load").collect()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class GeckoEngineSession(
}

geckoSession.load(loader)
Fact(Component.BROWSER_ENGINE_GECKO_BETA, Action.IMPLEMENTATION_DETAIL, "GeckoSession.load").collect()
Fact(Component.BROWSER_ENGINE_GECKO, Action.IMPLEMENTATION_DETAIL, "GeckoSession.load").collect()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class GeckoEngineView @JvmOverloads constructor(
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var currentSelection: BasicSelectionActionDelegate? = null

/**
* Cache of the last valid input result we got from GeckoView.
*/
@VisibleForTesting
internal var lastInputResult: EngineView.InputResult = EngineView.InputResult.INPUT_RESULT_UNHANDLED

override var selectionActionDelegate: SelectionActionDelegate? = null

init {
Expand Down Expand Up @@ -174,12 +180,19 @@ class GeckoEngineView @JvmOverloads constructor(
// Direct mapping of GeckoView's returned values.
// If not fail fast to allow for a quick fix.
val input = geckoView.inputResult
return when (input) {
lastInputResult = when (input) {
0 -> EngineView.InputResult.INPUT_RESULT_UNHANDLED
1, 3 -> EngineView.InputResult.INPUT_RESULT_HANDLED
1 -> EngineView.InputResult.INPUT_RESULT_HANDLED
2 -> EngineView.InputResult.INPUT_RESULT_HANDLED_CONTENT
else -> throw IllegalArgumentException("Unexpected geckoView.inputResult: \"${geckoView.inputResult}\"")
3 -> {
// Drop this result and return the previous.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1687430 for details
lastInputResult
}
else -> throw IllegalArgumentException("Unexpected geckoView.inputResult: \"$input\"")
}

return lastInputResult
}

override fun setVerticalClipping(clippingHeight: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import mozilla.components.browser.engine.gecko.GeckoEngineSession
import mozilla.components.browser.engine.gecko.await
import mozilla.components.concept.engine.mediasession.MediaSession
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.Image.ImageProcessingException
import org.mozilla.geckoview.MediaSession as GeckoViewMediaSession

private const val ARTWORK_RETRIEVE_TIMEOUT = 1000L
Expand Down Expand Up @@ -51,7 +52,7 @@ internal class GeckoMediaSessionDelegate(
}

bitmap
} catch (e: IllegalArgumentException) {
} catch (e: ImageProcessingException) {
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GeckoWebExtension(
val runtime: GeckoRuntime
) : WebExtension(nativeExtension.id, nativeExtension.location, true) {

private val connectedPorts: MutableMap<PortId, Port> = mutableMapOf()
private val connectedPorts: MutableMap<PortId, GeckoPort> = mutableMapOf()
private val logger = Logger("GeckoWebExtension")

/**
Expand All @@ -58,8 +58,11 @@ class GeckoWebExtension(
}

override fun onDisconnect(port: GeckoNativeWebExtension.Port) {
connectedPorts.remove(PortId(name))
messageHandler.onPortDisconnected(GeckoPort(port))
val connectedPort = connectedPorts[PortId(name)]
if (connectedPort != null && connectedPort.nativePort == port) {
connectedPorts.remove(PortId(name))
messageHandler.onPortDisconnected(GeckoPort(port))
}
}
}

Expand Down Expand Up @@ -97,9 +100,11 @@ class GeckoWebExtension(
}

override fun onDisconnect(port: GeckoNativeWebExtension.Port) {
val geckoPort = GeckoPort(port, session)
connectedPorts.remove(PortId(name, session))
messageHandler.onPortDisconnected(geckoPort)
val connectedPort = connectedPorts[PortId(name, session)]
if (connectedPort != null && connectedPort.nativePort == port) {
connectedPorts.remove(PortId(name, session))
messageHandler.onPortDisconnected(connectedPort)
}
}
}

Expand Down Expand Up @@ -241,6 +246,7 @@ class GeckoWebExtension(
* See [WebExtension.registerTabHandler].
*/
override fun registerTabHandler(tabHandler: TabHandler, defaultSettings: Settings?) {

val tabDelegate = object : GeckoNativeWebExtension.TabDelegate {

override fun onNewTab(
Expand All @@ -252,6 +258,7 @@ class GeckoWebExtension(
defaultSettings = defaultSettings,
openGeckoSession = false
)

tabHandler.onNewTab(
this@GeckoWebExtension,
geckoEngineSession,
Expand All @@ -265,7 +272,8 @@ class GeckoWebExtension(
ext.metaData.optionsPageUrl?.let { optionsPageUrl ->
tabHandler.onNewTab(
this@GeckoWebExtension,
GeckoEngineSession(runtime, defaultSettings = defaultSettings),
GeckoEngineSession(runtime,
defaultSettings = defaultSettings),
false,
optionsPageUrl
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ class GeckoEngineSessionTest {
}

@Test
fun `WHEN updating content blocking with a policy SCRIPTS_AND_SUB_RESOURCES useForPrivateSessions being in privateMode THEN useTrackingProtection should be true`() {
fun `WHEN update content blocking with a policy SCRIPTS_AND_SUB_RESOURCES useForPrivateSessions being in privateMode THEN useTrackingProtection should be true`() {
val geckoSetting = mock<GeckoSessionSettings>()
val geckoSession = mock<GeckoSession>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.engine.gecko.GeckoEngineView.Companion.DARK_COVER
import mozilla.components.browser.engine.gecko.selection.GeckoSelectionActionDelegate
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
import mozilla.components.concept.engine.selection.SelectionActionDelegate
import mozilla.components.support.test.argumentCaptor
Expand All @@ -32,7 +33,6 @@ import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.MockSelection
import org.robolectric.Robolectric.buildActivity
import java.lang.IllegalStateException

@RunWith(AndroidJUnit4::class)
class GeckoEngineViewTest {
Expand Down Expand Up @@ -277,4 +277,52 @@ class GeckoEngineViewTest {
whenever(engineView.currentSelection?.selection).thenReturn(selectionWthEmptyText)
assertFalse(engineView.canClearSelection())
}

@Test
fun `currentInputResult should default to EngineView#InputResult#INPUT_RESULT_UNHANDLED`() {
val engineView = GeckoEngineView(context)

assertEquals(EngineView.InputResult.INPUT_RESULT_UNHANDLED, engineView.lastInputResult)
}

@Test
fun `getInputResult should do a 1-1 mapping of the values received from GeckoView and cache the result`() {
val engineView = GeckoEngineView(context)
engineView.geckoView = mock()

whenever(engineView.geckoView.inputResult).thenReturn(0)
assertEquals(EngineView.InputResult.INPUT_RESULT_UNHANDLED, engineView.getInputResult())
assertEquals(EngineView.InputResult.INPUT_RESULT_UNHANDLED, engineView.lastInputResult)

whenever(engineView.geckoView.inputResult).thenReturn(1)
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.getInputResult())
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.lastInputResult)

whenever(engineView.geckoView.inputResult).thenReturn(2)
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED_CONTENT, engineView.getInputResult())
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED_CONTENT, engineView.lastInputResult)
}

@Test
fun `INPUT_RESULD_IGNORED should be ignored`() {
val engineView = GeckoEngineView(context)
engineView.geckoView = mock()

whenever(engineView.geckoView.inputResult).thenReturn(1)
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.getInputResult())
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.lastInputResult)

whenever(engineView.geckoView.inputResult).thenReturn(3)
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.getInputResult())
assertEquals(EngineView.InputResult.INPUT_RESULT_HANDLED, engineView.lastInputResult)
}

@Test(expected = IllegalArgumentException::class)
fun `Values other than 0, 1, 2, 3 received as input results from GeckoView should throw`() {
val engineView = GeckoEngineView(context)
engineView.geckoView = mock()

whenever(engineView.geckoView.inputResult).thenReturn(4)
engineView.getInputResult()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class GeckoWebExtensionTest {
verify(messageHandler).onPortMessage(eq(portMessage), portCaptor.capture())
assertSame(port, (portCaptor.value as GeckoPort).nativePort)

// Verify disconnected port is forwarded to message handler
// Verify disconnected port is forwarded to message handler if connected
portDelegate.onDisconnect(mock())
verify(messageHandler, never()).onPortDisconnected(portCaptor.capture())

portDelegate.onDisconnect(port)
verify(messageHandler).onPortDisconnected(portCaptor.capture())
assertSame(port, (portCaptor.value as GeckoPort).nativePort)
Expand Down Expand Up @@ -146,7 +149,10 @@ class GeckoWebExtensionTest {
assertSame(port, (portCaptor.value as GeckoPort).nativePort)
assertSame(session, (portCaptor.value as GeckoPort).engineSession)

// Verify disconnected port is forwarded to message handler
// Verify disconnected port is forwarded to message handler if connected
portDelegate.onDisconnect(mock())
verify(messageHandler, never()).onPortDisconnected(portCaptor.capture())

portDelegate.onDisconnect(port)
verify(messageHandler).onPortDisconnected(portCaptor.capture())
assertSame(port, (portCaptor.value as GeckoPort).nativePort)
Expand Down

0 comments on commit 563a918

Please sign in to comment.