Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge #7697
Browse files Browse the repository at this point in the history
7697: For mozilla-mobile/fenix#7310 - Adds bypassCache parameter to reload. r=csadilek a=boek

For mozilla-mobile/fenix#7310 - Adds bypassCache parameter to reload. 


Co-authored-by: Jeff Boek <jeff@jeffboek.com>
  • Loading branch information
MozLando and boek committed Jul 14, 2020
2 parents 91f6850 + b931ccb commit 589e186
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(flags: LoadUrlFlags) {
geckoSession.reload(flags.value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,18 @@ class GeckoEngineSessionTest {

engineSession.reload()

verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
}

@Test
fun reloadBypassingCache() {
val engineSession = GeckoEngineSession(mock(),
geckoSessionProvider = geckoSessionProvider)
engineSession.loadUrl("http://mozilla.org")

engineSession.reload(flags = LoadUrlFlags.select(LoadUrlFlags.BYPASS_CACHE))

verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE)
}

@Test
Expand Down Expand Up @@ -2319,7 +2330,7 @@ class GeckoEngineSessionTest {

// reload()
engineSession.reload()
verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand All @@ -2341,7 +2352,7 @@ class GeckoEngineSessionTest {
// toggleDesktopMode()
engineSession.toggleDesktopMode(false, reload = true)
// This is the second time in this test, so we actually want two invocations.
verify(geckoSession, times(2)).reload()
verify(geckoSession, times(2)).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(flags: LoadUrlFlags) {
geckoSession.reload(flags.value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,18 @@ class GeckoEngineSessionTest {

engineSession.reload()

verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
}

@Test
fun reloadBypassingCache() {
val engineSession = GeckoEngineSession(mock(),
geckoSessionProvider = geckoSessionProvider)
engineSession.loadUrl("http://mozilla.org")

engineSession.reload(flags = LoadUrlFlags.select(LoadUrlFlags.BYPASS_CACHE))

verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE)
}

@Test
Expand Down Expand Up @@ -2500,7 +2511,7 @@ class GeckoEngineSessionTest {

// reload()
engineSession.reload()
verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand All @@ -2522,7 +2533,7 @@ class GeckoEngineSessionTest {
// toggleDesktopMode()
engineSession.toggleDesktopMode(false, reload = true)
// This is the second time in this test, so we actually want two invocations.
verify(geckoSession, times(2)).reload()
verify(geckoSession, times(2)).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(flags: LoadUrlFlags) {
geckoSession.reload(flags.value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,18 @@ class GeckoEngineSessionTest {

engineSession.reload()

verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
}

@Test
fun reloadBypassingCache() {
val engineSession = GeckoEngineSession(mock(),
geckoSessionProvider = geckoSessionProvider)
engineSession.loadUrl("http://mozilla.org")

engineSession.reload(flags = LoadUrlFlags.select(LoadUrlFlags.BYPASS_CACHE))

verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_BYPASS_CACHE)
}

@Test
Expand Down Expand Up @@ -2319,7 +2330,7 @@ class GeckoEngineSessionTest {

// reload()
engineSession.reload()
verify(geckoSession).reload()
verify(geckoSession).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand All @@ -2341,7 +2352,7 @@ class GeckoEngineSessionTest {
// toggleDesktopMode()
engineSession.toggleDesktopMode(false, reload = true)
// This is the second time in this test, so we actually want two invocations.
verify(geckoSession, times(2)).reload()
verify(geckoSession, times(2)).reload(GeckoSession.LOAD_FLAGS_NONE)
fakePageLoad(false)

fakePageLoad(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ class SystemEngineSession(

/**
* See [EngineSession.reload]
* @param flags currently not supported in `SystemEngineSession`.
*/
override fun reload() {
override fun reload(flags: LoadUrlFlags) {
webView.reload()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EngineObserverTest {
override fun goBack() {}
override fun goForward() {}
override fun goToHistoryIndex(index: Int) {}
override fun reload() {}
override fun reload(flags: LoadUrlFlags) {}
override fun stopLoading() {}
override fun restoreState(state: EngineSessionState): Boolean { return false }
override fun enableTrackingProtection(policy: TrackingProtectionPolicy) {}
Expand Down Expand Up @@ -112,7 +112,7 @@ class EngineObserverTest {
override fun goForward() {}
override fun goToHistoryIndex(index: Int) {}
override fun stopLoading() {}
override fun reload() {}
override fun reload(flags: LoadUrlFlags) {}
override fun restoreState(state: EngineSessionState): Boolean { return false }
override fun enableTrackingProtection(policy: TrackingProtectionPolicy) {}
override fun disableTrackingProtection() {}
Expand Down Expand Up @@ -157,7 +157,7 @@ class EngineObserverTest {
override fun goForward() {}
override fun goToHistoryIndex(index: Int) {}
override fun stopLoading() {}
override fun reload() {}
override fun reload(flags: LoadUrlFlags) {}
override fun restoreState(state: EngineSessionState): Boolean { return false }
override fun enableTrackingProtection(policy: TrackingProtectionPolicy) {
notifyObservers { onTrackerBlockingEnabledChange(true) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ abstract class EngineSession(
* @param url the url to load.
* @param parent the parent (referring) [EngineSession] i.e. the session that
* triggered creating this one.
* @param flags the [LoadUrlFlags] to use when loading the provider url.
* @param flags the [LoadUrlFlags] to use when loading the provided url.
* @param additionalHeaders the extra headers to use when loading the provided url.
*/
abstract fun loadUrl(
Expand Down Expand Up @@ -452,8 +452,10 @@ abstract class EngineSession(

/**
* Reloads the current URL.
*
* @param flags the [LoadUrlFlags] to use when reloading the current url.
*/
abstract fun reload()
abstract fun reload(flags: LoadUrlFlags = LoadUrlFlags.none())

/**
* Navigates back in the history of this session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ open class DummyEngineSession : EngineSession() {

override fun stopLoading() {}

override fun reload() {}
override fun reload(flags: LoadUrlFlags) {}

override fun goBack() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,26 @@ class SessionUseCases(
* selected session if none is provided).
*
* @param session the session for which reload should be triggered.
* @param flags the [LoadUrlFlags] to use when reloading the given session.
*/
operator fun invoke(session: Session? = sessionManager.selectedSession) {
operator fun invoke(
session: Session? = sessionManager.selectedSession,
flags: LoadUrlFlags = LoadUrlFlags.none()
) {
if (session != null) {
sessionManager.getOrCreateEngineSession(session).reload()
sessionManager.getOrCreateEngineSession(session).reload(flags)
}
}

/**
* Reloads the current page of the tab with the given [tabId].
*
* @param tabId id of the tab that should be reloaded
* @param flags the [LoadUrlFlags] to use when reloading the given tabId.
*/
operator fun invoke(tabId: String) {
operator fun invoke(tabId: String, flags: LoadUrlFlags = LoadUrlFlags.none()) {
sessionManager.findSessionById(tabId)?.let {
invoke(it)
invoke(it, flags)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ class SessionUseCasesTest {
verify(selectedEngineSession).reload()
}

@Test
fun reloadBypassCache() {
val engineSession = mock<EngineSession>()
val session = mock<Session>()
val flags = LoadUrlFlags.select(LoadUrlFlags.BYPASS_CACHE)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)

useCases.reload(session, flags = flags)
verify(engineSession).reload(flags = flags)

whenever(sessionManager.getOrCreateEngineSession(selectedSession)).thenReturn(selectedEngineSession)
useCases.reload(flags = flags)
verify(selectedEngineSession).reload(flags = flags)
}

@Test
fun stopLoading() {
val engineSession = mock<EngineSession>()
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ permalink: /changelog/
* **feature-session**
* Added `SessionFeature.release()`: Calling this method stops the feature from rendering sessions on the `EngineView` (until explicitly started again) and releases an already rendering session from the `EngineView`.
* Added `SessionUseCases.goToHistoryIndex` to allow consumers to jump to a specific index in a session's history.
* Added `flags` parameter to `ReloadUrlUseCase`.

* **support-ktx**
* Adds `Bundle.contentEquals` function to check if two bundles are equal.

* **concept-engine**
* Added `EngineSession.goToHistoryIndex` to jump to a specific index in a session's history.
* Adds `flags` parameter to `reload`.

* **service-location**
* `LocationService.hasRegionCached()` is introduced to query if the region is already cached and a long running operation to fetch the region is not needed.
Expand Down

0 comments on commit 589e186

Please sign in to comment.