#![cfg(feature = "integration-tests")]
use serial_test::serial;
use zendriver::Browser;
const FETCH_PROBE: &str = r#"(async (u) => {
try {
await fetch(u, { mode: 'no-cors', cache: 'no-store' });
return 'ok';
} catch (e) {
return 'blocked:' + e;
}
})"#;
#[tokio::test]
#[serial]
#[ignore] async fn listed_host_is_blocked_unlisted_loads() {
let browser = Browser::builder()
.tracker_blocklist_add(["example.org".to_string()])
.launch()
.await
.unwrap();
let tab = browser.main_tab();
tab.goto("https://example.com/").await.unwrap();
tab.wait_for_load().await.unwrap();
let blocked: String = tab
.evaluate::<String>(&format!("({FETCH_PROBE})('https://example.org/')"))
.await
.unwrap();
assert!(
blocked.starts_with("blocked:"),
"listed host should be blocked, got: {blocked}"
);
let ok: String = tab
.evaluate::<String>(&format!("({FETCH_PROBE})('https://example.com/')"))
.await
.unwrap();
assert_eq!(ok, "ok", "unlisted host should load, got: {ok}");
browser.close().await.unwrap();
}
#[tokio::test]
#[serial]
#[ignore]
async fn subdomain_of_listed_host_is_blocked() {
let browser = Browser::builder()
.tracker_blocklist_add(["example.org".to_string()])
.launch()
.await
.unwrap();
let tab = browser.main_tab();
tab.goto("https://example.com/").await.unwrap();
tab.wait_for_load().await.unwrap();
let blocked: String = tab
.evaluate::<String>(&format!("({FETCH_PROBE})('https://www.example.org/')"))
.await
.unwrap();
assert!(
blocked.starts_with("blocked:"),
"subdomain of a listed host should be blocked, got: {blocked}"
);
browser.close().await.unwrap();
}