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 and remove most unit tests for the legacy fetch stack. #14315

Merged
merged 14 commits into from Nov 24, 2016

Rewrite test_content_blocked.

  • Loading branch information
Ms2ger committed Nov 23, 2016
commit 2fa032109f05a508caf56f43038e2e480fb9d260
@@ -1491,35 +1491,35 @@ fn test_auth_ui_needs_www_auth() {

#[test]
fn test_content_blocked() {
struct Factory;
impl HttpRequestFactory for Factory {
type R = MockRequest;
let handler = move |_: HyperRequest, response: HyperResponse| {
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

fn create(&self, _url: ServoUrl, _method: Method, _: Headers) -> Result<MockRequest, LoadError> {
Ok(MockRequest::new(ResponseType::Text(<[_]>::to_vec("Yay!".as_bytes()))))
}
}
let url_filter = url.as_str().replace("http://", "https?://");
let blocked_content_list = format!("[{{ \
\"trigger\": {{ \"url-filter\": \"{}\" }}, \
\"action\": {{ \"type\": \"block\" }} \
}}]", url_filter);

let blocked_url = ServoUrl::parse("http://mozilla.com").unwrap();
let mut http_state = HttpState::new();
let mut context = new_fetch_context(None);
context.state.blocked_content = Arc::new(Some(parse_list(&blocked_content_list).unwrap()));

let blocked_content_list = "[{ \"trigger\": { \"url-filter\": \"https?://mozilla.com\" }, \
\"action\": { \"type\": \"block\" } }]";
http_state.blocked_content = Arc::new(parse_list(blocked_content_list).ok());
assert!(http_state.blocked_content.is_some());
let request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Get,
body: None,
destination: Destination::Document,
origin: url.clone(),
.. RequestInit::default()
});

let ui_provider = TestProvider::new();
let response = fetch(Rc::new(request), &mut None, &context);

let load_data = LoadData::new(LoadContext::Browsing, blocked_url, &HttpTest);
let _ = server.close();

let response = load(
&load_data, &ui_provider, &http_state,
None, &Factory,
DEFAULT_USER_AGENT.into(), &CancellationListener::new(None), None);
match response {
Err(LoadError { error: LoadErrorType::ContentBlocked, .. }) => {},
_ => panic!("request should have been blocked"),
}
// TODO(#14307): this should fail.
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.