Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving the error handling out of network loader... #8851

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Updated the unit tests to include NetworkError

  • Loading branch information
wafflespeanut committed Feb 20, 2016
commit f033fc5c7207056926448049aaaaab8718297a58
@@ -295,13 +295,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,
@@ -310,7 +310,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,9 @@ use msg::constellation_msg::PipelineId;
use net::cookie::Cookie;
use net::cookie_storage::CookieStorage;
use net::hsts::{HSTSList};
use net::http_loader::{load, LoadError, HttpRequestFactory, HttpRequest, HttpResponse};
use net::http_loader::{load, LoadError, LoadErrorType, HttpRequestFactory, HttpRequest, HttpResponse};
use net::resource_thread::CancellationListener;
use net_traits::{LoadData, CookieSource, LoadContext};
use net_traits::{CookieSource, LoadData, LoadContext, NetworkError};
use std::borrow::Cow;
use std::io::{self, Write, Read, Cursor};
use std::sync::mpsc::Receiver;
@@ -1063,13 +1063,13 @@ fn test_load_errors_when_there_a_redirect_loop() {

let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));

match load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(LoadError::InvalidRedirect(_, msg)) => {
assert_eq!(msg, "redirect loop");
},
_ => panic!("expected max redirects to fail")
let load_result = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
match load_result {
Err(ref load_err) if load_err.error == LoadErrorType::InvalidRedirect =>
assert_eq!(&load_err.reason, "redirect loop"),
_ => panic!("expected max redirects to fail"),
}
}

@@ -1095,12 +1095,13 @@ fn test_load_errors_when_there_is_too_many_redirects() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));

match load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(LoadError::MaxRedirects(url)) => {
assert_eq!(url.domain().unwrap(), "mozilla.com")
},
_ => panic!("expected max redirects to fail")
let load_result = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
match load_result {
Err(ref load_err) if load_err.error == LoadErrorType::MaxRedirects =>
assert_eq!(load_err.url.domain().unwrap(), "mozilla.com"),
_ => panic!("expected max redirects to fail"),
}
}

@@ -1150,7 +1151,7 @@ impl HttpRequestFactory for DontConnectFactory {
type R = MockRequest;

fn create(&self, url: Url, _: Method) -> 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()))
}
}

@@ -1162,15 +1163,12 @@ fn test_load_errors_when_scheme_is_not_http_or_https() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));

match load::<MockRequest>(load_data,
hsts_list,
cookie_jar,
None,
&DontConnectFactory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None)) {
Err(LoadError::UnsupportedScheme(_)) => {}
_ => panic!("expected ftp scheme to be unsupported")
let load_result = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &DontConnectFactory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
match load_result {
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
_ => panic!("expected ftp scheme to be unsupported"),
}
}

@@ -1182,15 +1180,12 @@ fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_http
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));

match load::<MockRequest>(load_data,
hsts_list,
cookie_jar,
None,
&DontConnectFactory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None)) {
Err(LoadError::UnsupportedScheme(_)) => {}
_ => panic!("expected ftp scheme to be unsupported")
let load_result = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &DontConnectFactory,
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
match load_result {
Err(ref load_err) if load_err.error == LoadErrorType::UnsupportedScheme => (),
_ => panic!("expected ftp scheme to be unsupported"),
}
}

@@ -1225,14 +1220,11 @@ fn test_load_errors_when_cancelled() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));

match load::<MockRequest>(load_data,
hsts_list,
cookie_jar,
None,
&Factory,
DEFAULT_USER_AGENT.to_owned(),
&cancel_listener) {
Err(LoadError::Cancelled(_, _)) => (),
_ => panic!("expected load cancelled error!")
let load_result = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_owned(),
&cancel_listener);
match load_result {
Err(ref load_err) if load_err.error == LoadErrorType::Cancelled => (),
_ => panic!("expected load cancellation!"),
}
}
@@ -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;
@@ -215,9 +215,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();
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.