Reduce card image transfers and list metadata payloads
This commit is contained in:
parent
f4fb6e22c9
commit
e340d470c1
10 changed files with 152 additions and 31 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package org.justinvisser.wolfskin.design
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/** Card URLs bound server work and transfer size, while hero quality and cache identity stay intact. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], application = Application::class)
|
||||
class WolfskinImagesTest {
|
||||
private data class Surface(val name: String, val width: Int, val height: Int, val tier: String, val hero: Boolean = false)
|
||||
private val surfaces = listOf(
|
||||
Surface("grid/Home/Discover/person poster", 256, 384, "w342"),
|
||||
Surface("Home tile", 400, 225, "w780"),
|
||||
Surface("Home wide", 544, 306, "w780"),
|
||||
Surface("episode still", 400, 280, "w780"),
|
||||
Surface("cast portrait", 200, 200, "w342"),
|
||||
Surface("person portrait", 240, 240, "w342"),
|
||||
Surface("hero poster", 420, 630, "w342", true),
|
||||
Surface("Home/Discover/title hero", 1920, 1080, "w1280", true),
|
||||
)
|
||||
|
||||
private fun request(source: Any, surface: Surface): Any = WolfskinImages.request(
|
||||
RuntimeEnvironment.getApplication(), source, surface.width, surface.height, surface.height > surface.width).data
|
||||
|
||||
@Test fun jellyfinSurfacesReplaceStaleDimensionsAndEncodingWithoutLosingIdentity() {
|
||||
for (surface in surfaces) {
|
||||
val source = "https://jelly.example/Items/123/Images/Backdrop/0?tag=stable&api_key=kept&MaxWidth=1280&height=720&FillHeight=720&Quality=96&Format=Png"
|
||||
val rewritten = request(source, surface).toString()
|
||||
val uri = Uri.parse(rewritten)
|
||||
assertEquals(surface.name, surface.width.toString(), uri.getQueryParameter("fillWidth"))
|
||||
assertEquals(surface.name, surface.height.toString(), uri.getQueryParameter("fillHeight"))
|
||||
assertEquals(surface.name, if (surface.hero) "Jpg" else "Webp", uri.getQueryParameter("format"))
|
||||
assertEquals(surface.name, if (surface.hero) "96" else "80", uri.getQueryParameter("quality"))
|
||||
assertEquals("stable", uri.getQueryParameter("tag"))
|
||||
assertEquals("kept", uri.getQueryParameter("api_key"))
|
||||
assertEquals(setOf("tag", "api_key", "fillWidth", "fillHeight", "format", "quality"), uri.queryParameterNames)
|
||||
assertEquals(rewritten, request(rewritten, surface))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun tmdbSurfacesNeverDownloadOriginalArtwork() {
|
||||
for (surface in surfaces) {
|
||||
for (oldTier in listOf("original", "w500", "w780")) {
|
||||
assertEquals(surface.name, "https://image.tmdb.org/t/p/${surface.tier}/art.jpg?identity=kept",
|
||||
request("https://image.tmdb.org/t/p/$oldTier/art.jpg?identity=kept", surface))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun localAndUnrelatedSourcesRemainUntouched() {
|
||||
for (source in listOf("file:///android_asset/poster.webp", "https://cdn.example/poster.jpg?width=800", "https://jelly.example/Users/123/Images/Primary", Uri.parse("content://art/1"))) {
|
||||
assertEquals(source, request(source, surfaces.first()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue