Commit 0bd94919 authored by Mugurell's avatar Mugurell
Browse files

For #8188 - Expose BrowserIcons.clear() as a public API

This allows removing all saved icons data from disk and memory caches.
parent 5c2559da
......@@ -238,7 +238,7 @@ class BrowserIcons(
* If custom [IconLoader] and [IconProcessor] instances with a custom storage are provided to
* [BrowserIcons] then the calling app is responsible for clearing that data.
*/
private fun clear() {
fun clear() {
sharedDiskCache.clear(context)
sharedMemoryCache.clear()
}
......
......@@ -29,11 +29,13 @@ import org.junit.Assert.assertSame
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when`
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import java.io.OutputStream
@RunWith(AndroidJUnit4::class)
class BrowserIconsTest {
......@@ -264,4 +266,39 @@ class BrowserIconsTest {
result.cancel()
}
@Test
fun `clear should delete all disk and memory data`() {
// Test the effect of clear by first adding some icons data
val icons = BrowserIcons(testContext, httpClient = HttpURLConnectionClient())
val resource = IconRequest.Resource(
url = "https://www.mozilla.org/icon64.png",
sizes = listOf(Size(64, 64)),
mimeType = "image/png",
type = IconRequest.Resource.Type.FAVICON
)
val request = IconRequest(url = "https://www.mozilla.org", resources = listOf(resource))
sharedDiskCache.putResources(testContext, request)
val bitmap: Bitmap = mock()
`when`(bitmap.compress(any(), ArgumentMatchers.anyInt(), any())).thenAnswer {
assertEquals(Bitmap.CompressFormat.WEBP, it.arguments[0] as Bitmap.CompressFormat)
assertEquals(90, it.arguments[1] as Int) // Quality
val stream = it.arguments[2] as OutputStream
stream.write("Hello World".toByteArray())
true
}
val icon = Icon(bitmap, source = Icon.Source.DOWNLOAD)
sharedMemoryCache.put(request, resource, icon)
// Verifying it's all there
assertEquals(listOf(resource), sharedDiskCache.getResources(testContext, request))
assertEquals(listOf(resource), sharedMemoryCache.getResources(request))
icons.clear()
// Verifying it's not anymore
assertEquals(0, sharedDiskCache.getResources(testContext, request).size)
assertEquals(0, sharedMemoryCache.getResources(request).size)
}
}
......@@ -42,6 +42,9 @@ permalink: /changelog/
* **ui-widgets**
* Added widget for showing a website in a list, such as in bookmarks or history. The `mozac_primary_text_color` and `mozac_caption_text_color` attributes should be set.
* **browser-icons**
* Expose `BrowserIcons.clear()` as a public API to remove all saved data from disk and memory caches.
# 55.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v54.0.0...v55.0.0)
......
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