Test fixes; update for changes in spec

This commit is contained in:
Manish Goregaokar 2016-06-06 18:58:50 +05:30
parent f4e3e8e38e
commit fd6f9bd411
22 changed files with 320 additions and 269 deletions

View file

@ -14,7 +14,7 @@ use hyper::server::{Request as HyperRequest, Response as HyperResponse};
use hyper::status::StatusCode;
use hyper::uri::RequestUri;
use net::fetch::cors_cache::CORSCache;
use net::fetch::methods::{fetch, fetch_with_cors_cache};
use net::fetch::methods::{FetchContext, fetch, fetch_with_cors_cache};
use net::http_loader::HttpState;
use net_traits::FetchTaskTarget;
use net_traits::request::{Origin, RedirectMode, Referer, Request, RequestMode};
@ -22,10 +22,10 @@ use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
use std::fs::File;
use std::io::Read;
use std::rc::Rc;
use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Mutex};
use std::thread;
use time::{self, Duration};
use unicase::UniCase;
use url::{Origin as UrlOrigin, Url};
@ -37,6 +37,12 @@ struct FetchResponseCollector {
sender: Sender<Response>,
}
fn new_fetch_context() -> FetchContext {
FetchContext {
state: HttpState::new(),
user_agent: "Such Browser. Very Layout. Wow.".into(),
}
}
impl FetchTaskTarget for FetchResponseCollector {
fn process_request_body(&mut self, _: &Request) {}
fn process_request_eof(&mut self, _: &Request) {}
@ -50,7 +56,7 @@ impl FetchTaskTarget for FetchResponseCollector {
fn fetch_async(request: Request, target: Box<FetchTaskTarget + Send>) {
thread::spawn(move || {
fetch(Rc::new(request), &mut Some(target), HttpState::new());
fetch(Rc::new(request), &mut Some(target), new_fetch_context());
});
}
@ -77,7 +83,7 @@ fn test_fetch_response_is_not_network_error() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
if fetch_response.is_network_error() {
@ -98,7 +104,7 @@ fn test_fetch_response_body_matches_const_message() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -120,7 +126,7 @@ fn test_fetch_aboutblank() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert!(*fetch_response.body.lock().unwrap() == ResponseBody::Done(vec![]));
}
@ -132,7 +138,7 @@ fn test_fetch_data() {
let request = Request::new(url, Some(origin), false);
request.same_origin_data.set(true);
let expected_resp_body = "<p>Servo</p>".to_owned();
let fetch_response = fetch(Rc::new(request), &mut None, HttpState::new());
let fetch_response = fetch(Rc::new(request), &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 1);
@ -161,7 +167,7 @@ fn test_fetch_file() {
let request = Request::new(url, Some(origin), false);
request.same_origin_data.set(true);
let fetch_response = fetch(Rc::new(request), &mut None, HttpState::new());
let fetch_response = fetch(Rc::new(request), &mut None, new_fetch_context());
assert!(!fetch_response.is_network_error());
assert_eq!(fetch_response.headers.len(), 1);
let content_type: &ContentType = fetch_response.headers.get().unwrap();
@ -205,7 +211,7 @@ fn test_cors_preflight_fetch() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -245,8 +251,8 @@ fn test_cors_preflight_cache_fetch() {
let wrapped_request0 = Rc::new(request.clone());
let wrapped_request1 = Rc::new(request);
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache, &mut None, HttpState::new());
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache, &mut None, HttpState::new());
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache, &mut None, new_fetch_context());
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response0.is_network_error() && !fetch_response1.is_network_error());
@ -294,7 +300,7 @@ fn test_cors_preflight_fetch_network_error() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(fetch_response.is_network_error());
@ -317,7 +323,7 @@ fn test_fetch_response_is_basic_filtered() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -365,7 +371,7 @@ fn test_fetch_response_is_cors_filtered() {
request.mode = RequestMode::CORSMode;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -398,7 +404,7 @@ fn test_fetch_response_is_opaque_filtered() {
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -448,7 +454,7 @@ fn test_fetch_response_is_opaque_redirect_filtered() {
request.redirect_mode.set(RedirectMode::Manual);
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
assert!(!fetch_response.is_network_error());
@ -486,7 +492,7 @@ fn test_fetch_with_local_urls_only() {
request.local_urls_only = true;
let wrapped_request = Rc::new(request);
fetch(wrapped_request, &mut None, HttpState::new())
fetch(wrapped_request, &mut None, new_fetch_context())
};
let local_url = Url::parse("about:blank").unwrap();
@ -525,7 +531,7 @@ fn setup_server_and_fetch(message: &'static [u8], redirect_cap: u32) -> Response
*request.referer.borrow_mut() = Referer::NoReferer;
let wrapped_request = Rc::new(request);
let fetch_response = fetch(wrapped_request, &mut None, HttpState::new());
let fetch_response = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
fetch_response
}
@ -611,7 +617,7 @@ fn test_fetch_redirect_updates_method_runner(tx: Sender<bool>, status_code: Stat
*request.method.borrow_mut() = method;
let wrapped_request = Rc::new(request);
let _ = fetch(wrapped_request, &mut None, HttpState::new());
let _ = fetch(wrapped_request, &mut None, new_fetch_context());
let _ = server.close();
}