Loading components/browser/icons/src/main/java/mozilla/components/browser/icons/IconRequest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,8 @@ data class IconRequest( val url: String, val size: Size = Size.DEFAULT, val resources: List<Resource> = emptyList(), @ColorInt val color: Int? = null @ColorInt val color: Int? = null, val isPrivate: Boolean = false ) { /** Loading components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt +2 −2 Original line number Diff line number Diff line Loading @@ -62,11 +62,11 @@ internal fun List<IconRequest.Resource>.toJSON(): JSONArray { }.toJSONArray() } internal fun JSONObject.toIconRequest(): IconRequest? { internal fun JSONObject.toIconRequest(isPrivate: Boolean): IconRequest? { return try { val url = getString("url") IconRequest(url, resources = getJSONArray("icons").toIconResources()) IconRequest(url, isPrivate = isPrivate, resources = getJSONArray("icons").toIconResources()) } catch (e: JSONException) { Logger.warn("Could not parse message from icons extensions", e) null Loading components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessageHandler.kt +1 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ internal class IconMessageHandler( override fun onMessage(message: Any, source: EngineSession?): Any { if (message is JSONObject) { message.toIconRequest()?.let { loadRequest(it) } message.toIconRequest(session.private)?.let { loadRequest(it) } } else { throw IllegalStateException("Received unexpected message: $message") } Loading components/browser/icons/src/main/java/mozilla/components/browser/icons/processor/DiskIconProcessor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class DiskIconProcessor( icon: Icon, desiredSize: DesiredSize ): Icon { if (resource != null && icon.shouldCacheOnDisk) { if (resource != null && icon.shouldCacheOnDisk && !request.isPrivate) { cache.put(context, request, resource, icon) } Loading components/browser/icons/src/test/java/mozilla/components/browser/icons/processor/DiskIconProcessorTest.kt +31 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import mozilla.components.support.test.mock import org.junit.Test import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` class DiskIconProcessorTest { @Test Loading Loading @@ -83,4 +84,34 @@ class DiskIconProcessorTest { verify(cache, never()).put(any(), any(), any(), eq(icon)) } @Test fun `Icon loaded in private mode is not saved in cache`() { /* Can be Source.INLINE as well. To ensure that the icon is eligible for caching on the disk. */ val icon = Icon(mock(), source = Icon.Source.DOWNLOAD) val cache: DiskIconProcessor.ProcessorDiskCache = mock() val processor = DiskIconProcessor(cache) val request: IconRequest = mock() `when`(request.isPrivate).thenReturn(true) val resource: IconRequest.Resource = mock() processor.process(context = mock(), request = request, resource = resource, icon = icon, desiredSize = mock()) verify(cache, never()).put(any(), any(), any(), eq(icon)) } @Test fun `Icon loaded in non-private mode is saved in cache`() { /* Can be Source.INLINE as well. To ensure that the icon is eligible for caching on the disk. */ val icon = Icon(mock(), source = Icon.Source.DOWNLOAD) val cache: DiskIconProcessor.ProcessorDiskCache = mock() val processor = DiskIconProcessor(cache) val request: IconRequest = mock() `when`(request.isPrivate).thenReturn(false) val resource: IconRequest.Resource = mock() processor.process(context = mock(), request = request, resource = resource, icon = icon, desiredSize = mock()) verify(cache).put(any(), eq(request), eq(resource), eq(icon)) } } Loading
components/browser/icons/src/main/java/mozilla/components/browser/icons/IconRequest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,8 @@ data class IconRequest( val url: String, val size: Size = Size.DEFAULT, val resources: List<Resource> = emptyList(), @ColorInt val color: Int? = null @ColorInt val color: Int? = null, val isPrivate: Boolean = false ) { /** Loading
components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt +2 −2 Original line number Diff line number Diff line Loading @@ -62,11 +62,11 @@ internal fun List<IconRequest.Resource>.toJSON(): JSONArray { }.toJSONArray() } internal fun JSONObject.toIconRequest(): IconRequest? { internal fun JSONObject.toIconRequest(isPrivate: Boolean): IconRequest? { return try { val url = getString("url") IconRequest(url, resources = getJSONArray("icons").toIconResources()) IconRequest(url, isPrivate = isPrivate, resources = getJSONArray("icons").toIconResources()) } catch (e: JSONException) { Logger.warn("Could not parse message from icons extensions", e) null Loading
components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessageHandler.kt +1 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ internal class IconMessageHandler( override fun onMessage(message: Any, source: EngineSession?): Any { if (message is JSONObject) { message.toIconRequest()?.let { loadRequest(it) } message.toIconRequest(session.private)?.let { loadRequest(it) } } else { throw IllegalStateException("Received unexpected message: $message") } Loading
components/browser/icons/src/main/java/mozilla/components/browser/icons/processor/DiskIconProcessor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class DiskIconProcessor( icon: Icon, desiredSize: DesiredSize ): Icon { if (resource != null && icon.shouldCacheOnDisk) { if (resource != null && icon.shouldCacheOnDisk && !request.isPrivate) { cache.put(context, request, resource, icon) } Loading
components/browser/icons/src/test/java/mozilla/components/browser/icons/processor/DiskIconProcessorTest.kt +31 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import mozilla.components.support.test.mock import org.junit.Test import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` class DiskIconProcessorTest { @Test Loading Loading @@ -83,4 +84,34 @@ class DiskIconProcessorTest { verify(cache, never()).put(any(), any(), any(), eq(icon)) } @Test fun `Icon loaded in private mode is not saved in cache`() { /* Can be Source.INLINE as well. To ensure that the icon is eligible for caching on the disk. */ val icon = Icon(mock(), source = Icon.Source.DOWNLOAD) val cache: DiskIconProcessor.ProcessorDiskCache = mock() val processor = DiskIconProcessor(cache) val request: IconRequest = mock() `when`(request.isPrivate).thenReturn(true) val resource: IconRequest.Resource = mock() processor.process(context = mock(), request = request, resource = resource, icon = icon, desiredSize = mock()) verify(cache, never()).put(any(), any(), any(), eq(icon)) } @Test fun `Icon loaded in non-private mode is saved in cache`() { /* Can be Source.INLINE as well. To ensure that the icon is eligible for caching on the disk. */ val icon = Icon(mock(), source = Icon.Source.DOWNLOAD) val cache: DiskIconProcessor.ProcessorDiskCache = mock() val processor = DiskIconProcessor(cache) val request: IconRequest = mock() `when`(request.isPrivate).thenReturn(false) val resource: IconRequest.Resource = mock() processor.process(context = mock(), request = request, resource = resource, icon = icon, desiredSize = mock()) verify(cache).put(any(), eq(request), eq(resource), eq(icon)) } }