Skip to content

Commit

Permalink
Issue mozilla-mobile#2624: Reader mode not always enabled after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek committed May 1, 2019
1 parent af03128 commit 1dbfb52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ class ReaderViewFeature(
checkReaderable()
}

override fun onLoadingStateChanged(session: Session, loading: Boolean) {
// If the page was refreshed and reader mode was turned on before,
// make sure it is still turned on.
if (!loading && activeSession?.readerMode == true) {
showReaderView()
}
}

override fun onReaderableStateUpdated(session: Session, readerable: Boolean) {
onReaderViewAvailableChange(readerable)
}
Expand Down Expand Up @@ -211,6 +203,9 @@ class ReaderViewFeature(
override fun onPortConnected(port: Port) {
ports[port.engineSession] = port
checkReaderable()
if (activeSession?.readerMode == true) {
showReaderView()
}
}

override fun onPortDisconnected(port: Port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ class ReaderViewFeatureTest {

messageHandler.value.onPortConnected(port)
assertTrue(ReaderViewFeature.ports.containsValue(port))
verify(readerViewFeature).checkReaderable()
verify(readerViewFeature, never()).showReaderView()

`when`(session.readerMode).thenReturn(true)
messageHandler.value.onPortConnected(port)
verify(readerViewFeature).showReaderView()

val message = JSONObject().put("readerable", true)
messageHandler.value.onPortMessage(message, port)
val readerableMessage = JSONObject().put("readerable", true)
messageHandler.value.onPortMessage(readerableMessage, port)
verify(session).readerable = true

messageHandler.value.onPortDisconnected(port)
Expand Down Expand Up @@ -343,21 +349,6 @@ class ReaderViewFeatureTest {
verify(port, times(1)).postMessage(message.capture())
}

@Test
fun `reader view still shown after page reload`() {
val port: Port = mock()
val message = argumentCaptor<JSONObject>()
val selectedSession: Session = mock()
`when`(selectedSession.readerMode).thenReturn(true)

val readerViewFeature = prepareFeatureForTest(port, selectedSession)
readerViewFeature.observeSelected()
readerViewFeature.onLoadingStateChanged(selectedSession, false)

verify(port, times(1)).postMessage(message.capture())
assertEquals(ReaderViewFeature.ACTION_SHOW, message.value[ReaderViewFeature.ACTION_MESSAGE_KEY])
}

private fun prepareFeatureForTest(port: Port, session: Session = mock()): ReaderViewFeature {
val engine = mock(Engine::class.java)
val sessionManager: SessionManager = mock()
Expand Down

0 comments on commit 1dbfb52

Please sign in to comment.