# Stores pass (S008): user scripts and styles run on matching pages only; install a site as an app and open its window.
# Offline. Start the servers first:
#   python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages &
#   python3 tests/smoke/net/server.py &
#   tools/smoke.sh tests/smoke/stores-apps.txt <outdir>
wait 3
cmd install_script http://127.0.0.1:8768/probe.user.js
cmd install_script http://127.0.0.1:8768/probe.user.css
wait 3
status installed
expect /scripts 2
# Matching page: both run. Non-matching page (other port): neither does.
open http://127.0.0.1:8768/hello.html
waitload
wait 2
assert window.userScriptRan === true
assert getComputedStyle(document.body).backgroundColor === 'rgb(18, 52, 86)'
shot user-content-on
open http://127.0.0.1:8766/
waitload
wait 2
assert window.userScriptRan === undefined
assert getComputedStyle(document.body).backgroundColor !== 'rgb(18, 52, 86)'
# A style WebKit matches itself (no port in the pattern): a user style sheet, not the script fallback.
cmd install_script http://127.0.0.1:8768/probe-file.user.css
wait 2
open @PAGES@/basics.html
waitload
wait 1
assert getComputedStyle(document.body).backgroundColor === 'rgb(86, 52, 18)'
assert document.querySelector('style[data-nacre-user-style]') === null
open @PAGES@/input.html
waitload
wait 1
assert getComputedStyle(document.body).backgroundColor !== 'rgb(86, 52, 18)'
# Install the page as an app, open its window.
open http://127.0.0.1:8768/hello.html
waitload
wait 2
cmd install_app
wait 1
status app
expect /apps 1
cmd open_app
wait 4
status app-window
expect /windows 2
shot app-window
page nacre://apps
wait 1
shot apps-page
status done
quit
