# Network pass (S007): the ad blocker on a local page. The shipped seed lists build offline; then only a local list
# (tests/smoke/net/server.py /list.txt, a custom list URL) blocks a script and an image, and hides one element by a
# site rule and one by a generic rule; pausing for the site lets everything through; a list that can't be fetched
# is reported and the engine keeps the rules it has. Blocking runs in WebKit content filters, counted through the web
# process extension (S049); `waitstatus` waits for WebKit to compile a filter (the seed lists take ~15 s the first
# time). Offline. Never Tor or proxies. Start the server first:
#   python3 tests/smoke/net/server.py &   then   tools/smoke.sh tests/smoke/net-adblock.txt
wait 3
set /adblock/update_days 0
wait 5
status seed
expect /adblock/ready true
expect /adblock/rules > 10000
waitstatus 90 /adblock/filters_ready true
set /adblock/lists []
set /adblock/custom ["http://127.0.0.1:8766/list.txt"]
wait 5
status local
expect /adblock/rules 4
waitstatus 30 /adblock/filters_ready true
open http://127.0.0.1:8766/ads.html
waitfor 20 document.title === "Ads" && window.pixelLoaded !== null
wait 2
shot blocked
assert window.adScript === false && window.pixelLoaded === false
assert getComputedStyle(document.querySelector(".nacre-ad")).display === "none"
assert getComputedStyle(document.getElementById("nacre-generic-ad")).display === "none"
assert getComputedStyle(document.getElementById("content")).display !== "none"
status page
expect /active/blocked > 1
expect /active/hidden_elements > 0
# Paused for this site: nothing is blocked or hidden.
set /adblock/allow ["127.0.0.1"]
open http://127.0.0.1:8766/ads.html
waitfor 20 document.title === "Ads" && window.pixelLoaded !== null
wait 2
shot paused
assert window.adScript === true && window.pixelLoaded === true
assert getComputedStyle(document.querySelector(".nacre-ad")).display !== "none"
status paused
expect /active/blocked 0
set /adblock/allow []
# A redirect rule (S049): the web process extension serves the noopjs stand-in from nacre-resource: instead.
set /adblock/own_rules "||127.0.0.1:8766/standin.js$xmlhttprequest,redirect=noopjs"
wait 3
waitstatus 30 /adblock/filters_ready true
open http://127.0.0.1:8766/ads.html
waitfor 20 document.title === "Ads"
js fetch("/standin.js").then(r => r.text()).then(t => { window.standin = t; }, e => { window.standin = "error " + e; })
waitfor 10 window.standin !== undefined
assert window.standin === "(function() {})();"
set /adblock/own_rules ""
wait 3
# A list that can't be fetched: the failure is reported, the local list's rules stay.
set /adblock/custom ["http://127.0.0.1:8766/list.txt","http://127.0.0.1:8767/missing.txt"]
wait 5
cmd update_lists
wait 5
status failed
expect /adblock/rules 4
open http://127.0.0.1:8766/ads.html
waitfor 20 document.title === "Ads" && window.pixelLoaded !== null
assert window.adScript === false
wait 1
status reloaded
expect /active/blocked > 1
flyout shield
wait 1
shot shield
status done
quit
