mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Rewrite test_load_should_decode_the_response_as_gzip_when_response_headers_have_content_encoding_gzip.
This commit is contained in:
parent
4fe105b8e1
commit
ba86d8576d
1 changed files with 22 additions and 29 deletions
|
@ -686,38 +686,31 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_content_encoding_gzip() {
|
fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_content_encoding_gzip() {
|
||||||
struct Factory;
|
let handler = move |_: HyperRequest, mut response: HyperResponse| {
|
||||||
|
response.headers_mut().set(ContentEncoding(vec![Encoding::Gzip]));
|
||||||
impl HttpRequestFactory for Factory {
|
|
||||||
type R = MockRequest;
|
|
||||||
|
|
||||||
fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
|
|
||||||
let mut e = GzEncoder::new(Vec::new(), Compression::Default);
|
let mut e = GzEncoder::new(Vec::new(), Compression::Default);
|
||||||
e.write(b"Yay!").unwrap();
|
e.write(b"Yay!").unwrap();
|
||||||
let encoded_content = e.finish().unwrap();
|
let encoded_content = e.finish().unwrap();
|
||||||
|
response.send(&encoded_content).unwrap();
|
||||||
|
};
|
||||||
|
let (mut server, url) = make_server(handler);
|
||||||
|
|
||||||
let mut headers = Headers::new();
|
let request = Request::from_init(RequestInit {
|
||||||
headers.set(ContentEncoding(vec![Encoding::Gzip]));
|
url: url.clone(),
|
||||||
Ok(MockRequest::new(ResponseType::WithHeaders(encoded_content, headers)))
|
method: Method::Get,
|
||||||
}
|
body: None,
|
||||||
}
|
destination: Destination::Document,
|
||||||
|
origin: url.clone(),
|
||||||
|
pipeline_id: Some(TEST_PIPELINE_ID),
|
||||||
|
.. RequestInit::default()
|
||||||
|
});
|
||||||
|
let response = fetch_sync(request, None);
|
||||||
|
|
||||||
let url = Url::parse("http://mozilla.com").unwrap();
|
let _ = server.close();
|
||||||
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
|
|
||||||
|
|
||||||
let http_state = HttpState::new();
|
assert!(response.status.unwrap().is_success());
|
||||||
let ui_provider = TestProvider::new();
|
assert_eq!(*response.body.lock().unwrap(),
|
||||||
|
ResponseBody::Done(b"Yay!".to_vec()));
|
||||||
let mut response = load(
|
|
||||||
&load_data,
|
|
||||||
&ui_provider, &http_state,
|
|
||||||
None, &Factory,
|
|
||||||
DEFAULT_USER_AGENT.into(),
|
|
||||||
&CancellationListener::new(None),
|
|
||||||
None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(read_response(&mut response), "Yay!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue