mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement cancellation listener for cancelling network requests
This commit is contained in:
parent
92f9e58310
commit
10f5584f78
11 changed files with 191 additions and 53 deletions
|
@ -18,13 +18,16 @@ fn assert_parse(url: &'static str,
|
|||
data: Option<Vec<u8>>) {
|
||||
use net::data_loader::load;
|
||||
use net::mime_classifier::MIMEClassifier;
|
||||
use net::resource_task::CancellationListener;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::channel;
|
||||
use url::Url;
|
||||
|
||||
let (start_chan, start_port) = ipc::channel().unwrap();
|
||||
let classifier = Arc::new(MIMEClassifier::new());
|
||||
load(LoadData::new(Url::parse(url).unwrap(), None), Channel(start_chan), classifier);
|
||||
load(LoadData::new(Url::parse(url).unwrap(), None),
|
||||
Channel(start_chan),
|
||||
classifier, CancellationListener::new(None));
|
||||
|
||||
let response = start_port.recv().unwrap();
|
||||
assert_eq!(&response.metadata.content_type, &content_type);
|
||||
|
|
|
@ -11,7 +11,6 @@ use std::collections::HashMap;
|
|||
use std::sync::mpsc::channel;
|
||||
use url::Url;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_exit() {
|
||||
let resource_task = new_resource_task("".to_owned(), None);
|
||||
|
@ -23,7 +22,7 @@ fn test_bad_scheme() {
|
|||
let resource_task = new_resource_task("".to_owned(), None);
|
||||
let (start_chan, start) = ipc::channel().unwrap();
|
||||
let url = Url::parse("bogus://whatever").unwrap();
|
||||
resource_task.send(ControlMsg::Load(LoadData::new(url, None), LoadConsumer::Channel(start_chan))).unwrap();
|
||||
resource_task.send(ControlMsg::Load(LoadData::new(url, None), LoadConsumer::Channel(start_chan), None)).unwrap();
|
||||
let response = start.recv().unwrap();
|
||||
match response.progress_port.recv().unwrap() {
|
||||
ProgressMsg::Done(result) => { assert!(result.is_err()) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue