# Request headers and third-party cookies in the vendored servo-net (S023); frame document.cookie and privacy
# mode paused per site (S024). Offline: names resolve through the
# secure DNS stub in tests/smoke/net/server.py (*.nacre.test -> 127.0.0.1). site.nacre.test and img.nacre.test are
# one site (nacre.test); 127.0.0.1 is another. Never Tor or proxies. Start the server first:
#   python3 tests/smoke/net/server.py &   then   tools/smoke.sh tests/smoke/privacy-net.txt
wait 3
set /vpn/enabled false
set /privacy/doh_custom "http://127.0.0.1:8766/dns-query"
set /privacy/doh "custom"
set /privacy/https_only false
set /privacy/dnt true
set /privacy/save_data true
set /privacy/mode false
set /privacy/block_third_party true
# The ad blocker would take the test pictures (/pixel); this run is about cookies.
set /adblock/enabled false
wait 1
open http://127.0.0.1:8767/reset
waitfor 20 document.title === "Reset"
# First-party cookies: one for 127.0.0.1, one for the whole nacre.test site.
open http://127.0.0.1:8767/setcookie?name=fp
waitfor 20 document.title === "Set fp"
open http://site.nacre.test:8766/setcookie?name=sub&domain=nacre.test
waitfor 20 document.title === "Set sub"
open http://127.0.0.1:8767/cookies
waitfor 20 document.title === "Cookies fp=1"
# Blocking on: the cross-site frame and picture get no cookie and can't store one; the same-site picture keeps its.
open http://site.nacre.test:8766/tp?tag=on
waitfor 20 document.title === "TP on done"
shot blocked
# Blocking off: the same page sends and stores third-party cookies again.
set /privacy/block_third_party false
wait 1
open http://site.nacre.test:8766/tp?tag=off
waitfor 20 document.title === "TP off done"
# Privacy mode turns blocking on even with the switch off.
set /privacy/mode true
wait 1
open http://site.nacre.test:8766/tp?tag=mode
waitfor 20 document.title === "TP mode done"
set /privacy/mode false
# 127.0.0.1's own jar: fp, plus tpoff from the unblocked run; never tpon or tpmode.
open http://127.0.0.1:8767/cookies
waitfor 20 document.title.startsWith("Cookies ")
assert document.title === "Cookies fp=1; tpoff=1"
# document.cookie in a cross-site frame (S024, script layer): empty and not stored with blocking on, works off.
set /privacy/block_third_party true
wait 1
open http://site.nacre.test:8766/jstp?tag=jon
waitfor 20 document.title === "JSTP jon done"
set /privacy/block_third_party false
wait 1
open http://site.nacre.test:8766/jstp?tag=joff
waitfor 20 document.title === "JSTP joff done"
open http://127.0.0.1:8767/cookies
waitfor 20 document.title.startsWith("Cookies ")
assert !document.title.includes("jsjon") && document.title.includes("jsjoff=1")
# Privacy mode paused on one site (S024): common values on other sites, the engine's own on the paused one.
set /privacy/mode true
set /privacy/mode_off ["127.0.0.1"]
wait 1
open http://site.nacre.test:8766/echo?pm
waitfor 20 document.title === "Echo pm"
assert navigator.hardwareConcurrency === 8 && navigator.platform === "Linux x86_64" && navigator.appVersion === "5.0 (X11)"
open http://127.0.0.1:8767/echo?paused
waitfor 20 document.title === "Echo paused"
assert navigator.platform === "Linux" && navigator.appVersion === "4.0"
set /privacy/mode_off []
set /privacy/mode false
# Do Not Track off: the headers stop.
set /privacy/dnt false
set /privacy/save_data false
wait 1
open http://127.0.0.1:8767/echo?nodnt
waitfor 20 document.title === "Echo nodnt"
js fetch("/log").then(r => r.json()).then(l => { window.reqs = l.reqs; })
waitfor 5 window.reqs !== undefined
js window.pick = (tag, host) => window.reqs.filter(r => r.path.includes("tag=" + tag) && r.host.startsWith(host)); JSON.stringify(window.reqs.filter(r => r.path.includes("tag=")))
# Headers: every request with the switches on carried DNT, Sec-GPC and Save-Data; the last one none.
assert window.reqs.filter(r => r.path.startsWith("/tp")).every(r => r.dnt === "1" && r.gpc === "1" && r.savedata === "on")
assert window.reqs.some(r => r.path === "/echo?nodnt") && window.reqs.filter(r => r.path === "/echo?nodnt").every(r => r.dnt === null && r.gpc === null && r.savedata === null)
# Blocked: cross-site frame and picture without cookies, the same-site picture with sub=1.
assert window.pick("on", "127.0.0.1").length === 2 && window.pick("on", "127.0.0.1").every(r => r.cookie === null)
assert window.pick("on", "img.nacre.test").length === 1 && window.pick("on", "img.nacre.test")[0].cookie === "sub=1"
# Not blocked: the cross-site requests carry 127.0.0.1's cookie.
assert window.pick("off", "127.0.0.1").length === 2 && window.pick("off", "127.0.0.1").every(r => (r.cookie || "").includes("fp=1"))
# The cross-site frame's document.cookie: empty when blocked, 127.0.0.1's cookies when not.
assert window.reqs.some(r => r.path === "/note?tag=jon&seen=") && window.reqs.some(r => r.path.startsWith("/note?tag=joff&seen=") && r.path.includes("fp%3D1"))
# Accept-Language: Firefox's list in privacy mode (S024), Servo's single locale otherwise.
assert window.reqs.filter(r => r.path === "/echo?pm").every(r => r.lang === navigator.language + "," + navigator.language.split("-")[0] + ";q=0.5") && window.reqs.filter(r => r.path === "/echo?nodnt").every(r => r.lang === navigator.language)
# Privacy mode: blocked again.
assert window.pick("mode", "127.0.0.1").length === 2 && window.pick("mode", "127.0.0.1").every(r => r.cookie === null)
status done
quit
