+
+ #[test]
+ fn test_resolve_image_url() {
+ // url that lists the opengraph fields
+ let url = Url::parse("https://example.com/one/two.html").unwrap();
+
+ // root relative url
+ let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='/image.jpg'></head><body></body></html>";
+ let metadata = html_to_site_metadata(html_bytes, &url).expect("Unable to parse metadata");
+ assert_eq!(
+ metadata.image,
+ Some(Url::parse("https://example.com/image.jpg").unwrap().into())
+ );
+
+ // base relative url
+ let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='image.jpg'></head><body></body></html>";
+ let metadata = html_to_site_metadata(html_bytes, &url).expect("Unable to parse metadata");
+ assert_eq!(
+ metadata.image,
+ Some(
+ Url::parse("https://example.com/one/image.jpg")
+ .unwrap()
+ .into()
+ )
+ );
+
+ // absolute url
+ let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='https://cdn.host.com/image.jpg'></head><body></body></html>";
+ let metadata = html_to_site_metadata(html_bytes, &url).expect("Unable to parse metadata");
+ assert_eq!(
+ metadata.image,
+ Some(Url::parse("https://cdn.host.com/image.jpg").unwrap().into())
+ );
+
+ // protocol relative url
+ let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='//example.com/image.jpg'></head><body></body></html>";
+ let metadata = html_to_site_metadata(html_bytes, &url).expect("Unable to parse metadata");
+ assert_eq!(
+ metadata.image,
+ Some(Url::parse("https://example.com/image.jpg").unwrap().into())
+ );
+ }