summaryrefslogtreecommitdiff
path: root/app/src/test/java/org/terst/feedreader/ui
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/org/terst/feedreader/ui')
-rw-r--r--app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt49
1 files changed, 46 insertions, 3 deletions
diff --git a/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt b/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
index 3f7078d..aead885 100644
--- a/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
+++ b/app/src/test/java/org/terst/feedreader/ui/ImageZoomTest.kt
@@ -38,14 +38,46 @@ class ImageZoomTest {
}
@Test
- fun `a relative image source is left alone`() {
- // Relative srcs resolve against the WebView's base URL, which a custom-scheme href
- // can't reproduce -- better to leave the image un-zoomable than to build a dead link.
+ fun `a relative image source is left alone when nothing says where it came from`() {
+ // Relative srcs resolve against the WebView's base URL -- with no base URL to resolve
+ // against, better to leave the image un-zoomable than to build a dead link.
val original = """<img src="/local/a.jpg">"""
assertEquals(original, linkifyImagesForZoom(original))
}
@Test
+ fun `a site-relative image source resolves against the page it came from`() {
+ // Verbatim shape of the Ftrain feed's own markup, which is where this surfaced:
+ // every image in <content:encoded> is site-relative, so none of them were zoomable.
+ val html = linkifyImagesForZoom(
+ """<img src="/art/uploads/header.png" alt="x">""",
+ baseUrl = "https://ftrain.com/aboard-let-s-have-a-mouse-party"
+ )
+ assertEquals(
+ """<a href="feedreader-image:https://ftrain.com/art/uploads/header.png">""" +
+ """<img src="/art/uploads/header.png" alt="x"></a>""",
+ html
+ )
+ }
+
+ @Test
+ fun `a path-relative image source resolves against the article's own directory`() {
+ val html = linkifyImagesForZoom(
+ """<img src="pic.png">""",
+ baseUrl = "https://ex.com/posts/2026/hello"
+ )
+ assertTrue(html.contains("""<a href="feedreader-image:https://ex.com/posts/2026/pic.png">"""))
+ }
+
+ @Test
+ fun `a data uri image is still left alone when there is a page url`() {
+ // Resolving a data: src against a base URL just gives the data: URI back -- it is
+ // not something the viewer could ever open, so it must not become a zoom target.
+ val original = """<img src="data:image/png;base64,AAAA">"""
+ assertEquals(original, linkifyImagesForZoom(original, baseUrl = "https://ex.com/post"))
+ }
+
+ @Test
fun `a data uri image is left alone`() {
val original = """<img src="data:image/png;base64,AAAA">"""
assertEquals(original, linkifyImagesForZoom(original))
@@ -87,6 +119,17 @@ class ImageZoomTest {
}
@Test
+ fun `reader html makes a feed article's relative images zoomable`() {
+ // The non-reader path renders the feed's own HTML, which routinely keeps relative
+ // srcs -- the reader path never hits this because Readability absolutizes them.
+ val html = wrapReaderHtml(
+ """<p>x</p><img src="/art/a.png">""",
+ baseUrl = "https://ftrain.com/aboard-let-s-have-a-mouse-party"
+ )
+ assertTrue(html.contains("""<a href="feedreader-image:https://ftrain.com/art/a.png">"""))
+ }
+
+ @Test
fun `reader html makes the synthesized hero image zoomable too`() {
val html = wrapReaderHtml("<p>no image of its own</p>", imageUrl = "https://ex.com/hero.jpg")
assertTrue(html.contains("""<a href="feedreader-image:https://ex.com/hero.jpg">"""))