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

Start using fetch for the HTTP unit tests. #14114

Merged
merged 4 commits into from Nov 8, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Move make_server to the root of the net unit tests crate.

  • Loading branch information
Ms2ger committed Nov 7, 2016
commit b64ca44953ab26fdfcaa2736eb9a7c9e0bd3d6aa
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use {DEFAULT_USER_AGENT, FetchResponseCollector, new_fetch_context, fetch_async, fetch_sync};
use {DEFAULT_USER_AGENT, FetchResponseCollector, new_fetch_context, fetch_async, fetch_sync, make_server};
use devtools_traits::DevtoolsControlMsg;
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
@@ -16,7 +16,6 @@ use hyper::header::{Encoding, Location, Pragma, SetCookie, qitem};
use hyper::header::{Headers, Host, HttpDate, Referer as HyperReferer};
use hyper::method::Method;
use hyper::mime::{Mime, SubLevel, TopLevel};
use hyper::server::{Handler, Listening, Server};
use hyper::server::{Request as HyperRequest, Response as HyperResponse};
use hyper::status::StatusCode;
use hyper::uri::RequestUri;
@@ -39,16 +38,6 @@ use util::resource_files::resources_dir_path;

// TODO write a struct that impls Handler for storing test values

fn make_server<H: Handler + 'static>(handler: H) -> (Listening, Url) {
// 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 port = server.socket.port().to_string();
let mut url_string = "http://localhost:".to_owned();
url_string.push_str(&port);
let url = Url::parse(&url_string).unwrap();
(server, url)
}

#[test]
fn test_fetch_response_is_not_network_error() {
static MESSAGE: &'static [u8] = b"";
@@ -35,6 +35,7 @@ extern crate util;

use devtools_traits::DevtoolsControlMsg;
use filemanager_thread::{TestProvider, TEST_PROVIDER};
use hyper::server::{Handler, Listening, Server};
use net::fetch::methods::{FetchContext, fetch};
use net::filemanager_thread::FileManager;
use net::test::HttpState;
@@ -44,6 +45,7 @@ use net_traits::response::Response;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::thread;
use url::Url;

const DEFAULT_USER_AGENT: &'static str = "Such Browser. Very Layout. Wow.";

@@ -79,3 +81,13 @@ fn fetch_async(request: Request, target: Box<FetchTaskTarget + Send>, dc: Option
fn fetch_sync(request: Request, dc: Option<Sender<DevtoolsControlMsg>>) -> Response {
fetch(Rc::new(request), &mut None, new_fetch_context(dc))
}

fn make_server<H: Handler + 'static>(handler: H) -> (Listening, Url) {
// 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 port = server.socket.port().to_string();
let mut url_string = "http://localhost:".to_owned();
url_string.push_str(&port);
let url = Url::parse(&url_string).unwrap();
(server, url)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.