mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #5734 - marcusklaas:issue-5709, r=jdm
This closes issue https://github.com/servo/servo/issues/5709. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5734) <!-- Reviewable:end -->
This commit is contained in:
commit
2b3acd1f5d
3 changed files with 60 additions and 49 deletions
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#![feature(plugin)]
|
||||
#![cfg_attr(test, feature(net, alloc))]
|
||||
#![cfg_attr(test, feature(net, alloc, path, io))]
|
||||
|
||||
#![plugin(string_cache_plugin)]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use net_traits::image_cache_task::ImageResponseMsg::*;
|
|||
use net_traits::image_cache_task::Msg::*;
|
||||
|
||||
use net::resource_task::{start_sending, ProgressSender};
|
||||
use net_traits::{ControlMsg, Metadata, ProgressMsg, ResourceTask, ResponseSenders};
|
||||
use net_traits::{ControlMsg, Metadata, ResourceTask, ResponseSenders};
|
||||
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheTaskClient, ImageResponseMsg, Msg};
|
||||
use net_traits::ProgressMsg::{Payload, Done};
|
||||
use profile::time;
|
||||
|
@ -110,7 +110,7 @@ fn mock_resource_task<T: Closure + Send + 'static>(on_load: Box<T>) -> ResourceT
|
|||
spawn_listener(move |port: Receiver<ControlMsg>| {
|
||||
loop {
|
||||
match port.recv().unwrap() {
|
||||
ControlMsg::Load(response, consumer) => {
|
||||
ControlMsg::Load(_, consumer) => {
|
||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
||||
Url::parse("file:///fake").unwrap()));
|
||||
on_load.invoke(chan);
|
||||
|
@ -280,15 +280,15 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
|||
let mock_resource_task = spawn_listener(move |port: Receiver<ControlMsg>| {
|
||||
loop {
|
||||
match port.recv().unwrap() {
|
||||
ControlMsg::Load(response, consumer) => {
|
||||
ControlMsg::Load(_, consumer) => {
|
||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
||||
Url::parse("file:///fake").unwrap()));
|
||||
chan.send(Payload(test_image_bin()));
|
||||
chan.send(Done(Ok(())));
|
||||
image_bin_sent_chan.send(());
|
||||
chan.send(Payload(test_image_bin())).unwrap();
|
||||
chan.send(Done(Ok(()))).unwrap();
|
||||
image_bin_sent_chan.send(()).unwrap();
|
||||
}
|
||||
ControlMsg::Exit => {
|
||||
resource_task_exited_chan.send(());
|
||||
resource_task_exited_chan.send(()).unwrap();
|
||||
break
|
||||
}
|
||||
_ => {}
|
||||
|
@ -309,7 +309,7 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
|||
image_cache_task.send(Prefetch(url.clone()));
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
|
||||
resource_task_exited.recv().unwrap();
|
||||
|
||||
|
@ -329,15 +329,15 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
|||
let mock_resource_task = spawn_listener(move |port: Receiver<ControlMsg>| {
|
||||
loop {
|
||||
match port.recv().unwrap() {
|
||||
ControlMsg::Load(response, consumer) => {
|
||||
ControlMsg::Load(_, consumer) => {
|
||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
||||
Url::parse("file:///fake").unwrap()));
|
||||
chan.send(Payload(test_image_bin()));
|
||||
chan.send(Done(Err("".to_string())));
|
||||
image_bin_sent_chan.send(());
|
||||
chan.send(Payload(test_image_bin())).unwrap();
|
||||
chan.send(Done(Err("".to_string()))).unwrap();
|
||||
image_bin_sent_chan.send(()).unwrap();
|
||||
}
|
||||
ControlMsg::Exit => {
|
||||
resource_task_exited_chan.send(());
|
||||
resource_task_exited_chan.send(()).unwrap();
|
||||
break
|
||||
}
|
||||
_ => {}
|
||||
|
@ -360,7 +360,7 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
|||
image_cache_task.send(Decode(url.clone()));
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
|
||||
resource_task_exited.recv().unwrap();
|
||||
|
||||
|
@ -397,7 +397,7 @@ fn should_return_failed_if_image_bin_cannot_be_fetched() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -433,7 +433,7 @@ fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_f
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -463,7 +463,7 @@ fn should_return_failed_if_image_decode_fails() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -491,7 +491,7 @@ fn should_return_image_on_wait_if_image_is_already_loaded() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -511,7 +511,7 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
|
|||
let (response_chan, response_port) = channel();
|
||||
image_cache_task.send(Msg::WaitForImage(url, response_chan));
|
||||
|
||||
wait_chan.send(());
|
||||
wait_chan.send(()).unwrap();
|
||||
|
||||
match response_port.recv().unwrap() {
|
||||
ImageResponseMsg::ImageReady(..) => (),
|
||||
|
@ -519,7 +519,7 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -539,7 +539,7 @@ fn should_return_image_failed_on_wait_if_image_fails_to_load() {
|
|||
let (response_chan, response_port) = channel();
|
||||
image_cache_task.send(Msg::WaitForImage(url, response_chan));
|
||||
|
||||
wait_chan.send(());
|
||||
wait_chan.send(()).unwrap();
|
||||
|
||||
match response_port.recv().unwrap() {
|
||||
ImageResponseMsg::ImageFailed => (),
|
||||
|
@ -547,7 +547,7 @@ fn should_return_image_failed_on_wait_if_image_fails_to_load() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -570,5 +570,5 @@ fn sync_cache_should_wait_for_images() {
|
|||
}
|
||||
|
||||
image_cache_task.exit();
|
||||
mock_resource_task.send(ControlMsg::Exit);
|
||||
mock_resource_task.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
|
|
@ -2,19 +2,30 @@
|
|||
* 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 std::old_io::File;
|
||||
use std::os;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read};
|
||||
use std::env;
|
||||
use std::path::{self, PathBuf};
|
||||
use net::mime_classifier::Mp4Matcher;
|
||||
use net::mime_classifier::MIMEClassifier;
|
||||
use net::mime_classifier::as_string_option;
|
||||
|
||||
fn read_file(path: &path::Path) -> io::Result<Vec<u8>> {
|
||||
let mut file = try!(File::open(path));
|
||||
let mut buffer = Vec::new();
|
||||
|
||||
try!(file.read_to_end(&mut buffer));
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sniff_mp4_matcher() {
|
||||
let matcher = Mp4Matcher;
|
||||
|
||||
let p = Path::new("../../tests/unit/net/parsable_mime/video/mp4/test.mp4");
|
||||
let mut file = File::open(&p);
|
||||
let read_result = file.read_to_end();
|
||||
let p = PathBuf::new("../../tests/unit/net/parsable_mime/video/mp4/test.mp4");
|
||||
let read_result = read_file(&p);
|
||||
|
||||
match read_result {
|
||||
Ok(data) => {
|
||||
println!("Data Length {:?}",data.len());
|
||||
|
@ -27,42 +38,42 @@ fn test_sniff_mp4_matcher() {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_sniff_full(filename_orig: &Path,type_string: &str,subtype_string: &str,
|
||||
fn test_sniff_full(filename_orig: &path::Path,type_string: &str,subtype_string: &str,
|
||||
supplied_type: Option<(&'static str,&'static str)>){
|
||||
let current_working_directory = os::getcwd().unwrap();
|
||||
let current_working_directory = env::current_dir().unwrap();
|
||||
println!("The current directory is {}", current_working_directory.display());
|
||||
|
||||
let mut filename = Path::new("../../tests/unit/net/parsable_mime/");
|
||||
|
||||
let mut filename = PathBuf::new("../../tests/unit/net/parsable_mime/");
|
||||
filename.push(filename_orig);
|
||||
|
||||
let classifier = MIMEClassifier::new();
|
||||
|
||||
let mut file = File::open(&filename);
|
||||
let read_result = file.read_to_end();
|
||||
let read_result = read_file(&filename);
|
||||
|
||||
match read_result {
|
||||
Ok(data) => {
|
||||
match classifier.classify(false, false, &as_string_option(supplied_type), &data) {
|
||||
Some((parsed_type, parsed_subtp)) => {
|
||||
if (parsed_type.as_slice() != type_string) ||
|
||||
(parsed_subtp.as_slice() != subtype_string) {
|
||||
panic!("File {} parsed incorrectly should be {}/{}, parsed as {}/{}",
|
||||
filename.as_str().unwrap(), type_string, subtype_string,
|
||||
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);
|
||||
}
|
||||
}
|
||||
None => panic!("No classification found for {} with supplied type {:?}",
|
||||
filename.as_str().unwrap(), supplied_type),
|
||||
None => panic!("No classification found for {:?} with supplied type {:?}",
|
||||
filename, supplied_type),
|
||||
}
|
||||
}
|
||||
Err(e) => panic!("Couldn't read from file {} with error {}",
|
||||
filename.as_str().unwrap(), e),
|
||||
Err(e) => panic!("Couldn't read from file {:?} with error {}",
|
||||
filename, e),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_sniff_classification(file: &str,type_string: &str,subtype_string: &str,
|
||||
supplied_type: Option<(&'static str,&'static str)>){
|
||||
let mut x = Path::new("./");
|
||||
let mut x = PathBuf::new("./");
|
||||
x.push(type_string);
|
||||
x.push(subtype_string);
|
||||
x.push(file);
|
||||
|
@ -170,19 +181,19 @@ fn test_sniff_vsn_ms_fontobject() {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn test_sniff_true_type() {
|
||||
test_sniff_full(&Path::new("unknown/true_type.ttf"), "(TrueType)", "", None);
|
||||
test_sniff_full(&PathBuf::new("unknown/true_type.ttf"), "(TrueType)", "", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_sniff_open_type() {
|
||||
test_sniff_full(&Path::new("unknown/open_type"), "(OpenType)", "", None);
|
||||
test_sniff_full(&PathBuf::new("unknown/open_type"), "(OpenType)", "", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_sniff_true_type_collection() {
|
||||
test_sniff_full(&Path::new("unknown/true_type_collection.ttc"), "(TrueType Collection)", "", None);
|
||||
test_sniff_full(&PathBuf::new("unknown/true_type_collection.ttc"), "(TrueType Collection)", "", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -424,10 +435,10 @@ fn test_sniff_utf_8_bom() {
|
|||
|
||||
#[test]
|
||||
fn test_sniff_rss_feed() {
|
||||
test_sniff_full(&Path::new("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
|
||||
test_sniff_full(&PathBuf::new("text/xml/feed.rss"), "application", "rss+xml", Some(("text", "html")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sniff_atom_feed() {
|
||||
test_sniff_full(&Path::new("text/xml/feed.atom"), "application", "atom+xml", Some(("text", "html")));
|
||||
test_sniff_full(&PathBuf::new("text/xml/feed.atom"), "application", "atom+xml", Some(("text", "html")));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue