Commit 99ba7542 authored by Tiger Oakes's avatar Tiger Oakes Committed by Tiger Oakes
Browse files

For #5028 - Add webAppManifest to ContentState

parent e13f1623
......@@ -18,9 +18,10 @@ import mozilla.components.browser.state.action.ContentAction.AddFindResultAction
import mozilla.components.browser.state.action.ContentAction.ClearFindResultsAction
import mozilla.components.browser.state.action.ContentAction.ConsumeHitResultAction
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
import mozilla.components.browser.state.action.ContentAction.UpdateForwardNavigationStateAction
import mozilla.components.browser.state.action.ContentAction.RemoveThumbnailAction
import mozilla.components.browser.state.action.ContentAction.UpdateHitResultAction
import mozilla.components.browser.state.action.ContentAction.UpdateLoadingStateAction
import mozilla.components.browser.state.action.ContentAction.UpdateProgressAction
......@@ -29,6 +30,7 @@ import mozilla.components.browser.state.action.ContentAction.UpdateSecurityInfoA
import mozilla.components.browser.state.action.ContentAction.UpdateThumbnailAction
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
......@@ -310,8 +312,17 @@ class Session(
/**
* The Web App Manifest for the currently visited page (or null).
*/
var webAppManifest: WebAppManifest? by Delegates.observable<WebAppManifest?>(null) { _, _, new ->
var webAppManifest: WebAppManifest? by Delegates.observable<WebAppManifest?>(null) { _, old, new ->
notifyObservers { onWebAppManifestChanged(this@Session, new) }
if (old != new) {
val action = if (new != null) {
UpdateWebAppManifestAction(id, new)
} else {
RemoveWebAppManifestAction(id)
}
store?.syncDispatch(action)
}
}
/**
......
......@@ -374,6 +374,37 @@ class SessionTest {
assertEquals(manifest, captor.value)
}
@Test
fun `action is dispatched when web app manifest is set`() {
val manifest = WebAppManifest(
name = "HackerWeb",
description = "A simply readable Hacker News app.",
startUrl = ".",
display = WebAppManifest.DisplayMode.STANDALONE,
icons = listOf(
WebAppManifest.Icon(
src = "images/touch/homescreen192.png",
sizes = listOf(Size(192, 192)),
type = "image/png"
)
)
)
val store: BrowserStore = mock()
`when`(store.dispatch(any())).thenReturn(mock())
val session = Session("https://www.mozilla.org")
session.store = store
session.webAppManifest = manifest
verify(store).dispatch(ContentAction.UpdateWebAppManifestAction(session.id, manifest))
session.webAppManifest = null
verify(store).dispatch(ContentAction.RemoveWebAppManifestAction(session.id))
verifyNoMoreInteractions(store)
}
@Test
fun `session returns initial URL`() {
val session = Session("https://www.mozilla.org")
......
......@@ -22,6 +22,7 @@ import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineSessionState
import mozilla.components.concept.engine.HitResult
import mozilla.components.concept.engine.content.blocking.Tracker
import mozilla.components.concept.engine.manifest.WebAppManifest
import mozilla.components.concept.engine.media.Media
import mozilla.components.concept.engine.prompt.PromptRequest
import mozilla.components.concept.engine.search.SearchRequest
......@@ -269,6 +270,16 @@ sealed class ContentAction : BrowserAction() {
* Updates the [ContentState] of the given [sessionId] to indicate whether or not a forward navigation is possible.
*/
data class UpdateForwardNavigationStateAction(val sessionId: String, val canGoForward: Boolean) : ContentAction()
/**
* Updates the [WebAppManifest] of the [ContentState] with the given [sessionId].
*/
data class UpdateWebAppManifestAction(val sessionId: String, val webAppManifest: WebAppManifest) : ContentAction()
/**
* Removes the [WebAppManifest] of the [ContentState] with the given [sessionId].
*/
data class RemoveWebAppManifestAction(val sessionId: String) : ContentAction()
}
/**
......
......@@ -111,6 +111,12 @@ internal object ContentStateReducer {
is ContentAction.UpdateForwardNavigationStateAction -> updateContentState(state, action.sessionId) {
it.copy(canGoForward = action.canGoForward)
}
is ContentAction.UpdateWebAppManifestAction -> updateContentState(state, action.sessionId) {
it.copy(webAppManifest = action.webAppManifest)
}
is ContentAction.RemoveWebAppManifestAction -> updateContentState(state, action.sessionId) {
it.copy(webAppManifest = null)
}
}
}
}
......
......@@ -8,6 +8,7 @@ import android.graphics.Bitmap
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.browser.state.state.content.FindResultState
import mozilla.components.concept.engine.HitResult
import mozilla.components.concept.engine.manifest.WebAppManifest
import mozilla.components.concept.engine.prompt.PromptRequest
import mozilla.components.concept.engine.search.SearchRequest
import mozilla.components.concept.engine.window.WindowRequest
......@@ -37,6 +38,7 @@ import mozilla.components.concept.engine.window.WindowRequest
* @property layoutInDisplayCutoutMode the display layout cutout mode state.
* @property canGoBack whether or not there's an history item to navigate back to.
* @property canGoForward whether or not there's an history item to navigate forward to.
* @property webAppManifest the Web App Manifest for the currently visited page (or null).
*/
data class ContentState(
val url: String,
......@@ -57,5 +59,6 @@ data class ContentState(
val fullScreen: Boolean = false,
val layoutInDisplayCutoutMode: Int = 0,
val canGoBack: Boolean = false,
val canGoForward: Boolean = false
val canGoForward: Boolean = false,
val webAppManifest: WebAppManifest? = null
)
......@@ -16,6 +16,7 @@ import mozilla.components.browser.state.state.createCustomTab
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.HitResult
import mozilla.components.concept.engine.manifest.WebAppManifest
import mozilla.components.concept.engine.prompt.PromptRequest
import mozilla.components.concept.engine.window.WindowRequest
import mozilla.components.support.test.ext.joinBlocking
......@@ -559,4 +560,44 @@ class ContentActionTest {
assertFalse(tab.content.canGoForward)
assertFalse(otherTab.content.canGoForward)
}
}
\ No newline at end of file
@Test
fun `UpdateWebAppManifestAction updates web app manifest`() {
val manifest = WebAppManifest(
name = "Mozilla",
startUrl = "https://mozilla.org"
)
assertNotEquals(manifest, tab.content.webAppManifest)
assertNotEquals(manifest, otherTab.content.webAppManifest)
store.dispatch(
ContentAction.UpdateWebAppManifestAction(tab.id, manifest)
).joinBlocking()
assertEquals(manifest, tab.content.webAppManifest)
assertNotEquals(manifest, otherTab.content.webAppManifest)
}
@Test
fun `RemoveWebAppManifestAction removes web app manifest`() {
val manifest = WebAppManifest(
name = "Mozilla",
startUrl = "https://mozilla.org"
)
assertNotEquals(manifest, tab.content.webAppManifest)
store.dispatch(
ContentAction.UpdateWebAppManifestAction(tab.id, manifest)
).joinBlocking()
assertEquals(manifest, tab.content.webAppManifest)
store.dispatch(
ContentAction.RemoveWebAppManifestAction(tab.id)
).joinBlocking()
assertNull(tab.content.webAppManifest)
}
}
......@@ -19,6 +19,9 @@ permalink: /changelog/
`val config = Configuration(httpClient = ConceptFetchHttpUploader(lazy { HttpURLConnectionClient() as Client }))`.
See [PR #6875](https://github.com/mozilla-mobile/android-components/pull/6875) for details and full code examples.
* **browser-store**
* Added `webAppManifest` property to `ContentState`.
# 41.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v40.0.0...v41.0.0)
......@@ -54,7 +57,7 @@ permalink: /changelog/
* The minimum and maximum values of a timing distribution can now be controlled by the `time_unit` parameter. See [bug 1630997](https://bugzilla.mozilla.org/show_bug.cgi?id=1630997) for more details.
* **feature-accounts**
* ⚠️ **This is a breaking change**: Refactored component to use `browser-state` instead of `browser-session`. The `FxaWebChannelFeature` now requires a `BrowserStore` instance instead of a `SessionManager`.
* ⚠️ **This is a breaking change**: Refactored component to use `browser-state` instead of `browser-session`. The `FxaWebChannelFeature` now requires a `BrowserStore` instance instead of a `SessionManager`.
* **browser-toolbar**
* It will only be animated for vertical scrolls inside the EngineView. Not for horizontal scrolls. Not for zoom gestures.
......@@ -109,11 +112,11 @@ permalink: /changelog/
* **feature-syncedtabs**
* Moved `SyncedTabsFeature` to `SyncedTabsStorage`.
* ⚠️ **This is a breaking change**: The new `SyncedTabsFeature` now orchestrates the correct state needed for consumers to handle by implementing the `SyncedTabsView`.
* **browser-thumbnails**
* 🆕 New component for capturing browser thumbnails.
* `ThumbnailsFeature` will be deprecated for the new `BrowserThumbnails` in a future.
# 39.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v38.0.0...v39.0.0)
......@@ -185,7 +188,7 @@ permalink: /changelog/
* **Developer ergonomics**
* Improved autoPublication workflow. See https://mozac.org/contributing/testing-components-inside-app for updated documentation.
* **browser-search**
* Added `getSearchTemplate` to reconstruct the user-entered search engine url template
......
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