Commit 42198274 authored by Sebastian Kaspari's avatar Sebastian Kaspari
Browse files

Issue #3432: feature-tab-collections: Restore Session objects and lists of...

Issue #3432: feature-tab-collections: Restore Session objects and lists of Sessions instead of a Snapshot.
parent aacccbd7
......@@ -184,15 +184,15 @@ class TabCollectionStorageTest {
val collection = collections[0]
val snapshot = collection.restore(context, FakeEngine(), restoreSessionId = true)
assertEquals(2, snapshot.sessions.size)
val sessions = collection.restore(context, FakeEngine(), restoreSessionId = true)
assertEquals(2, sessions.size)
// We restored the same sessions
assertEquals(session1, snapshot.sessions[0].session)
assertEquals(session2, snapshot.sessions[1].session)
assertEquals(session1, sessions[0])
assertEquals(session2, sessions[1])
assertEquals(session1.id, snapshot.sessions[0].session.id)
assertEquals(session2.id, snapshot.sessions[1].session.id)
assertEquals(session1.id, sessions[0].id)
assertEquals(session2.id, sessions[1].id)
}
getAllCollections().let { collections ->
......@@ -200,21 +200,21 @@ class TabCollectionStorageTest {
val collection = collections[0]
val snapshot = collection.restore(context, FakeEngine(), restoreSessionId = false)
assertEquals(2, snapshot.sessions.size)
val sessions = collection.restore(context, FakeEngine(), restoreSessionId = false)
assertEquals(2, sessions.size)
// The sessions are not the same but contain the same data
assertNotEquals(session1, snapshot.sessions[0].session)
assertNotEquals(session2, snapshot.sessions[1].session)
assertNotEquals(session1, sessions[0])
assertNotEquals(session2, sessions[1])
assertNotEquals(session1.id, snapshot.sessions[0].session.id)
assertNotEquals(session2.id, snapshot.sessions[1].session.id)
assertNotEquals(session1.id, sessions[0].id)
assertNotEquals(session2.id, sessions[1].id)
assertEquals(session1.url, snapshot.sessions[0].session.url)
assertEquals(session2.url, snapshot.sessions[1].session.url)
assertEquals(session1.url, sessions[0].url)
assertEquals(session2.url, sessions[1].url)
assertEquals(session1.title, snapshot.sessions[0].session.title)
assertEquals(session2.title, snapshot.sessions[1].session.title)
assertEquals(session1.title, sessions[0].title)
assertEquals(session2.title, sessions[1].title)
}
}
......
......@@ -45,8 +45,8 @@ class TabCollectionDaoTest {
@Test
fun testInsertingAndReadingCollections() {
val collection1 = TabCollectionEntity(title = "Collection One", createdAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", createdAt = 50)
val collection1 = TabCollectionEntity(title = "Collection One", updatedAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", updatedAt = 50)
tabCollectionDao.insertTabCollection(collection1)
tabCollectionDao.insertTabCollection(collection2)
......@@ -94,9 +94,9 @@ class TabCollectionDaoTest {
@Test
fun testRemovingCollections() {
val collection1 = TabCollectionEntity(title = "Collection One", createdAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", createdAt = 50)
val collection3 = TabCollectionEntity(title = "Collection Three", createdAt = 75)
val collection1 = TabCollectionEntity(title = "Collection One", updatedAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", updatedAt = 50)
val collection3 = TabCollectionEntity(title = "Collection Three", updatedAt = 75)
collection1.id = tabCollectionDao.insertTabCollection(collection1)
collection2.id = tabCollectionDao.insertTabCollection(collection2)
......@@ -120,8 +120,8 @@ class TabCollectionDaoTest {
@Test
fun testGettingCollectionsWithLimit() {
val collection1 = TabCollectionEntity(title = "Collection One", createdAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", createdAt = 50)
val collection1 = TabCollectionEntity(title = "Collection One", updatedAt = 10)
val collection2 = TabCollectionEntity(title = "Collection Two", updatedAt = 50)
collection1.id = tabCollectionDao.insertTabCollection(collection1)
collection2.id = tabCollectionDao.insertTabCollection(collection2)
......
......@@ -5,7 +5,6 @@
package mozilla.components.feature.tab.collections
import android.content.Context
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.Session
import mozilla.components.concept.engine.Engine
......@@ -29,7 +28,7 @@ interface Tab {
val url: String
/**
* Restores a single tab from this collection and returns a matching [SessionManager.Snapshot].
* Restores a single tab from this collection and returns a matching [Session].
*
* @param restoreSessionId If true the original [Session.id] of [Session]s will be restored. Otherwise a new ID
* will be generated. An app may prefer to use a new ID if it expects sessions to get restored multiple times -
......@@ -40,5 +39,5 @@ interface Tab {
engine: Engine,
tab: Tab,
restoreSessionId: Boolean = false
): SessionManager.Snapshot
): Session?
}
......@@ -6,7 +6,6 @@ package mozilla.components.feature.tab.collections
import android.content.Context
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.Engine
/**
......@@ -29,7 +28,7 @@ interface TabCollection {
val tabs: List<Tab>
/**
* Restores all tabs in this collection and returns a matching [SessionManager.Snapshot].
* Restores all tabs in this collection and returns a matching list of [Session] objects.
*
* @param restoreSessionId If true the original [Session.id] of [Session]s will be restored. Otherwise a new ID
* will be generated. An app may prefer to use a new ID if it expects sessions to get restored multiple times -
......@@ -39,10 +38,10 @@ interface TabCollection {
context: Context,
engine: Engine,
restoreSessionId: Boolean = false
): SessionManager.Snapshot
): List<Session>
/**
* Restores a subset of the tabs in this collection and returns a matching [SessionManager.Snapshot].
* Restores a subset of the tabs in this collection and returns a matching list of [Session] objects.
*
* @param restoreSessionId If true the original [Session.id] of [Session]s will be restored. Otherwise a new ID
* will be generated. An app may prefer to use a new ID if it expects sessions to get restored multiple times -
......@@ -53,5 +52,5 @@ interface TabCollection {
engine: Engine,
tabs: List<Tab>,
restoreSessionId: Boolean = false
): SessionManager.Snapshot
): List<Session>
}
......@@ -5,6 +5,7 @@
package mozilla.components.feature.tab.collections.adapter
import android.content.Context
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.ext.readSnapshotItem
import mozilla.components.concept.engine.Engine
......@@ -31,9 +32,10 @@ internal class TabAdapter(
engine: Engine,
tab: Tab,
restoreSessionId: Boolean
): SessionManager.Snapshot {
val item = entity.getStateFile(context.filesDir).readSnapshotItem(engine, restoreSessionId)
return SessionManager.Snapshot(if (item == null) emptyList() else listOf(item), SessionManager.NO_SELECTION)
): Session? {
return entity.getStateFile(context.filesDir)
.readSnapshotItem(engine, restoreSessionId)
?.session
}
override fun equals(other: Any?): Boolean {
......
......@@ -5,7 +5,7 @@
package mozilla.components.feature.tab.collections.adapter
import android.content.Context
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.ext.readSnapshotItem
import mozilla.components.concept.engine.Engine
import mozilla.components.feature.tab.collections.Tab
......@@ -29,7 +29,7 @@ internal class TabCollectionAdapter(
override val id: Long
get() = entity.collection.id!!
override fun restore(context: Context, engine: Engine, restoreSessionId: Boolean): SessionManager.Snapshot {
override fun restore(context: Context, engine: Engine, restoreSessionId: Boolean): List<Session> {
return restore(context, engine, entity.tabs, restoreSessionId)
}
......@@ -38,8 +38,10 @@ internal class TabCollectionAdapter(
engine: Engine,
tabs: List<Tab>,
restoreSessionId: Boolean
): SessionManager.Snapshot {
val entities = entity.tabs.filter { candidate -> tabs.find { tab -> tab.id == candidate.id } != null }
): List<Session> {
val entities = entity.tabs.filter {
candidate -> tabs.find { tab -> tab.id == candidate.id } != null
}
return restore(context, engine, entities, restoreSessionId)
}
......@@ -48,11 +50,10 @@ internal class TabCollectionAdapter(
engine: Engine,
tabs: List<TabEntity>,
restoreSessionId: Boolean
): SessionManager.Snapshot {
val items = tabs.mapNotNull { tab ->
tab.getStateFile(context.filesDir).readSnapshotItem(engine, restoreSessionId)
): List<Session> {
return tabs.mapNotNull { tab ->
tab.getStateFile(context.filesDir).readSnapshotItem(engine, restoreSessionId)?.session
}
return SessionManager.Snapshot(items, SessionManager.NO_SELECTION)
}
override fun equals(other: Any?): Boolean {
......
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