1
0
Fork 0

No issue: Show article/page url instead of reader extension url

master
Christian Sadilek 2020-05-05 12:10:43 -04:00
parent d72e455c0d
commit fee09c3092
2 changed files with 47 additions and 2 deletions

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.ext
import android.content.Context
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.state.MediaState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
@ -19,10 +20,11 @@ fun Session.toTab(context: Context, selected: Boolean? = null): Tab =
)
fun Session.toTab(store: BrowserStore, publicSuffixList: PublicSuffixList, selected: Boolean? = null): Tab {
val url = store.state.findTab(this.id)?.readerState?.activeUrl ?: this.url
return Tab(
sessionId = this.id,
url = this.url,
hostname = this.url.toShortUrl(publicSuffixList),
url = url,
hostname = url.toShortUrl(publicSuffixList),
title = this.title,
selected = selected,
icon = this.icon,

View File

@ -0,0 +1,43 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ReaderState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class SessionTest {
@Test
fun `toTab uses active reader URL`() {
val sessionWithoutReaderState = Session(id = "1", initialUrl = "https://example.com")
val tabWithoutReaderState = createTab(url = sessionWithoutReaderState.url, id = sessionWithoutReaderState.id)
val sessionWithInactiveReaderState = Session(id = "2", initialUrl = "https://blog.mozilla.org")
val tabWithInactiveReaderState = createTab(url = sessionWithInactiveReaderState.url, id = sessionWithInactiveReaderState.id,
readerState = ReaderState(active = false, activeUrl = null)
)
val sessionWithActiveReaderState = Session(id = "3", initialUrl = "moz-extension://123")
val tabWithActiveReaderState = createTab(url = sessionWithActiveReaderState.url, id = sessionWithActiveReaderState.id,
readerState = ReaderState(active = true, activeUrl = "https://blog.mozilla.org/123")
)
val tabs = listOf(tabWithoutReaderState, tabWithInactiveReaderState, tabWithActiveReaderState)
val store = BrowserStore(BrowserState(tabs))
assertEquals(sessionWithoutReaderState.url, sessionWithoutReaderState.toTab(store, mock()).url)
assertEquals(sessionWithInactiveReaderState.url, sessionWithInactiveReaderState.toTab(store, mock()).url)
assertEquals("https://blog.mozilla.org/123", sessionWithActiveReaderState.toTab(store, mock()).url)
}
}