mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Refactor tryReloadTabBy to use browser store
This commit is contained in:
parent
a78e50464d
commit
8aa8caa944
@ -13,12 +13,20 @@ import org.mozilla.fenix.components.Components
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
|
||||
/**
|
||||
* Try to reload a session if a session with the given [origin] it is found.
|
||||
* @param origin The origin the session to be reloaded.
|
||||
* Reloads the last used tab matching the provided origin. For performance
|
||||
* reasons we don't want to reload all matching tabs. Reloading the last used
|
||||
* tab is a good compromise as it's likely the reason for a change in site
|
||||
* permissions.
|
||||
*
|
||||
* @param origin The origin of the tab to reload.
|
||||
*/
|
||||
internal fun Components.tryReloadTabBy(origin: String) {
|
||||
val session = core.sessionManager.all.find { it.url.toUri().host == origin }
|
||||
useCases.sessionUseCases.reload(session)
|
||||
core.store.state.tabs
|
||||
.sortedByDescending { it.lastAccess }
|
||||
.find { it.content.url.toUri().host == origin }
|
||||
?.let {
|
||||
useCases.sessionUseCases.reload(it.id)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun initBlockedByAndroidView(phoneFeature: PhoneFeature, blockedByAndroidView: View) {
|
||||
|
@ -0,0 +1,45 @@
|
||||
/* 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.components.settings.sitepermissions
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import mozilla.components.browser.state.state.BrowserState
|
||||
import mozilla.components.browser.state.state.createTab
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.components.Components
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.settings.sitepermissions.tryReloadTabBy
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class ExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `tryReloadTabBy reloads latest tab matching origin`() {
|
||||
val store = BrowserStore(
|
||||
BrowserState(tabs = listOf(
|
||||
createTab(id = "1", url = "https://www.mozilla.org/1", lastAccess = 1),
|
||||
createTab(id = "2", url = "https://www.mozilla.org/2", lastAccess = 2),
|
||||
createTab(id = "3", url = "https://www.firefox.com")
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val components: Components = mockk(relaxed = true)
|
||||
every { components.core.store } returns store
|
||||
|
||||
components.tryReloadTabBy("www.getpocket.com")
|
||||
verify(exactly = 0) { components.useCases.sessionUseCases.reload(any<String>()) }
|
||||
|
||||
components.tryReloadTabBy("www.mozilla.org")
|
||||
verify { components.useCases.sessionUseCases.reload("2") }
|
||||
|
||||
components.tryReloadTabBy("www.firefox.com")
|
||||
verify { components.useCases.sessionUseCases.reload("3") }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user