Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Close #10984: Persist search term in content state
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger authored and mergify[bot] committed Sep 15, 2021
1 parent 50914d9 commit 823681c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
Expand Up @@ -167,6 +167,7 @@ private fun JsonReader.tabSession(): RecoverableTab {
var parentId: String? = null
var url: String? = null
var title: String? = null
var searchTerm: String = ""
var contextId: String? = null
var lastAccess: Long? = null
var createdAt: Long? = null
Expand Down Expand Up @@ -194,6 +195,7 @@ private fun JsonReader.tabSession(): RecoverableTab {
Keys.SESSION_CONTEXT_ID_KEY -> contextId = nextStringOrNull()
Keys.SESSION_PARENT_UUID_KEY -> parentId = nextStringOrNull()?.takeIf { it.isNotEmpty() }
Keys.SESSION_TITLE -> title = nextStringOrNull() ?: ""
Keys.SESSION_SEARCH_TERM -> searchTerm = nextStringOrNull() ?: ""
Keys.SESSION_READER_MODE_KEY -> readerStateActive = nextBooleanOrNull()
Keys.SESSION_READER_MODE_ACTIVE_URL_KEY -> readerActiveUrl = nextStringOrNull()
Keys.SESSION_HISTORY_METADATA_URL -> historyMetadataUrl = nextStringOrNull()
Expand All @@ -219,6 +221,7 @@ private fun JsonReader.tabSession(): RecoverableTab {
parentId = parentId,
url = requireNotNull(url),
title = requireNotNull(title),
searchTerm = requireNotNull(searchTerm),
contextId = contextId,
state = null, // This will be deserialized and added separately
readerState = ReaderState(
Expand Down
Expand Up @@ -83,6 +83,9 @@ private fun JsonWriter.tab(
name(Keys.SESSION_TITLE)
value(tab.content.title)

name(Keys.SESSION_SEARCH_TERM)
value(tab.content.searchTerms)

name(Keys.SESSION_CONTEXT_ID_KEY)
value(tab.contextId)

Expand Down
Expand Up @@ -21,6 +21,7 @@ internal object Keys {
const val SESSION_READER_MODE_KEY = "readerMode"
const val SESSION_READER_MODE_ACTIVE_URL_KEY = "readerModeArticleUrl"
const val SESSION_TITLE = "title"
const val SESSION_SEARCH_TERM = "searchTerm"
const val SESSION_LAST_ACCESS = "lastAccess"
const val SESSION_CREATED_AT = "createdAt"
const val SESSION_LAST_MEDIA_URL = "lastMediaUrl"
Expand Down
Expand Up @@ -333,6 +333,59 @@ class BrowserStateWriterReaderTest {

assertNotNull(restoredTab.createdAt)
}

@Test
fun `Read and write tab with search term`() {
val engineState = createFakeEngineState()
val engine = createFakeEngine(engineState)

val tab = createTab(
url = "https://www.mozilla.org",
title = "Mozilla",
contextId = "work",
searchTerms = "test search"
)

val writer = BrowserStateWriter()
val reader = BrowserStateReader()

val file = AtomicFile(
File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString())
)

assertTrue(writer.writeTab(tab, file))

val restoredTab = reader.readTab(engine, file)
assertNotNull(restoredTab!!)

assertEquals("test search", restoredTab.searchTerm)
}

@Test
fun `Read and write tab without search term`() {
val engineState = createFakeEngineState()
val engine = createFakeEngine(engineState)

val tab = createTab(
url = "https://www.mozilla.org",
title = "Mozilla",
contextId = "work"
)

val writer = BrowserStateWriter()
val reader = BrowserStateReader()

val file = AtomicFile(
File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString())
)

assertTrue(writer.writeTab(tab, file))

val restoredTab = reader.readTab(engine, file)
assertNotNull(restoredTab!!)

assertEquals("", restoredTab.searchTerm)
}
}

private fun createFakeEngineState(): EngineSessionState {
Expand Down
Expand Up @@ -24,6 +24,8 @@ import mozilla.components.concept.storage.HistoryMetadataKey
* @property parentId The unique ID of the parent tab if this tab was opened from another tab (e.g. via
* the context menu).
* @property title The last title of this tab (or an empty String).
* @property searchTerms The last used search terms, or an empty string if no
* search was executed for this session.
* @property contextId The context ID ("container") this tab used (or null).
* @property state The [EngineSessionState] needed for restoring the previous state of this tab.
* @property readerState The last [ReaderState] of the tab.
Expand All @@ -40,6 +42,7 @@ data class RecoverableTab(
val url: String,
val parentId: String? = null,
val title: String = "",
val searchTerm: String = "",
val contextId: String? = null,
val state: EngineSessionState? = null,
val readerState: ReaderState = ReaderState(),
Expand All @@ -60,6 +63,7 @@ fun TabSessionState.toRecoverableTab(index: Int = -1) = RecoverableTab(
parentId = parentId,
url = content.url,
title = content.title,
searchTerm = content.searchTerms,
contextId = contextId,
state = engineState.engineSessionState,
readerState = readerState,
Expand All @@ -80,6 +84,7 @@ fun RecoverableTab.toTabSessionState() = createTab(
url = url,
parentId = parentId,
title = title,
searchTerms = searchTerm,
contextId = contextId,
engineSessionState = state,
readerState = readerState,
Expand Down

2 comments on commit 823681c

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.