mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Rewrite test_load_sends_cookie_if_nonhttp.
This commit is contained in:
parent
f1f090ca81
commit
52258e2282
1 changed files with 22 additions and 16 deletions
|
@ -899,34 +899,40 @@ fn test_load_sends_secure_cookie_if_http_changed_to_https_due_to_entry_in_hsts_s
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_sends_cookie_if_nonhttp() {
|
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 context = new_fetch_context(None);
|
||||||
let ui_provider = TestProvider::new();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
|
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
|
||||||
let cookie_url = url.clone();
|
|
||||||
let cookie = Cookie::new_wrapped(
|
let cookie = Cookie::new_wrapped(
|
||||||
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
|
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
|
||||||
&cookie_url,
|
&url,
|
||||||
CookieSource::NonHTTP
|
CookieSource::NonHTTP
|
||||||
).unwrap();
|
).unwrap();
|
||||||
cookie_jar.push(cookie, CookieSource::HTTP);
|
cookie_jar.push(cookie, CookieSource::HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
|
let request = Request::from_init(RequestInit {
|
||||||
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
|
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();
|
let _ = server.close();
|
||||||
headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]);
|
|
||||||
|
|
||||||
let _ = load(
|
assert!(response.status.unwrap().is_success());
|
||||||
&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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue