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

Rewrite some http unit tests with fetch. #14163

Merged
merged 12 commits into from Nov 12, 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

Rewrite test_load_sets_default_accept_to_html_xhtml_xml_and_then_anyt…

…hing_else.
  • Loading branch information
Ms2ger committed Nov 10, 2016
commit e12a6d7f4e27a86b843748b2618045b196968385
@@ -1091,30 +1091,29 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {

#[test]
fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
let mut accept_headers = Headers::new();
accept_headers.set(Accept(vec![
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
qitem(Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_owned()), vec![])),
QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]), Quality(900)),
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800)),
]));

let url = Url::parse("http://mozilla.com").unwrap();
let mut load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
let handler = move |request: HyperRequest, response: HyperResponse| {
assert_eq!(request.headers.get::<Accept>(), Some(&Accept(vec![
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
qitem(Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_owned()), vec![])),
QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]), Quality(900)),
])));
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
let request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let response = fetch_sync(request, None);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
let _ = server.close();

let _ = load(&load_data,
&ui_provider, &http_state,
None,
&AssertMustIncludeHeadersRequestFactory {
expected_headers: accept_headers,
body: <[_]>::to_vec("Yay!".as_bytes())
}, DEFAULT_USER_AGENT.into(),
&CancellationListener::new(None), None);
assert!(response.status.unwrap().is_success());
}

#[test]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.