aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/tests/mime_classifier.rs
diff options
context:
space:
mode:
authorBastien Orivel <eijebong@bananium.fr>2018-08-27 18:36:52 +0200
committerBastien Orivel <eijebong@bananium.fr>2018-11-01 19:17:36 +0100
commit024b40b39d3848f1a1f7020bd7ed8c901817f09c (patch)
tree27508f102b0973cbae3dca22143ea4aedd349f4b /components/net/tests/mime_classifier.rs
parent95bfaa0a770479fb3bf6bf0b1f85c9ae343e66ff (diff)
downloadservo-024b40b39d3848f1a1f7020bd7ed8c901817f09c.tar.gz
servo-024b40b39d3848f1a1f7020bd7ed8c901817f09c.zip
Update hyper to 0.12
Diffstat (limited to 'components/net/tests/mime_classifier.rs')
-rw-r--r--components/net/tests/mime_classifier.rs305
1 files changed, 148 insertions, 157 deletions
diff --git a/components/net/tests/mime_classifier.rs b/components/net/tests/mime_classifier.rs
index 1a4757ded5f..593017c7f2c 100644
--- a/components/net/tests/mime_classifier.rs
+++ b/components/net/tests/mime_classifier.rs
@@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use mime::{self, Mime};
use net::mime_classifier::{ApacheBugFlag, MimeClassifier, Mp4Matcher, NoSniffFlag};
-use net::mime_classifier::as_string_option;
use net_traits::LoadContext;
use std::env;
use std::fs::File;
@@ -58,11 +58,10 @@ fn test_validate_classifier() {
#[cfg(test)]
fn test_sniff_with_flags(filename_orig: &path::Path,
- type_string: &str,
- subtype_string: &str,
- supplied_type: Option<(&'static str, &'static str)>,
- no_sniff_flag: NoSniffFlag,
- apache_bug_flag: ApacheBugFlag) {
+ expected_mime: Mime,
+ supplied_type: Option<Mime>,
+ no_sniff_flag: NoSniffFlag,
+ apache_bug_flag: ApacheBugFlag) {
let current_working_directory = env::current_dir().unwrap();
println!("The current directory is {}", current_working_directory.display());
@@ -75,17 +74,15 @@ fn test_sniff_with_flags(filename_orig: &path::Path,
match read_result {
Ok(data) => {
- let supplied_type = supplied_type.map(|(x, y)| (x.parse().unwrap(), y));
- let (parsed_type, parsed_subtp) = classifier.classify(LoadContext::Browsing,
- no_sniff_flag,
- apache_bug_flag,
- &as_string_option(supplied_type),
- &data);
- if (&parsed_type[..] != type_string) ||
- (&parsed_subtp[..] != subtype_string) {
- panic!("File {:?} parsed incorrectly should be {}/{}, parsed as {}/{}",
- filename, type_string, subtype_string,
- parsed_type, parsed_subtp);
+ let parsed_mime = classifier.classify(LoadContext::Browsing,
+ no_sniff_flag,
+ apache_bug_flag,
+ &supplied_type,
+ &data);
+ if (parsed_mime.type_() != expected_mime.type_()) ||
+ (parsed_mime.subtype() != expected_mime.subtype()) {
+ panic!("File {:?} parsed incorrectly should be {:?}, parsed as {:?}",
+ filename, expected_mime, parsed_mime);
}
}
Err(e) => panic!("Couldn't read from file {:?} with error {}",
@@ -94,407 +91,407 @@ fn test_sniff_with_flags(filename_orig: &path::Path,
}
#[cfg(test)]
-fn test_sniff_full(filename_orig: &path::Path, type_string: &str, subtype_string: &str,
- supplied_type: Option<(&'static str, &'static str)>) {
+fn test_sniff_full(filename_orig: &path::Path, expected_mime: Mime,
+ supplied_type: Option<Mime>) {
test_sniff_with_flags(filename_orig,
- type_string,
- subtype_string,
+ expected_mime,
supplied_type,
NoSniffFlag::Off,
ApacheBugFlag::Off)
}
#[cfg(test)]
-fn test_sniff_classification(file: &str, type_string: &str, subtype_string: &str,
- supplied_type: Option<(&'static str, &'static str)>) {
+fn test_sniff_classification(file: &str, expected_mime: Mime, supplied_type: Option<Mime>) {
let mut x = PathBuf::from("./");
- x.push(type_string);
- x.push(subtype_string);
+ x.push(expected_mime.type_().as_str());
+ x.push(expected_mime.subtype().as_str());
x.push(file);
- test_sniff_full(&x, type_string, subtype_string, supplied_type);
+ test_sniff_full(&x, expected_mime, supplied_type);
}
#[cfg(test)]
-fn test_sniff_classification_sup(file: &str, type_string: &'static str, subtype_string: &str) {
- test_sniff_classification(file, type_string, subtype_string, None);
- let class_type = Some((type_string, ""));
- test_sniff_classification(file, type_string, subtype_string, class_type);
+fn test_sniff_classification_sup(file: &str, expected_mime: Mime) {
+ test_sniff_classification(file, expected_mime.clone(), None);
+ let no_sub = format!("{}/", expected_mime.type_()).parse().unwrap();
+ test_sniff_classification(file, expected_mime, Some(no_sub));
}
#[test]
fn test_sniff_x_icon() {
- test_sniff_classification_sup("test.ico", "image", "x-icon");
+ test_sniff_classification_sup("test.ico", "image/x-icon".parse().unwrap());
}
#[test]
fn test_sniff_x_icon_cursor() {
- test_sniff_classification_sup("test_cursor.ico", "image", "x-icon");
+ test_sniff_classification_sup("test_cursor.ico", "image/x-icon".parse().unwrap());
}
#[test]
fn test_sniff_bmp() {
- test_sniff_classification_sup("test.bmp", "image", "bmp");
+ test_sniff_classification_sup("test.bmp", mime::IMAGE_BMP);
}
#[test]
fn test_sniff_gif87a() {
- test_sniff_classification_sup("test87a", "image", "gif");
+ test_sniff_classification_sup("test87a", mime::IMAGE_GIF);
}
#[test]
fn test_sniff_gif89a() {
- test_sniff_classification_sup("test89a.gif", "image", "gif");
+ test_sniff_classification_sup("test89a.gif", mime::IMAGE_GIF);
}
#[test]
fn test_sniff_webp() {
- test_sniff_classification_sup("test.webp", "image", "webp");
+ test_sniff_classification_sup("test.webp", "image/webp".parse().unwrap());
}
#[test]
fn test_sniff_png() {
- test_sniff_classification_sup("test.png", "image", "png");
+ test_sniff_classification_sup("test.png", mime::IMAGE_PNG);
}
#[test]
fn test_sniff_jpg() {
- test_sniff_classification_sup("test.jpg", "image", "jpeg");
+ test_sniff_classification_sup("test.jpg", mime::IMAGE_JPEG);
}
#[test]
fn test_sniff_webm() {
- test_sniff_classification_sup("test.webm", "video", "webm");
+ test_sniff_classification_sup("test.webm", "video/webm".parse().unwrap());
}
#[test]
fn test_sniff_mp4() {
- test_sniff_classification_sup("test.mp4", "video", "mp4");
+ test_sniff_classification_sup("test.mp4", "video/mp4".parse().unwrap());
}
#[test]
fn test_sniff_avi() {
- test_sniff_classification_sup("test.avi", "video", "avi");
+ test_sniff_classification_sup("test.avi", "video/avi".parse().unwrap());
}
#[test]
fn test_sniff_basic() {
- test_sniff_classification_sup("test.au", "audio", "basic");
+ test_sniff_classification_sup("test.au", "audio/basic".parse().unwrap());
}
#[test]
fn test_sniff_aiff() {
- test_sniff_classification_sup("test.aif", "audio", "aiff");
+ test_sniff_classification_sup("test.aif", "audio/aiff".parse().unwrap());
}
#[test]
fn test_sniff_mpeg() {
- test_sniff_classification_sup("test.mp3", "audio", "mpeg");
+ test_sniff_classification_sup("test.mp3", "audio/mpeg".parse().unwrap());
}
#[test]
fn test_sniff_midi() {
- test_sniff_classification_sup("test.mid", "audio", "midi");
+ test_sniff_classification_sup("test.mid", "audio/midi".parse().unwrap());
}
#[test]
fn test_sniff_wave() {
- test_sniff_classification_sup("test.wav", "audio", "wave");
+ test_sniff_classification_sup("test.wav", "audio/wave".parse().unwrap());
}
#[test]
fn test_sniff_ogg() {
- test_sniff_classification("small.ogg", "application", "ogg", None);
- test_sniff_classification("small.ogg", "application", "ogg", Some(("audio", "")));
+ test_sniff_classification("small.ogg", "application/ogg".parse().unwrap(), None);
+ test_sniff_classification("small.ogg", "application/ogg".parse().unwrap(), Some("audio/".parse().unwrap()));
}
#[test]
#[should_panic]
fn test_sniff_vsn_ms_fontobject() {
- test_sniff_classification_sup("vnd.ms-fontobject", "application", "vnd.ms-fontobject");
+ test_sniff_classification_sup("vnd.ms-fontobject", "application/vnd.ms-fontobject".parse().unwrap());
}
#[test]
#[should_panic]
fn test_sniff_true_type() {
- test_sniff_full(&PathBuf::from("unknown/true_type.ttf"), "(TrueType)", "", None);
+ test_sniff_full(&PathBuf::from("unknown/true_type.ttf"), "(TrueType)/".parse().unwrap(), None);
}
#[test]
#[should_panic]
fn test_sniff_open_type() {
- test_sniff_full(&PathBuf::from("unknown/open_type"), "(OpenType)", "", None);
+ test_sniff_full(&PathBuf::from("unknown/open_type"), "(OpenType)/".parse().unwrap(), None);
}
#[test]
#[should_panic]
fn test_sniff_true_type_collection() {
- test_sniff_full(&PathBuf::from("unknown/true_type_collection.ttc"), "(TrueType Collection)", "", None);
+ test_sniff_full(&PathBuf::from("unknown/true_type_collection.ttc"), "(TrueType Collection)/".parse().unwrap(),
+ None);
}
#[test]
#[should_panic]
fn test_sniff_woff() {
- test_sniff_classification_sup("test.wof", "application", "font-woff");
+ test_sniff_classification_sup("test.wof", "application/font-woff".parse().unwrap());
}
#[test]
fn test_sniff_gzip() {
- test_sniff_classification("test.gz", "application", "x-gzip", None);
+ test_sniff_classification("test.gz", "application/x-gzip".parse().unwrap(), None);
}
#[test]
fn test_sniff_zip() {
- test_sniff_classification("test.zip", "application", "zip", None);
+ test_sniff_classification("test.zip", "application/zip".parse().unwrap(), None);
}
#[test]
fn test_sniff_rar() {
- test_sniff_classification("test.rar", "application", "x-rar-compressed", None);
+ test_sniff_classification("test.rar", "application/x-rar-compressed".parse().unwrap(), None);
}
#[test]
fn test_sniff_text_html_doctype_20() {
- test_sniff_classification("text_html_doctype_20.html", "text", "html", None);
- test_sniff_classification("text_html_doctype_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_doctype_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_doctype_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_doctype_3e() {
- test_sniff_classification("text_html_doctype_3e.html", "text", "html", None);
- test_sniff_classification("text_html_doctype_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_doctype_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_doctype_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_page_20() {
- test_sniff_classification("text_html_page_20.html", "text", "html", None);
- test_sniff_classification("text_html_page_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_page_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_page_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_page_3e() {
- test_sniff_classification("text_html_page_3e.html", "text", "html", None);
- test_sniff_classification("text_html_page_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_page_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_page_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_head_20() {
- test_sniff_classification("text_html_head_20.html", "text", "html", None);
- test_sniff_classification("text_html_head_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_head_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_head_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_head_3e() {
- test_sniff_classification("text_html_head_3e.html", "text", "html", None);
- test_sniff_classification("text_html_head_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_head_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_head_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_script_20() {
- test_sniff_classification("text_html_script_20.html", "text", "html", None);
- test_sniff_classification("text_html_script_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_script_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_script_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_script_3e() {
- test_sniff_classification("text_html_script_3e.html", "text", "html", None);
- test_sniff_classification("text_html_script_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_script_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_script_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_iframe_20() {
- test_sniff_classification("text_html_iframe_20.html", "text", "html", None);
- test_sniff_classification("text_html_iframe_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_iframe_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_iframe_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_iframe_3e() {
- test_sniff_classification("text_html_iframe_3e.html", "text", "html", None);
- test_sniff_classification("text_html_iframe_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_iframe_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_iframe_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_h1_20() {
- test_sniff_classification("text_html_h1_20.html", "text", "html", None);
- test_sniff_classification("text_html_h1_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_h1_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_h1_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_h1_3e() {
- test_sniff_classification("text_html_h1_3e.html", "text", "html", None);
- test_sniff_classification("text_html_h1_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_h1_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_h1_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_div_20() {
- test_sniff_classification("text_html_div_20.html", "text", "html", None);
- test_sniff_classification("text_html_div_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_div_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_div_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_div_3e() {
- test_sniff_classification("text_html_div_3e.html", "text", "html", None);
- test_sniff_classification("text_html_div_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_div_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_div_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_font_20() {
- test_sniff_classification("text_html_font_20.html", "text", "html", None);
- test_sniff_classification("text_html_font_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_font_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_font_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_font_3e() {
- test_sniff_classification("text_html_font_3e.html", "text", "html", None);
- test_sniff_classification("text_html_font_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_font_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_font_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_table_20() {
- test_sniff_classification("text_html_table_20.html", "text", "html", None);
- test_sniff_classification("text_html_table_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_table_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_table_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_table_3e() {
- test_sniff_classification("text_html_table_3e.html", "text", "html", None);
- test_sniff_classification("text_html_table_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_table_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_table_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_a_20() {
- test_sniff_classification("text_html_a_20.html", "text", "html", None);
- test_sniff_classification("text_html_a_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_a_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_a_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_a_3e() {
- test_sniff_classification("text_html_a_3e.html", "text", "html", None);
- test_sniff_classification("text_html_a_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_a_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_a_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_style_20() {
- test_sniff_classification("text_html_style_20.html", "text", "html", None);
- test_sniff_classification("text_html_style_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_style_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_style_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_style_3e() {
- test_sniff_classification("text_html_style_3e.html", "text", "html", None);
- test_sniff_classification("text_html_style_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_style_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_style_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_title_20() {
- test_sniff_classification("text_html_title_20.html", "text", "html", None);
- test_sniff_classification("text_html_title_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_title_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_title_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_title_3e() {
- test_sniff_classification("text_html_title_3e.html", "text", "html", None);
- test_sniff_classification("text_html_title_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_title_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_title_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_b_20() {
- test_sniff_classification("text_html_b_20.html", "text", "html", None);
- test_sniff_classification("text_html_b_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_b_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_b_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_b_3e() {
- test_sniff_classification("text_html_b_3e.html", "text", "html", None);
- test_sniff_classification("text_html_b_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_b_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_b_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_body_20() {
- test_sniff_classification("text_html_body_20.html", "text", "html", None);
- test_sniff_classification("text_html_body_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_body_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_body_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_body_3e() {
- test_sniff_classification("text_html_body_3e.html", "text", "html", None);
- test_sniff_classification("text_html_body_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_body_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_body_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_br_20() {
- test_sniff_classification("text_html_br_20.html", "text", "html", None);
- test_sniff_classification("text_html_br_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_br_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_br_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_br_3e() {
- test_sniff_classification("text_html_br_3e.html", "text", "html", None);
- test_sniff_classification("text_html_br_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_br_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_br_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_p_20() {
- test_sniff_classification("text_html_p_20.html", "text", "html", None);
- test_sniff_classification("text_html_p_20_u.html", "text", "html", None);
+ test_sniff_classification("text_html_p_20.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_p_20_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_p_3e() {
- test_sniff_classification("text_html_p_3e.html", "text", "html", None);
- test_sniff_classification("text_html_p_3e_u.html", "text", "html", None);
+ test_sniff_classification("text_html_p_3e.html", mime::TEXT_HTML, None);
+ test_sniff_classification("text_html_p_3e_u.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_comment_20() {
- test_sniff_classification("text_html_comment_20.html", "text", "html", None);
+ test_sniff_classification("text_html_comment_20.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_text_html_comment_3e() {
- test_sniff_classification("text_html_comment_3e.html", "text", "html", None);
+ test_sniff_classification("text_html_comment_3e.html", mime::TEXT_HTML, None);
}
#[test]
fn test_sniff_xml() {
- test_sniff_classification("test.xml", "text", "xml", None);
+ test_sniff_classification("test.xml", mime::TEXT_XML, None);
}
#[test]
fn test_sniff_pdf() {
- test_sniff_classification("test.pdf", "application", "pdf", None);
+ test_sniff_classification("test.pdf", mime::APPLICATION_PDF, None);
}
#[test]
fn test_sniff_postscript() {
- test_sniff_classification("test.ps", "application", "postscript", None);
+ test_sniff_classification("test.ps", "application/postscript".parse().unwrap(), None);
}
#[test]
fn test_sniff_utf_16be_bom() {
- test_sniff_classification("utf16bebom.txt", "text", "plain", None);
+ test_sniff_classification("utf16bebom.txt", mime::TEXT_PLAIN, None);
}
#[test]
fn test_sniff_utf_16le_bom() {
- test_sniff_classification("utf16lebom.txt", "text", "plain", None);
+ test_sniff_classification("utf16lebom.txt", mime::TEXT_PLAIN, None);
}
#[test]
fn test_sniff_utf_8_bom() {
- test_sniff_classification("utf8bom.txt", "text", "plain", None);
+ test_sniff_classification("utf8bom.txt", mime::TEXT_PLAIN, None);
}
#[test]
fn test_sniff_rss_feed() {
// RSS feeds
- test_sniff_full(&PathBuf::from("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
- test_sniff_full(&PathBuf::from("text/xml/rdf_rss.xml"), "application", "rss+xml", Some(("text", "html")));
+ test_sniff_full(&PathBuf::from("text/xml/feed.rss"), "application/rss+xml".parse().unwrap(), Some(mime::TEXT_HTML));
+ test_sniff_full(&PathBuf::from("text/xml/rdf_rss.xml"), "application/rss+xml".parse().unwrap(),
+ Some(mime::TEXT_HTML));
// Not RSS feeds
- test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_1.xml"), "text", "html", Some(("text", "html")));
- test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_2.xml"), "text", "html", Some(("text", "html")));
- test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_3.xml"), "text", "html", Some(("text", "html")));
- test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_4.xml"), "text", "html", Some(("text", "html")));
+ test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_1.xml"), mime::TEXT_HTML, Some(mime::TEXT_HTML));
+ test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_2.xml"), mime::TEXT_HTML, Some(mime::TEXT_HTML));
+ test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_3.xml"), mime::TEXT_HTML, Some(mime::TEXT_HTML));
+ test_sniff_full(&PathBuf::from("text/xml/rdf_rss_ko_4.xml"), mime::TEXT_HTML, Some(mime::TEXT_HTML));
}
#[test]
fn test_sniff_atom_feed() {
- test_sniff_full(&PathBuf::from("text/xml/feed.atom"), "application", "atom+xml", Some(("text", "html")));
+ test_sniff_full(&PathBuf::from("text/xml/feed.atom"), "application/atom+xml".parse().unwrap(),
+ Some(mime::TEXT_HTML));
}
#[test]
fn test_sniff_binary_file() {
- test_sniff_full(&PathBuf::from("unknown/binary_file"), "application", "octet-stream", None);
+ test_sniff_full(&PathBuf::from("unknown/binary_file"), mime::APPLICATION_OCTET_STREAM, None);
}
#[test]
fn test_sniff_atom_feed_with_no_sniff_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/xml/feed.atom"),
- "text",
- "html",
- Some(("text", "html")),
+ mime::TEXT_HTML,
+ Some(mime::TEXT_HTML),
NoSniffFlag::On,
ApacheBugFlag::Off);
}
@@ -502,9 +499,8 @@ fn test_sniff_atom_feed_with_no_sniff_flag_on() {
#[test]
fn test_sniff_with_no_sniff_flag_on_and_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/xml/feed.atom"),
- "text",
- "html",
- Some(("text", "html")),
+ mime::TEXT_HTML,
+ Some(mime::TEXT_HTML),
NoSniffFlag::On,
ApacheBugFlag::On);
}
@@ -512,9 +508,8 @@ fn test_sniff_with_no_sniff_flag_on_and_apache_flag_on() {
#[test]
fn test_sniff_utf_8_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf8bom.txt"),
- "text",
- "plain",
- Some(("dummy", "text")),
+ mime::TEXT_PLAIN,
+ Some("dummy/text".parse().unwrap()),
NoSniffFlag::Off,
ApacheBugFlag::On);
}
@@ -522,9 +517,8 @@ fn test_sniff_utf_8_bom_with_apache_flag_on() {
#[test]
fn test_sniff_utf_16be_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf16bebom.txt"),
- "text",
- "plain",
- Some(("dummy", "text")),
+ mime::TEXT_PLAIN,
+ Some("dummy/text".parse().unwrap()),
NoSniffFlag::Off,
ApacheBugFlag::On);
}
@@ -532,9 +526,8 @@ fn test_sniff_utf_16be_bom_with_apache_flag_on() {
#[test]
fn test_sniff_utf_16le_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf16lebom.txt"),
- "text",
- "plain",
- Some(("dummy", "text")),
+ mime::TEXT_PLAIN,
+ Some("dummy/text".parse().unwrap()),
NoSniffFlag::Off,
ApacheBugFlag::On);
}
@@ -542,9 +535,8 @@ fn test_sniff_utf_16le_bom_with_apache_flag_on() {
#[test]
fn test_sniff_octet_stream_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("unknown/binary_file"),
- "application",
- "octet-stream",
- Some(("dummy", "binary")),
+ mime::APPLICATION_OCTET_STREAM,
+ Some("dummy/binary".parse().unwrap()),
NoSniffFlag::Off,
ApacheBugFlag::On);
}
@@ -552,9 +544,8 @@ fn test_sniff_octet_stream_apache_flag_on() {
#[test]
fn test_sniff_mp4_video_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("video/mp4/test.mp4"),
- "application",
- "octet-stream",
- Some(("video", "mp4")),
+ mime::APPLICATION_OCTET_STREAM,
+ Some("video/mp4".parse().unwrap()),
NoSniffFlag::Off,
ApacheBugFlag::On);
}