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

Next

Rewrite test_load_sets_cookies_in_the_resource_manager_when_it_get_se…

…t_cookie_header_in_response.
  • Loading branch information
Ms2ger committed Nov 10, 2016
commit 5bf90c563ce54bde6ca595825731e3b64efd794b
@@ -31,7 +31,7 @@ use net::test::{HttpRequest, HttpRequestFactory, HttpState, LoadError, UIProvide
use net::test::{HttpResponse, LoadErrorType};
use net_traits::{CookieSource, IncludeSubdomains, LoadContext, LoadData};
use net_traits::{CustomResponse, LoadOrigin, Metadata, ReferrerPolicy};
use net_traits::request::{Request, RequestInit, Destination};
use net_traits::request::{Request, RequestInit, CredentialsMode, Destination};
use net_traits::response::ResponseBody;
use new_fetch_context;
use std::borrow::Cow;
@@ -788,37 +788,33 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present

#[test]
fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_in_response() {
struct Factory;

impl HttpRequestFactory for Factory {
type R = MockRequest;

fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
let content = <[_]>::to_vec("Yay!".as_bytes());
let mut headers = Headers::new();
headers.set(SetCookie(vec![CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned())]));
Ok(MockRequest::new(ResponseType::WithHeaders(content, headers)))
}
}
let handler = move |_: HyperRequest, mut response: HyperResponse| {
response.headers_mut().set(SetCookie(vec![CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned())]));
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

let url = Url::parse("http://mozilla.com").unwrap();
let context = new_fetch_context(None);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
assert_cookie_for_domain(context.state.cookie_jar.clone(), url.as_str(), None);

assert_cookie_for_domain(http_state.cookie_jar.clone(), "http://mozilla.com", None);
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.clone(), &HttpTest);
let _ = server.close();

let _ = load(&load_data,
&ui_provider, &http_state,
None,
&Factory,
DEFAULT_USER_AGENT.into(),
&CancellationListener::new(None),
None);
assert!(response.status.unwrap().is_success());

assert_cookie_for_domain(http_state.cookie_jar.clone(), "http://mozilla.com", Some("mozillaIs=theBest"));
assert_cookie_for_domain(context.state.cookie_jar.clone(), url.as_str(), Some("mozillaIs=theBest"));
}

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