mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35: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)]
|
||||
pub struct LoadError {
|
||||
url: Url,
|
||||
error: LoadErrorType,
|
||||
reason: String,
|
||||
pub url: Url,
|
||||
pub error: LoadErrorType,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
impl LoadError {
|
||||
fn new(url: Url, error: LoadErrorType, reason: String) -> LoadError {
|
||||
pub fn new(url: Url, error: LoadErrorType, reason: String) -> LoadError {
|
||||
LoadError {
|
||||
url: url,
|
||||
error: error,
|
||||
|
@ -324,7 +324,7 @@ impl LoadError {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Eq, PartialEq, Debug)]
|
||||
pub enum LoadErrorType {
|
||||
Cancelled,
|
||||
Connection,
|
||||
|
|
|
@ -7,7 +7,7 @@ extern crate hyper;
|
|||
use ipc_channel::ipc;
|
||||
use net_traits::LoadConsumer::Channel;
|
||||
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::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
||||
|
||||
|
@ -36,7 +36,7 @@ fn assert_parse(url: &'static str,
|
|||
|
||||
match data {
|
||||
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) => {
|
||||
assert_eq!(progress, Payload(dat));
|
||||
|
|
|
@ -20,9 +20,10 @@ use msg::constellation_msg::PipelineId;
|
|||
use net::cookie::Cookie;
|
||||
use net::cookie_storage::CookieStorage;
|
||||
use net::hsts::HstsEntry;
|
||||
use net::http_loader::LoadErrorType;
|
||||
use net::http_loader::{load, LoadError, HttpRequestFactory, HttpRequest, HttpResponse, UIProvider, HttpState};
|
||||
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::io::{self, Write, Read, Cursor};
|
||||
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,
|
||||
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
|
||||
Err(LoadError::InvalidRedirect(_, msg)) => {
|
||||
assert_eq!(msg, "redirect loop");
|
||||
},
|
||||
Err(ref load_err) if load_err.error == LoadErrorType::InvalidRedirect =>
|
||||
assert_eq!(&load_err.reason, "redirect loop"),
|
||||
_ => 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,
|
||||
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!(url.domain().unwrap(), "mozilla.com")
|
||||
},
|
||||
assert_eq!(url.domain().unwrap(), "mozilla.com");
|
||||
}
|
||||
_ => panic!("expected max redirects to fail")
|
||||
}
|
||||
|
||||
|
@ -1166,7 +1167,7 @@ impl HttpRequestFactory for DontConnectFactory {
|
|||
type R = MockRequest;
|
||||
|
||||
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,
|
||||
DEFAULT_USER_AGENT.to_owned(),
|
||||
&CancellationListener::new(None)) {
|
||||
Err(LoadError::UnsupportedScheme(_)) => {}
|
||||
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
|
||||
_ => 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,
|
||||
DEFAULT_USER_AGENT.to_owned(),
|
||||
&CancellationListener::new(None)) {
|
||||
Err(LoadError::UnsupportedScheme(_)) => {}
|
||||
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
|
||||
_ => panic!("expected ftp scheme to be unsupported")
|
||||
}
|
||||
}
|
||||
|
@ -1245,7 +1246,7 @@ fn test_load_errors_when_cancelled() {
|
|||
&Factory,
|
||||
DEFAULT_USER_AGENT.to_owned(),
|
||||
&cancel_listener) {
|
||||
Err(LoadError::Cancelled(_, _)) => (),
|
||||
Err(ref load_err) if load_err.error == LoadErrorType::Cancelled => (),
|
||||
_ => panic!("expected load cancelled error!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use ipc_channel::ipc;
|
||||
use net::resource_thread::new_resource_thread;
|
||||
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::collections::HashMap;
|
||||
use std::sync::mpsc::channel;
|
||||
|
@ -213,9 +213,7 @@ fn test_cancelled_listener() {
|
|||
// (but, the loading has been cancelled)
|
||||
let _ = body_sender.send(body);
|
||||
let response = receiver.recv().unwrap();
|
||||
match response.progress_port.recv().unwrap() {
|
||||
ProgressMsg::Done(result) => assert_eq!(result.unwrap_err(), "load cancelled".to_owned()),
|
||||
_ => panic!("baaaah!"),
|
||||
}
|
||||
assert_eq!(response.progress_port.recv().unwrap(),
|
||||
ProgressMsg::Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
|
||||
resource_thread.send(ControlMsg::Exit).unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue