Skip to content

Commit

Permalink
Add a test for parsing YouTube favicons at the largest size available
Browse files Browse the repository at this point in the history
  • Loading branch information
chimbori committed Dec 26, 2024
1 parent 7526211 commit ce0ee17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/kotlin/com/chimbori/crux/plugins/FaviconExtractorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.chimbori.crux.plugins
import com.chimbori.crux.api.Fields.FAVICON_URL
import com.chimbori.crux.api.Resource
import com.chimbori.crux.common.fetchFromUrl
import com.chimbori.crux.common.fromTestData
import com.chimbori.crux.common.loggingOkHttpClient
import kotlinx.coroutines.runBlocking
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
Expand Down Expand Up @@ -55,4 +57,17 @@ class FaviconExtractorTest {
assertEquals(mockWebServer.url("/favicon.png"), parsed[FAVICON_URL])
}
}

@Test
fun testYouTubeFavicon() {
val candidateUrl = "https://youtube.com".toHttpUrl()
assertTrue(faviconExtractor.canExtract(candidateUrl))
runBlocking {
val parsed = faviconExtractor.extract(Resource.fromTestData(candidateUrl, "youtube.html"))
assertEquals(
"https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon_144x144.png".toHttpUrl(),
parsed[FAVICON_URL]
)
}
}
}
24 changes: 24 additions & 0 deletions test_data/youtube.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon.ico" type="image/x-icon">
<link rel="icon" href="https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon_32x32.png" sizes="32x32">
<link rel="icon" href="https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon_48x48.png" sizes="48x48">
<link rel="icon" href="https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon_96x96.png" sizes="96x96">
<link rel="icon" href="https://www.youtube.com/s/desktop/c01ea7e3/img/logos/favicon_144x144.png" sizes="144x144">
<title>YouTube</title>
<link rel="canonical" href="https://www.youtube.com/">
<link rel="alternate" media="handheld" href="https://m.youtube.com/">
<link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.youtube.com/">
<meta property="og:image" content="https://www.youtube.com/img/desktop/yt_1200.png">
<link rel="alternate" href="android-app://com.google.android.youtube/http/www.youtube.com/">
<link rel="alternate" href="ios-app://544007664/vnd.youtube/www.youtube.com/">
<meta name="description" content="Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.">
<meta name="keywords" content="video, sharing, camera phone, video phone, free, upload">
<meta name="theme-color" content="rgba(33, 33, 33, 0.98)">
<link rel="search" type="application/opensearchdescription+xml" href="https://www.youtube.com/opensearch?locale=en_US" title="YouTube">
<link rel="manifest" href="/manifest.webmanifest" crossorigin="use-credentials">
</head>
<body>
</body>
</html>

0 comments on commit ce0ee17

Please sign in to comment.