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

  • Loading branch information
Ms2ger committed Nov 10, 2016
commit c229a0116ead0c0aa1bb9b13ee18e2bf2e67ceaa
@@ -972,31 +972,35 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(

#[test]
fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
struct Factory;
let handler = move |_: HyperRequest, mut response: HyperResponse| {
let mut pair = CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned());
pair.secure = true;
response.headers_mut().set(SetCookie(vec![pair]));
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

impl HttpRequestFactory for Factory {
type R = MockRequest;
let context = new_fetch_context(None);

fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
let content = <[_]>::to_vec("Yay!".as_bytes());
let mut headers = Headers::new();
headers.set_raw("set-cookie", vec![b"mozillaIs=theBest; Secure;".to_vec()]);
Ok(MockRequest::new(ResponseType::WithHeaders(content, headers)))
}
}
assert_cookie_for_domain(context.state.cookie_jar.clone(), url.as_str(), None);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
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 load_data = LoadData::new(LoadContext::Browsing, Url::parse("http://mozilla.com").unwrap(), &HttpTest);
let _ = load(&load_data,
&ui_provider, &http_state,
None,
&Factory,
DEFAULT_USER_AGENT.into(),
&CancellationListener::new(None), None);
let _ = server.close();

assert_cookie_for_domain(http_state.cookie_jar.clone(), "http://mozilla.com", None);
assert!(response.status.unwrap().is_success());

assert_cookie_for_domain(context.state.cookie_jar.clone(), url.as_str(), None);
}

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