mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Updated the unit tests to include NetworkError
This commit is contained in:
parent
5e6f32a59b
commit
945a2c66e1
4 changed files with 22 additions and 23 deletions
|
@ -309,13 +309,13 @@ impl HttpRequest for WrappedHttpRequest {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LoadError {
|
pub struct LoadError {
|
||||||
url: Url,
|
pub url: Url,
|
||||||
error: LoadErrorType,
|
pub error: LoadErrorType,
|
||||||
reason: String,
|
pub reason: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoadError {
|
impl LoadError {
|
||||||
fn new(url: Url, error: LoadErrorType, reason: String) -> LoadError {
|
pub fn new(url: Url, error: LoadErrorType, reason: String) -> LoadError {
|
||||||
LoadError {
|
LoadError {
|
||||||
url: url,
|
url: url,
|
||||||
error: error,
|
error: error,
|
||||||
|
@ -324,7 +324,7 @@ impl LoadError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
pub enum LoadErrorType {
|
pub enum LoadErrorType {
|
||||||
Cancelled,
|
Cancelled,
|
||||||
Connection,
|
Connection,
|
||||||
|
|
|
@ -7,7 +7,7 @@ extern crate hyper;
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use net_traits::LoadConsumer::Channel;
|
use net_traits::LoadConsumer::Channel;
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use net_traits::{LoadData, LoadContext};
|
use net_traits::{LoadData, LoadContext, NetworkError};
|
||||||
use self::hyper::header::ContentType;
|
use self::hyper::header::ContentType;
|
||||||
use self::hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
use self::hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ fn assert_parse(url: &'static str,
|
||||||
|
|
||||||
match data {
|
match data {
|
||||||
None => {
|
None => {
|
||||||
assert_eq!(progress, Done(Err("invalid data uri".to_owned())));
|
assert_eq!(progress, Done(Err(NetworkError::Internal("invalid data uri".to_owned()))));
|
||||||
}
|
}
|
||||||
Some(dat) => {
|
Some(dat) => {
|
||||||
assert_eq!(progress, Payload(dat));
|
assert_eq!(progress, Payload(dat));
|
||||||
|
|
|
@ -20,9 +20,10 @@ use msg::constellation_msg::PipelineId;
|
||||||
use net::cookie::Cookie;
|
use net::cookie::Cookie;
|
||||||
use net::cookie_storage::CookieStorage;
|
use net::cookie_storage::CookieStorage;
|
||||||
use net::hsts::HstsEntry;
|
use net::hsts::HstsEntry;
|
||||||
|
use net::http_loader::LoadErrorType;
|
||||||
use net::http_loader::{load, LoadError, HttpRequestFactory, HttpRequest, HttpResponse, UIProvider, HttpState};
|
use net::http_loader::{load, LoadError, HttpRequestFactory, HttpRequest, HttpResponse, UIProvider, HttpState};
|
||||||
use net::resource_thread::{AuthCacheEntry, CancellationListener};
|
use net::resource_thread::{AuthCacheEntry, CancellationListener};
|
||||||
use net_traits::{LoadData, CookieSource, LoadContext, IncludeSubdomains};
|
use net_traits::{LoadData, CookieSource, LoadContext, NetworkError, IncludeSubdomains};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::{self, Write, Read, Cursor};
|
use std::io::{self, Write, Read, Cursor};
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
@ -1075,9 +1076,8 @@ fn test_load_errors_when_there_a_redirect_loop() {
|
||||||
|
|
||||||
match load(&load_data, &ui_provider, &http_state, None, &Factory,
|
match load(&load_data, &ui_provider, &http_state, None, &Factory,
|
||||||
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
|
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
|
||||||
Err(LoadError::InvalidRedirect(_, msg)) => {
|
Err(ref load_err) if load_err.error == LoadErrorType::InvalidRedirect =>
|
||||||
assert_eq!(msg, "redirect loop");
|
assert_eq!(&load_err.reason, "redirect loop"),
|
||||||
},
|
|
||||||
_ => panic!("expected max redirects to fail")
|
_ => panic!("expected max redirects to fail")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1110,10 +1110,11 @@ fn test_load_errors_when_there_is_too_many_redirects() {
|
||||||
|
|
||||||
match load(&load_data, &ui_provider, &http_state, None, &Factory,
|
match load(&load_data, &ui_provider, &http_state, None, &Factory,
|
||||||
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
|
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
|
||||||
Err(LoadError::MaxRedirects(url, num_redirects)) => {
|
Err(LoadError { error: LoadErrorType::MaxRedirects(num_redirects),
|
||||||
|
url, .. }) => {
|
||||||
assert_eq!(num_redirects, redirect_limit as u32);
|
assert_eq!(num_redirects, redirect_limit as u32);
|
||||||
assert_eq!(url.domain().unwrap(), "mozilla.com")
|
assert_eq!(url.domain().unwrap(), "mozilla.com");
|
||||||
},
|
}
|
||||||
_ => panic!("expected max redirects to fail")
|
_ => panic!("expected max redirects to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1166,7 +1167,7 @@ impl HttpRequestFactory for DontConnectFactory {
|
||||||
type R = MockRequest;
|
type R = MockRequest;
|
||||||
|
|
||||||
fn create(&self, url: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
|
fn create(&self, url: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
|
||||||
Err(LoadError::Connection(url, "should not have connected".to_owned()))
|
Err(LoadError::new(url, LoadErrorType::Connection, "should not have connected".to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1184,7 +1185,7 @@ fn test_load_errors_when_scheme_is_not_http_or_https() {
|
||||||
&DontConnectFactory,
|
&DontConnectFactory,
|
||||||
DEFAULT_USER_AGENT.to_owned(),
|
DEFAULT_USER_AGENT.to_owned(),
|
||||||
&CancellationListener::new(None)) {
|
&CancellationListener::new(None)) {
|
||||||
Err(LoadError::UnsupportedScheme(_)) => {}
|
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
|
||||||
_ => panic!("expected ftp scheme to be unsupported")
|
_ => panic!("expected ftp scheme to be unsupported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1203,7 +1204,7 @@ fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_http
|
||||||
&DontConnectFactory,
|
&DontConnectFactory,
|
||||||
DEFAULT_USER_AGENT.to_owned(),
|
DEFAULT_USER_AGENT.to_owned(),
|
||||||
&CancellationListener::new(None)) {
|
&CancellationListener::new(None)) {
|
||||||
Err(LoadError::UnsupportedScheme(_)) => {}
|
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
|
||||||
_ => panic!("expected ftp scheme to be unsupported")
|
_ => panic!("expected ftp scheme to be unsupported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1245,7 +1246,7 @@ fn test_load_errors_when_cancelled() {
|
||||||
&Factory,
|
&Factory,
|
||||||
DEFAULT_USER_AGENT.to_owned(),
|
DEFAULT_USER_AGENT.to_owned(),
|
||||||
&cancel_listener) {
|
&cancel_listener) {
|
||||||
Err(LoadError::Cancelled(_, _)) => (),
|
Err(ref load_err) if load_err.error == LoadErrorType::Cancelled => (),
|
||||||
_ => panic!("expected load cancelled error!")
|
_ => panic!("expected load cancelled error!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use net::resource_thread::new_resource_thread;
|
use net::resource_thread::new_resource_thread;
|
||||||
use net_traits::hosts::{parse_hostsfile, host_replacement};
|
use net_traits::hosts::{parse_hostsfile, host_replacement};
|
||||||
use net_traits::{ControlMsg, LoadData, LoadConsumer, ProgressMsg, LoadContext};
|
use net_traits::{ControlMsg, LoadData, LoadConsumer, LoadContext, NetworkError, ProgressMsg};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
@ -213,9 +213,7 @@ fn test_cancelled_listener() {
|
||||||
// (but, the loading has been cancelled)
|
// (but, the loading has been cancelled)
|
||||||
let _ = body_sender.send(body);
|
let _ = body_sender.send(body);
|
||||||
let response = receiver.recv().unwrap();
|
let response = receiver.recv().unwrap();
|
||||||
match response.progress_port.recv().unwrap() {
|
assert_eq!(response.progress_port.recv().unwrap(),
|
||||||
ProgressMsg::Done(result) => assert_eq!(result.unwrap_err(), "load cancelled".to_owned()),
|
ProgressMsg::Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
|
||||||
_ => panic!("baaaah!"),
|
|
||||||
}
|
|
||||||
resource_thread.send(ControlMsg::Exit).unwrap();
|
resource_thread.send(ControlMsg::Exit).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue