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

Make the fetch target non-optional. #14465

Merged
merged 9 commits into from Dec 15, 2016

Introduce fetch_with_cors_cache() API for tests.

  • Loading branch information
Ms2ger committed Dec 15, 2016
commit 6f2606cdee153674dd1dda48405d2c2d7578b228
@@ -7,6 +7,7 @@ use devtools_traits::DevtoolsControlMsg;
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
use fetch_with_context;
use fetch_with_cors_cache;
use http_loader::{expect_devtools_http_request, expect_devtools_http_response};
use hyper::LanguageTag;
use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowOrigin};
@@ -22,7 +23,6 @@ use hyper::status::StatusCode;
use hyper::uri::RequestUri;
use msg::constellation_msg::TEST_PIPELINE_ID;
use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::fetch_with_cors_cache;
use net_traits::ReferrerPolicy;
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
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_request1 = Rc::new(request);

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,
&mut None, &new_fetch_context(None));
let fetch_response0 = fetch_with_cors_cache(wrapped_request0.clone(), &mut cache);
let fetch_response1 = fetch_with_cors_cache(wrapped_request1.clone(), &mut cache);
let _ = server.close();

assert!(!fetch_response0.is_network_error() && !fetch_response1.is_network_error());
@@ -36,6 +36,7 @@ extern crate url;

use devtools_traits::DevtoolsControlMsg;
use hyper::server::{Handler, Listening, Server};
use net::fetch::cors_cache::CorsCache;
use net::fetch::methods::{self, FetchContext};
use net::filemanager_thread::FileManager;
use net::test::HttpState;
@@ -86,6 +87,17 @@ fn fetch_with_context(request: Request, context: &FetchContext) -> Response {
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) {
// this is a Listening server because of handle_threads()
let server = Server::http("0.0.0.0:0").unwrap().handle_threads(handler, 1).unwrap();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.