Commit 8cbf5ae3 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #6783: Engine session state is not restored

parent 6543e2c0
......@@ -82,10 +82,11 @@ class SnapshotSerializer(
fun itemFromJSON(engine: Engine, json: JSONObject): SessionManager.Snapshot.Item {
val sessionJson = json.getJSONObject(Keys.SESSION_KEY)
val engineSessionJson = json.getJSONObject(Keys.ENGINE_SESSION_KEY)
val session = deserializeSession(sessionJson, restoreSessionIds, restoreParentIds)
val readerState =
ReaderState(active = sessionJson.optBoolean(Keys.SESSION_READER_MODE_KEY, false))
val engineState = engine.createSessionState(sessionJson)
val engineState = engine.createSessionState(engineSessionJson)
return SessionManager.Snapshot.Item(
session,
......
......@@ -9,6 +9,8 @@ import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager.Snapshot
import mozilla.components.browser.state.state.ReaderState
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineSessionState
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import mozilla.components.support.test.whenever
......@@ -16,6 +18,7 @@ import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
......@@ -44,6 +47,44 @@ class SnapshotSerializerTest {
assertEquals("Hello World", restoredSession.title)
}
@Test
fun `Serialize and deserialize with engine session state`() {
val engineSessionState: EngineSessionState = mock()
val engineSessionJson = JSONObject().apply { put("state", "test") }
val engineSession: EngineSession = mock()
whenever(engineSession.saveState()).thenReturn(engineSessionState)
whenever(engineSessionState.toJSON()).thenReturn(engineSessionJson)
val engine: Engine = mock()
val restoredEngineSessionState: EngineSessionState = mock()
whenever(engine.createSessionState(engineSessionJson)).thenReturn(restoredEngineSessionState)
val originalSession = Session(
"https://www.mozilla.org",
source = Session.Source.ACTION_VIEW,
id = "test-id",
contextId = "test-context-id"
).apply {
title = "Hello World"
}
val serializer = SnapshotSerializer()
val json = serializer.itemToJSON(
Snapshot.Item(
originalSession,
engineSession = engineSession
)
)
val restoredItem = serializer.itemFromJSON(engine, json)
assertEquals("https://www.mozilla.org", restoredItem.session.url)
assertEquals(Session.Source.RESTORED, restoredItem.session.source)
assertEquals("test-id", restoredItem.session.id)
assertEquals("test-context-id", restoredItem.session.contextId)
assertEquals("Hello World", restoredItem.session.title)
assertSame(restoredEngineSessionState, restoredItem.engineSessionState)
}
@Test
fun `Serialize and deserialize session with reader state`() {
val engine: Engine = mock()
......
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