-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
servo: Merge #9298 - Implement a basic test for Fetch (from nikkisqua…
…red:test_fetch); r=KiChjang As per jdm's suggestion that I start minimally testing the Fetch protocol to catch any errors, I wrote a very simple test that just calls Fetch and checks that the response isn't a network error. I've made changes as necessary for every failure I encountered, although this doesn't mean the implementation is faultless yet. As always, I look forward to any feedback for improvements regarding the test itself, the changes to the fetch files I've made, and anything that I missed and should update. Source-Repo: https://github.com/servo/servo Source-Revision: 9c713cb4688f1a1729ada64846fac2d8426b1ef4 UltraBlame original commit: 2b7cfbc101b78151607bf66bea2632543bfed083
- Loading branch information
Showing
5 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
|
||
|
||
|
||
use hyper::server::{Listening, Server}; | ||
use hyper::server::{Request as HyperRequest, Response as HyperResponse}; | ||
use net::fetch::request::{Context, fetch, Referer, Request}; | ||
use net_traits::response::{Response}; | ||
use std::rc::Rc; | ||
use url::Url; | ||
|
||
fn make_server(message: &'static [u8]) -> (Listening, Url) { | ||
|
||
let handler = move |_: HyperRequest, response: HyperResponse| { | ||
response.send(message).unwrap(); | ||
}; | ||
|
||
|
||
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""; | ||
let (mut server, url) = make_server(MESSAGE); | ||
|
||
let mut request = Request::new(url, Context::Fetch, false); | ||
request.referer = Referer::NoReferer; | ||
let wrapped_request = Rc::new(request); | ||
|
||
let fetch_response = fetch(wrapped_request, false); | ||
let _ = server.close(); | ||
|
||
if Response::is_network_error(&fetch_response) { | ||
panic!("fetch response shouldn't be a network error"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters