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_sends_cookie_if_nonhttp.

  • Loading branch information
Ms2ger committed Nov 10, 2016
commit 52258e22825bee7df4fe35b37c66383e3274fe02
@@ -899,34 +899,40 @@ fn test_load_sends_secure_cookie_if_http_changed_to_https_due_to_entry_in_hsts_s

#[test]
fn test_load_sends_cookie_if_nonhttp() {
let url = Url::parse("http://mozilla.com").unwrap();
let handler = move |request: HyperRequest, response: HyperResponse| {
assert_eq!(request.headers.get::<CookieHeader>(),
Some(&CookieHeader(vec![CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned())])));
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
let context = new_fetch_context(None);

{
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
let cookie_url = url.clone();
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
let cookie = Cookie::new_wrapped(
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
&cookie_url,
&url,
CookieSource::NonHTTP
).unwrap();
cookie_jar.push(cookie, CookieSource::HTTP);
}

let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
let request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
pipeline_id: Some(TEST_PIPELINE_ID),
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
});
let response = fetch(Rc::new(request), &mut None, &context);

let mut headers = Headers::new();
headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]);
let _ = server.close();

let _ = load(
&load_data.clone(), &ui_provider, &http_state, None,
&AssertMustIncludeHeadersRequestFactory {
expected_headers: headers,
body: <[_]>::to_vec(&*load_data.data.unwrap())
}, 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.