Skip to content

Commit

Permalink
For mozilla-mobile/fenix#7310 - Adds bypassCache parameter to reload.
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed Jul 13, 2020
1 parent cdef87e commit 2847d39
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(bypassCache: Boolean) {
val flags = if (bypassCache) {
GeckoSession.LOAD_FLAGS_BYPASS_CACHE
} else {
GeckoSession.LOAD_FLAGS_NONE
}

geckoSession.reload(flags)
}

/**
Expand All @@ -146,7 +152,7 @@ class GeckoEngineSession(
}
}
/**
* See [EngineSession.goForward]
* See [EngineSession.goForward]1
*/
override fun goForward() {
geckoSession.goForward()
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(bypassCache = true)

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(bypassCache: Boolean) {
val flags = if (bypassCache) {
GeckoSession.LOAD_FLAGS_BYPASS_CACHE
} else {
GeckoSession.LOAD_FLAGS_NONE
}

geckoSession.reload(flags)
}

/**
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(bypassCache = true)

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ class GeckoEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
geckoSession.reload()
override fun reload(bypassCache: Boolean) {
val flags = if (bypassCache) {
GeckoSession.LOAD_FLAGS_BYPASS_CACHE
} else {
GeckoSession.LOAD_FLAGS_NONE
}

geckoSession.reload(flags)
}

/**
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(bypassCache = true)

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class SystemEngineSession(
/**
* See [EngineSession.reload]
*/
override fun reload() {
override fun reload(bypassCache: Boolean) {
if (bypassCache) {
webView.clearCache(true)
}

webView.reload()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ class SystemEngineSessionTest {
verify(webView).reload()
}

@Test
fun reloadBypassingCache() {
val engineSession = spy(SystemEngineSession(testContext))
val webView = mock<WebView>()

engineSession.reload(bypassCache = true)
verify(webView, never()).clearCache(true)
verify(webView, never()).reload()

engineSession.webView = webView

engineSession.reload(bypassCache = true)
verify(webView).clearCache(true)
verify(webView).reload()
}

@Test
fun goBack() {
val engineSession = spy(SystemEngineSession(testContext))
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(bypassCache: Boolean) {}
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(bypassCache: Boolean) {}
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(bypassCache: Boolean) {}
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 @@ -452,8 +452,10 @@ abstract class EngineSession(

/**
* Reloads the current URL.
*
* @param bypassCache true if you want to reload the URL bypassing the cache.
*/
abstract fun reload()
abstract fun reload(bypassCache: Boolean = false)

/**
* 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(bypassCache: Boolean) {}

override fun goBack() {}

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt)


* **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.
Expand All @@ -21,6 +22,7 @@ permalink: /changelog/

* **concept-engine**
* Added `EngineSession.goToHistoryIndex` to jump to a specific index in a session's history.
* Adds `bypassCache` parameter to `reload` to bypass the cache on 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 2847d39

Please sign in to comment.