// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗ // ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝ // ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗ // ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║ // ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝ // ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ #[cfg(test)] mod passing { use crate::html; use html5ever::serialize::{serialize, SerializeOpts}; use reqwest::blocking::Client; use std::collections::HashMap; #[test] fn basic() { let cache = &mut HashMap::new(); let html = "

"; let dom = html::html_to_dom(&html); let url = "http://localhost"; let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "

" ); } #[test] fn ensure_no_recursive_iframe() { let html = "

"; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "

" ); } #[test] fn ensure_no_recursive_frame() { let html = ""; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "" ); } #[test] fn no_css() { let html = "\ \
"; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = true; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "\ \ \ \ \ \
\ \ " ); } #[test] fn no_images() { let html = "\
"; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = true; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), format!( "\ \ \ \ \
\ \
\ \ ", empty_image = empty_image!() ) ); } #[test] fn no_body_background_images() { let html = ""; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = false; let opt_no_images: bool = true; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "" ); } #[test] fn no_frames() { let html = ""; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = true; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "" ); } #[test] fn no_iframes() { let html = ""; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = true; let opt_no_js: bool = false; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "" ); } #[test] fn no_js() { let html = "
\ \ \
"; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let opt_no_css: bool = false; let opt_no_fonts: bool = false; let opt_no_frames: bool = false; let opt_no_js: bool = true; let opt_no_images: bool = false; let opt_silent = true; let client = Client::new(); html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "
\
" ); } #[test] fn with_no_integrity() { let html = "No integrity\ \ "; let dom = html::html_to_dom(&html); let url = "http://localhost"; let cache = &mut HashMap::new(); let client = Client::new(); let opt_no_css: bool = true; let opt_no_fonts: bool = false; let opt_no_frames: bool = true; let opt_no_js: bool = true; let opt_no_images: bool = true; let opt_silent = true; html::walk_and_embed_assets( cache, &client, &url, &dom.document, opt_no_css, opt_no_fonts, opt_no_frames, opt_no_js, opt_no_images, opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); assert_eq!( buf.iter().map(|&c| c as char).collect::(), "\ No integrity\ \ " ); } }