mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Rewrite test_content_blocked.
This commit is contained in:
parent
b4178c7eaf
commit
2fa032109f
1 changed files with 23 additions and 23 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue