Introduce fetch_with_cors_cache() API for tests.

This commit is contained in:
Ms2ger 2016-12-02 12:16:27 +01:00
parent 306905a631
commit 6f2606cdee
2 changed files with 15 additions and 5 deletions

View file

@ -7,6 +7,7 @@ use devtools_traits::DevtoolsControlMsg;
use devtools_traits::HttpRequest as DevtoolsHttpRequest; use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse; use devtools_traits::HttpResponse as DevtoolsHttpResponse;
use fetch_with_context; use fetch_with_context;
use fetch_with_cors_cache;
use http_loader::{expect_devtools_http_request, expect_devtools_http_response}; use http_loader::{expect_devtools_http_request, expect_devtools_http_response};
use hyper::LanguageTag; use hyper::LanguageTag;
use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowOrigin}; use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowOrigin};
@ -22,7 +23,6 @@ use hyper::status::StatusCode;
use hyper::uri::RequestUri; use hyper::uri::RequestUri;
use msg::constellation_msg::TEST_PIPELINE_ID; use msg::constellation_msg::TEST_PIPELINE_ID;
use net::fetch::cors_cache::CorsCache; use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::fetch_with_cors_cache;
use net_traits::ReferrerPolicy; use net_traits::ReferrerPolicy;
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode}; use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
use net_traits::response::{CacheState, Response, ResponseBody, ResponseType}; use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
@ -250,10 +250,8 @@ fn test_cors_preflight_cache_fetch() {
let wrapped_request0 = Rc::new(request.clone()); let wrapped_request0 = Rc::new(request.clone());
let wrapped_request1 = Rc::new(request); let wrapped_request1 = Rc::new(request);
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache, let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache);
&mut None, &new_fetch_context(None)); let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache);
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache,
&mut None, &new_fetch_context(None));
let _ = server.close(); let _ = server.close();
assert!(!fetch_response0.is_network_error() && !fetch_response1.is_network_error()); assert!(!fetch_response0.is_network_error() && !fetch_response1.is_network_error());

View file

@ -36,6 +36,7 @@ extern crate url;
use devtools_traits::DevtoolsControlMsg; use devtools_traits::DevtoolsControlMsg;
use hyper::server::{Handler, Listening, Server}; use hyper::server::{Handler, Listening, Server};
use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::{self, FetchContext}; use net::fetch::methods::{self, FetchContext};
use net::filemanager_thread::FileManager; use net::filemanager_thread::FileManager;
use net::test::HttpState; use net::test::HttpState;
@ -86,6 +87,17 @@ fn fetch_with_context(request: Request, context: &FetchContext) -> Response {
receiver.recv().unwrap() receiver.recv().unwrap()
} }
fn fetch_with_cors_cache(request: Rc<Request>, cache: &mut CorsCache) -> Response {
let (sender, receiver) = channel();
let target = Box::new(FetchResponseCollector {
sender: sender,
});
methods::fetch_with_cors_cache(request, cache, &mut Some(target), &new_fetch_context(None));
receiver.recv().unwrap()
}
fn make_server<H: Handler + 'static>(handler: H) -> (Listening, ServoUrl) { fn make_server<H: Handler + 'static>(handler: H) -> (Listening, ServoUrl) {
// this is a Listening server because of handle_threads() // this is a Listening server because of handle_threads()
let server = Server::http("0.0.0.0:0").unwrap().handle_threads(handler, 1).unwrap(); let server = Server::http("0.0.0.0:0").unwrap().handle_threads(handler, 1).unwrap();