Revert "Bug 1861459 - Remove BrowsingModeManager"
This reverts commit 38af1c1363aa34b564305a1b2c809249e1be5b1b.fenix/123.0
parent
04d83965a4
commit
d080cf6e70
@ -1,23 +0,0 @@
|
|||||||
/* 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.appstate.home
|
|
||||||
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction.TabsTrayAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of a [TabsTrayAction].
|
|
||||||
*/
|
|
||||||
object TabsTrayReducer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of a [TabsTrayAction].
|
|
||||||
*/
|
|
||||||
fun reduce(state: AppState, action: TabsTrayAction): AppState = when (action) {
|
|
||||||
is TabsTrayAction.NewTab -> state.copy(mode = BrowsingMode.Normal)
|
|
||||||
is TabsTrayAction.NewPrivateTab -> state.copy(mode = BrowsingMode.Private)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
/* 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.appstate.home
|
|
||||||
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction.ToolbarAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of a [ToolbarAction].
|
|
||||||
*/
|
|
||||||
object ToolbarReducer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of a [ToolbarAction].
|
|
||||||
*/
|
|
||||||
fun reduce(state: AppState, action: ToolbarAction): AppState = when (action) {
|
|
||||||
is ToolbarAction.NewTab -> state.copy(mode = BrowsingMode.Normal)
|
|
||||||
is ToolbarAction.NewPrivateTab -> state.copy(mode = BrowsingMode.Private)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/* 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.appstate.home
|
|
||||||
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction.WallpaperAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of an [WallpaperAction].
|
|
||||||
*/
|
|
||||||
object WallpapersReducer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reducer to handle updating [AppState] with the result of an [WallpaperAction].
|
|
||||||
*/
|
|
||||||
fun reduce(state: AppState, action: WallpaperAction): AppState = when (action) {
|
|
||||||
is WallpaperAction.UpdateCurrentWallpaper ->
|
|
||||||
state.copy(
|
|
||||||
wallpaperState = state.wallpaperState.copy(currentWallpaper = action.wallpaper),
|
|
||||||
)
|
|
||||||
is WallpaperAction.UpdateAvailableWallpapers ->
|
|
||||||
state.copy(
|
|
||||||
wallpaperState = state.wallpaperState.copy(availableWallpapers = action.wallpapers),
|
|
||||||
)
|
|
||||||
is WallpaperAction.UpdateWallpaperDownloadState -> {
|
|
||||||
val wallpapers = state.wallpaperState.availableWallpapers.map {
|
|
||||||
if (it.name == action.wallpaper.name) {
|
|
||||||
it.copy(assetsFileState = action.imageState)
|
|
||||||
} else {
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val wallpaperState = state.wallpaperState.copy(availableWallpapers = wallpapers)
|
|
||||||
state.copy(wallpaperState = wallpaperState)
|
|
||||||
}
|
|
||||||
is WallpaperAction.OpenToHome -> state.copy(mode = BrowsingMode.Normal)
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
/* 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.home
|
||||||
|
|
||||||
|
import org.mozilla.fenix.components.appstate.AppAction.HomeAction
|
||||||
|
import org.mozilla.fenix.components.appstate.AppState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reducer to handle updating [AppState] with the result of an [HomeAction].
|
||||||
|
*/
|
||||||
|
object HomeReducer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reducer to handle updating [AppState] with the result of an [HomeAction].
|
||||||
|
*/
|
||||||
|
fun reduce(state: AppState, action: HomeAction): AppState = when (action) {
|
||||||
|
is HomeAction.OpenToHome -> state.copy(mode = action.mode)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/* 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.browser.browsingmode
|
||||||
|
|
||||||
|
import io.mockk.MockKAnnotations
|
||||||
|
import io.mockk.Runs
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.impl.annotations.MockK
|
||||||
|
import io.mockk.just
|
||||||
|
import io.mockk.verify
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mozilla.fenix.helpers.MockkRetryTestRule
|
||||||
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
|
class DefaultBrowsingModeManagerTest {
|
||||||
|
|
||||||
|
@MockK lateinit var settings: Settings
|
||||||
|
|
||||||
|
@MockK(relaxed = true)
|
||||||
|
lateinit var callback: (BrowsingMode) -> Unit
|
||||||
|
lateinit var manager: BrowsingModeManager
|
||||||
|
|
||||||
|
private val initMode = BrowsingMode.Normal
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val mockkRule = MockkRetryTestRule()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun before() {
|
||||||
|
MockKAnnotations.init(this)
|
||||||
|
|
||||||
|
manager = DefaultBrowsingModeManager(initMode, settings, callback)
|
||||||
|
every { settings.lastKnownMode = any() } just Runs
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN mode is updated THEN callback is invoked`() {
|
||||||
|
verify(exactly = 0) { callback.invoke(any()) }
|
||||||
|
|
||||||
|
manager.mode = BrowsingMode.Private
|
||||||
|
manager.mode = BrowsingMode.Private
|
||||||
|
manager.mode = BrowsingMode.Private
|
||||||
|
|
||||||
|
verify(exactly = 3) { callback.invoke(BrowsingMode.Private) }
|
||||||
|
|
||||||
|
manager.mode = BrowsingMode.Normal
|
||||||
|
manager.mode = BrowsingMode.Normal
|
||||||
|
|
||||||
|
verify(exactly = 2) { callback.invoke(BrowsingMode.Normal) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `WHEN mode is updated THEN it should be returned from get`() {
|
||||||
|
assertEquals(BrowsingMode.Normal, manager.mode)
|
||||||
|
|
||||||
|
manager.mode = BrowsingMode.Private
|
||||||
|
assertEquals(BrowsingMode.Private, manager.mode)
|
||||||
|
verify { settings.lastKnownMode = BrowsingMode.Private }
|
||||||
|
|
||||||
|
manager.mode = BrowsingMode.Normal
|
||||||
|
assertEquals(BrowsingMode.Normal, manager.mode)
|
||||||
|
verify { settings.lastKnownMode = BrowsingMode.Normal }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
/* 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.browser.browsingmode
|
||||||
|
|
||||||
|
data class SimpleBrowsingModeManager(
|
||||||
|
override var mode: BrowsingMode,
|
||||||
|
) : BrowsingModeManager
|
@ -1,29 +0,0 @@
|
|||||||
package org.mozilla.fenix.home
|
|
||||||
|
|
||||||
import mozilla.components.support.test.ext.joinBlocking
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.AppStore
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
class TabsTrayReducerTest {
|
|
||||||
@Test
|
|
||||||
fun `WHEN new tab clicked THEN mode is updated to normal`() {
|
|
||||||
val appStore = AppStore(AppState(mode = BrowsingMode.Private))
|
|
||||||
|
|
||||||
appStore.dispatch(AppAction.TabsTrayAction.NewTab).joinBlocking()
|
|
||||||
|
|
||||||
assertEquals(BrowsingMode.Normal, appStore.state.mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `WHEN new private tab clicked THEN mode is updated to private`() {
|
|
||||||
val appStore = AppStore(AppState(mode = BrowsingMode.Normal))
|
|
||||||
|
|
||||||
appStore.dispatch(AppAction.TabsTrayAction.NewPrivateTab).joinBlocking()
|
|
||||||
|
|
||||||
assertEquals(BrowsingMode.Private, appStore.state.mode)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package org.mozilla.fenix.home
|
|
||||||
|
|
||||||
import mozilla.components.support.test.ext.joinBlocking
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.AppStore
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
class ToolbarReducerTest {
|
|
||||||
@Test
|
|
||||||
fun `WHEN new tab clicked THEN mode is updated to normal`() {
|
|
||||||
val appStore = AppStore(AppState(mode = BrowsingMode.Private))
|
|
||||||
|
|
||||||
appStore.dispatch(AppAction.ToolbarAction.NewTab).joinBlocking()
|
|
||||||
|
|
||||||
assertEquals(BrowsingMode.Normal, appStore.state.mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `WHEN new private tab clicked THEN mode is updated to private`() {
|
|
||||||
val appStore = AppStore(AppState(mode = BrowsingMode.Normal))
|
|
||||||
|
|
||||||
appStore.dispatch(AppAction.ToolbarAction.NewPrivateTab).joinBlocking()
|
|
||||||
|
|
||||||
assertEquals(BrowsingMode.Private, appStore.state.mode)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package org.mozilla.fenix.home
|
|
||||||
|
|
||||||
import mozilla.components.support.test.ext.joinBlocking
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Test
|
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|
||||||
import org.mozilla.fenix.components.AppStore
|
|
||||||
import org.mozilla.fenix.components.appstate.AppAction
|
|
||||||
import org.mozilla.fenix.components.appstate.AppState
|
|
||||||
|
|
||||||
class WallpapersReducerTest {
|
|
||||||
@Test
|
|
||||||
fun `WHEN OpenToHome dispatched THEN mode is updated to normal`() {
|
|
||||||
val appStore = AppStore(AppState(mode = BrowsingMode.Private))
|
|
||||||
|
|
||||||
appStore.dispatch(AppAction.WallpaperAction.OpenToHome).joinBlocking()
|
|
||||||
|
|
||||||
assertEquals(BrowsingMode.Normal, appStore.state.mode)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue