Commit 67b38970 authored by MozLando's avatar MozLando
Browse files

Merge #6787

6787: Closes #6783: Engine session state is not restored r=pocmo a=csadilek

Regression is fairly recent and my mistake. 

Introduced by this change:

We now use the wrong key to look up the engine session JSON object. We use `Keys.SESSION_KEY` instead of `Keys.ENGINE_SESSION_KEY`. 🤦


I've also add a unit test here so this doesn't happen again.  
Co-authored-by: default avatarChristian Sadilek <>
parents 1c05f7c1 8cbf5ae3
......@@ -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(
......@@ -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
......@@ -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)
fun `Serialize and deserialize with engine session state`() {
val engineSessionState: EngineSessionState = mock()
val engineSessionJson = JSONObject().apply { put("state", "test") }
val engineSession: EngineSession = mock()
val engine: Engine = mock()
val restoredEngineSessionState: EngineSessionState = mock()
val originalSession = Session(
source = Session.Source.ACTION_VIEW,
id = "test-id",
contextId = "test-context-id"
).apply {
title = "Hello World"
val serializer = SnapshotSerializer()
val json = serializer.itemToJSON(
engineSession = engineSession
val restoredItem = serializer.itemFromJSON(engine, json)
assertEquals("", restoredItem.session.url)
assertEquals(Session.Source.RESTORED, restoredItem.session.source)
assertEquals("test-context-id", restoredItem.session.contextId)
assertEquals("Hello World", restoredItem.session.title)
assertSame(restoredEngineSessionState, restoredItem.engineSessionState)
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