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

Issue #7737: Remove fullScreenMode and layoutInDisplayCutoutMode from Session.

parent 3ee03f28
......@@ -13,7 +13,6 @@ import mozilla.components.browser.session.engine.request.LoadRequestOption
import mozilla.components.browser.session.ext.syncDispatch
import mozilla.components.browser.session.ext.toSecurityInfoState
import mozilla.components.browser.session.ext.toTabSessionState
import mozilla.components.browser.state.action.ContentAction.FullScreenChangedAction
import mozilla.components.browser.state.action.ContentAction.RemoveThumbnailAction
import mozilla.components.browser.state.action.ContentAction.RemoveWebAppManifestAction
import mozilla.components.browser.state.action.ContentAction.UpdateBackNavigationStateAction
......@@ -26,7 +25,6 @@ import mozilla.components.browser.state.action.ContentAction.UpdateThumbnailActi
import mozilla.components.browser.state.action.ContentAction.UpdateTitleAction
import mozilla.components.browser.state.action.ContentAction.UpdateUrlAction
import mozilla.components.browser.state.action.ContentAction.UpdateWebAppManifestAction
import mozilla.components.browser.state.action.ContentAction.ViewportFitChangedAction
import mozilla.components.browser.state.action.CustomTabListAction.RemoveCustomTabAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction.AddTabAction
......@@ -95,11 +93,6 @@ class Session(
fun onTrackerBlocked(session: Session, tracker: Tracker, all: List<Tracker>) = Unit
fun onTrackerLoaded(session: Session, tracker: Tracker, all: List<Tracker>) = Unit
fun onDesktopModeChanged(session: Session, enabled: Boolean) = Unit
fun onFullScreenChanged(session: Session, enabled: Boolean) = Unit
/**
* @param layoutInDisplayCutoutMode value of defined in https://developer.android.com/reference/android/view/WindowManager.LayoutParams#layoutInDisplayCutoutMode
*/
fun onMetaViewportFitChanged(session: Session, layoutInDisplayCutoutMode: Int) = Unit
fun onThumbnailChanged(session: Session, bitmap: Bitmap?) = Unit
fun onContentPermissionRequested(session: Session, permissionRequest: PermissionRequest): Boolean = false
fun onAppPermissionRequested(session: Session, permissionRequest: PermissionRequest): Boolean = false
......@@ -376,23 +369,6 @@ class Session(
notifyObservers(old, new) { onDesktopModeChanged(this@Session, new) }
}
/**
* Exits fullscreen mode if it's in that state.
*/
var fullScreenMode: Boolean by Delegates.observable(false) { _, old, new ->
if (notifyObservers(old, new) { onFullScreenChanged(this@Session, new) }) {
store?.syncDispatch(FullScreenChangedAction(id, new))
}
}
/**
* Display cutout mode state.
*/
var layoutInDisplayCutoutMode: Int by Delegates.observable(0) { _, _, new ->
notifyObservers { onMetaViewportFitChanged(this@Session, new) }
store?.syncDispatch(ViewportFitChangedAction(id, new))
}
/**
* An icon for the currently visible page.
*/
......
......@@ -218,11 +218,15 @@ internal class EngineObserver(
}
override fun onFullScreenChange(enabled: Boolean) {
session.fullScreenMode = enabled
store?.dispatch(ContentAction.FullScreenChangedAction(
session.id, enabled
))
}
override fun onMetaViewportFitChanged(layoutInDisplayCutoutMode: Int) {
session.layoutInDisplayCutoutMode = layoutInDisplayCutoutMode
store?.dispatch(ContentAction.ViewportFitChangedAction(
session.id, layoutInDisplayCutoutMode
))
}
override fun onThumbnailChange(bitmap: Bitmap?) {
......
......@@ -148,7 +148,6 @@ class SelectionAwareSessionObserverTest {
observer.onTrackerBlockingEnabledChanged(session, true)
observer.onTrackerBlocked(session, Tracker(""), emptyList())
observer.onDesktopModeChanged(session, true)
observer.onFullScreenChanged(session, true)
observer.onThumbnailChanged(session, Mockito.spy(Bitmap::class.java))
observer.onSessionRemoved(session)
observer.onAllSessionsRemoved()
......
......@@ -5,7 +5,6 @@
package mozilla.components.browser.session
import android.graphics.Bitmap
import android.view.WindowManager
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
......@@ -578,34 +577,6 @@ class SessionTest {
assertTrue(session.desktopMode)
}
@Test
fun `observer is notified on fullscreen mode`() {
val observer = mock(Session.Observer::class.java)
val session = Session("https://www.mozilla.org")
session.register(observer)
session.fullScreenMode = true
verify(observer).onFullScreenChanged(session, true)
reset(observer)
session.unregister(observer)
session.fullScreenMode = false
verify(observer, never()).onFullScreenChanged(session, false)
}
@Test
fun `observer is notified on meta viewport fit change`() {
val observer = mock(Session.Observer::class.java)
val session = Session("https://www.mozilla.org")
session.register(observer)
session.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
verify(observer).onMetaViewportFitChanged(session,
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT)
reset(observer)
session.unregister(observer)
session.layoutInDisplayCutoutMode = 123
verify(observer, never()).onMetaViewportFitChanged(session, 123)
}
@Test
fun `observer is notified on on thumbnail changed `() {
val observer = mock(Session.Observer::class.java)
......@@ -658,7 +629,6 @@ class SessionTest {
defaultObserver.onTrackerBlockingEnabledChanged(session, true)
defaultObserver.onTrackerBlocked(session, mock(), emptyList())
defaultObserver.onDesktopModeChanged(session, true)
defaultObserver.onFullScreenChanged(session, true)
defaultObserver.onThumbnailChanged(session, spy(Bitmap::class.java))
defaultObserver.onContentPermissionRequested(session, contentPermissionRequest)
defaultObserver.onAppPermissionRequested(session, appPermissionRequest)
......
......@@ -434,31 +434,53 @@ class EngineObserverTest {
@Test
fun engineObserverNotifiesFullscreenMode() {
val session = Session("https://www.mozilla.org")
val observer = EngineObserver(session)
val session = Session("https://www.mozilla.org", id = "test-id")
val store: BrowserStore = mock()
val observer = EngineObserver(session, store)
observer.onFullScreenChange(true)
assertEquals(true, session.fullScreenMode)
verify(store).dispatch(ContentAction.FullScreenChangedAction(
"test-id", true
))
reset(store)
observer.onFullScreenChange(false)
assertEquals(false, session.fullScreenMode)
verify(store).dispatch(ContentAction.FullScreenChangedAction(
"test-id", false
))
}
@Test
fun engineObserverNotifiesMetaViewportFitChange() {
val session = Session("https://www.mozilla.org")
val observer = EngineObserver(session)
val store: BrowserStore = mock()
val session = Session("https://www.mozilla.org", id = "test-id")
val observer = EngineObserver(session, store)
observer.onMetaViewportFitChanged(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT)
assertEquals(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT,
session.layoutInDisplayCutoutMode)
verify(store).dispatch(ContentAction.ViewportFitChangedAction(
"test-id", WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
))
reset(store)
observer.onMetaViewportFitChanged(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES)
assertEquals(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES,
session.layoutInDisplayCutoutMode)
verify(store).dispatch(ContentAction.ViewportFitChangedAction(
"test-id", WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
))
reset(store)
observer.onMetaViewportFitChanged(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER)
assertEquals(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER,
session.layoutInDisplayCutoutMode)
verify(store).dispatch(ContentAction.ViewportFitChangedAction(
"test-id", WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
))
reset(store)
observer.onMetaViewportFitChanged(123)
assertEquals(123, session.layoutInDisplayCutoutMode)
verify(store).dispatch(ContentAction.ViewportFitChangedAction(
"test-id", 123
))
reset(store)
}
@Test
......
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