# nacre:// lockdown (S063, D-049): a web page's link, middle click, target=_blank, window.open, script navigation,
# frame, meta refresh and HTTP redirect to nacre://passwords never show one of Nacre's pages; the user's address bar
# does, and the passwords page asks first every time it is shown (here without a master password: the computer
# password, D-052, through the selftest's stand-in, never real PAM). Offline. Run: python3 tests/smoke/net/server.py &
# then NACRE_TEST_ACCOUNT_PASSWORD=smoke-account SMOKE_SIZE=1280x900 tools/smoke.sh tests/smoke/nacre-lock.txt ;
# `grep -c "can't open Nacre's pages" <out>/nacre.log` > 0.
wait 3
resize 1280 900
open @PAGES@/nacre-lock.html
waitload
wait 1
expect /active/page null
expect /tab_count 1
# The frame stayed empty: it never got Nacre's page (nothing to read, WebKit has no such address).
assert document.getElementById('state').textContent === 'web page'
locate #link
wait 0.5
click @
wait 1
expect /active/page null
mclick @
wait 1
expect /tab_count 1
locate #blank
wait 0.5
click @
wait 1
expect /tab_count 1
locate #popup
wait 0.5
click @
wait 1
expect /tab_count 1
expect /active/page null
locate #script
wait 0.5
click @
wait 1
expect /active/page null
js location.href = 'nacre://passwords'
wait 1
expect /active/page null
assert location.href.endsWith('nacre-lock.html')
js window.open('nacre://settings')
wait 1
expect /tab_count 1
shot web-denied
open @PAGES@/nacre-refresh.html
waitload
wait 2
expect /active/page null
assert location.href.endsWith('nacre-refresh.html')
open http://127.0.0.1:8767/to-nacre
wait 3
expect /active/page null
expect /tab_count 1
# The user opens it: it asks first.
cmd navigate nacre://passwords
wait 1
expect /active/page "nacre://passwords"
expect /lifecycle/passwords_open false
shot ask
# A wrong computer password keeps it shut; the right one opens it.
uitext not-it
key enter
wait 1
expect /lifecycle/passwords_open false
shot wrong
uitext smoke-account
key enter
wait 1
expect /lifecycle/passwords_open true
shot open
# Another tab and back: it asks again.
do new_tab
wait 1
expect /lifecycle/passwords_open false
cmd select 0
wait 1
expect /active/page "nacre://passwords"
expect /lifecycle/passwords_open false
shot ask-again
# The address bar kept the keyboard: click the field first.
tap 640 382
wait 0.5
uitext smoke-account
key enter
wait 1
expect /lifecycle/passwords_open true
# Away to another page in the same tab and back by the address bar: asks again.
cmd navigate nacre://history
wait 1
cmd navigate nacre://passwords
wait 1
expect /lifecycle/passwords_open false
# With a master password and the store unlocked (for filling in), it still asks for the password.
vault master smoke-pw
cmd navigate nacre://history
wait 1
cmd navigate nacre://passwords
wait 1
expect /lifecycle/passwords_open false
shot ask-master
status done
quit
