# Browser basics (S006): tabs, navigation, address bar, find, zoom, full screen, new window, pop-ups. Offline.
# Run with tools/smoke.sh; every check is an `expect` / `assert`, so a failure fails the run.
# Layout of pages/basics.html: _blank link y 20..50, pop-up button y 70..100, full screen button y 120..150.
wait 3
open @PAGES@/hello.html
waitload
expect /tab_count 1
# Tabs: new, duplicate, pin, mute, reorder, close, reopen.
do new_tab
wait 0.5
expect /tab_count 2
open @PAGES@/basics.html
waitload
expect /active/title "Basics"
# Inline SVG takes its colour from CSS (R1-13; WebKit paints currentColor itself): the icon is green, not black.
waitfor 5 getComputedStyle(document.getElementById("icon")).color === "rgb(0, 160, 0)"
shot svg-colour
do duplicate_tab
waitload
expect /tab_count 3
expect /active/title "Basics"
do pin_tab
wait 0.5
# Pinning moves the tab to the front; unpinning leaves it there.
expect /active_index 0
expect /active/pinned true
do pin_tab
wait 0.5
expect /active/pinned false
do mute_tab
wait 0.5
expect /active/muted true
do mute_tab
wait 0.5
expect /active/muted false
# Order now: Basics (duplicate, active), Smoke page, Basics.
do move_tab_right
wait 0.5
expect /active_index 1
do move_tab_left
wait 0.5
expect /active_index 0
do move_tab_right
wait 0.5
do tab_1
wait 0.5
expect /active_index 0
expect /active/title "Smoke page"
do last_tab
wait 0.5
expect /active_index 2
do close_tab
wait 0.5
expect /tab_count 2
do reopen_closed
wait 1.5
expect /tab_count 3
do next_tab
do prev_tab
wait 0.5
shot tabs
# Navigation: back, forward, reload, home.
do tab_1
wait 0.5
open @PAGES@/basics.html
waitload
expect /active/can_back true
do back
waitload
wait 0.5
expect /active/title "Smoke page"
expect /active/can_forward true
do forward
waitload
wait 0.5
expect /active/title "Basics"
js window.marker = 1
do reload
waitload
wait 0.5
assert window.marker === undefined
# Address bar: a URL loads, plain words become a search.
cmd navigate @PAGES@/hello.html
waitload
expect /active/title "Smoke page"
# The search engine is a local page here, so the check stays offline.
set /startup/custom_engines [["Local", "@PAGES@/hello.html?q=%s"]]
set /startup/search_engine "custom:Local"
cmd navigate nacre smoke words
waitload
wait 0.5
expect /active/url "@PAGES@/hello.html?q=nacre+smoke+words"
status search
# Find in page: 3 matches, 2 with match case is the bar's job (count only here).
open @PAGES@/basics.html
waitload
waitfor 10 document.title === "Basics"
cmd find needle
wait 1
expect /active/find [1,3]
do find_next
wait 0.5
expect /active/find [2,3]
shot find
key Escape
wait 0.3
# Zoom.
do zoom_in
wait 0.5
status zoom-in
do zoom_reset
wait 0.5
expect /active/zoom 1.0
# Full screen: F11 and the page's own request.
do fullscreen
wait 1
expect /fullscreen true
shot fullscreen
do fullscreen
wait 1
expect /fullscreen false
click 60 135
wait 1
expect /fullscreen true
# Escape in full screen is the browser's Stop (leave full screen), not the page's key.
do stop
wait 1
expect /fullscreen false
assert document.fullscreenElement === null
# target=_blank opens a tab; window.open a pop-up (as a tab or blocked by the pop-up permission).
click 60 35
wait 1.5
expect /tab_count 4
expect /active/title "Smoke page"
do tab_1
wait 0.5
click 60 85
wait 1.5
expect /tab_count 5
status popup
shot popup
# The pop-up is a related view: it knows its opener.
assert window.opener !== null && window.name === "pop"
# Single instance: a second launch hands its link to this browser (a new tab) and exits.
launch @PAGES@/input.html
wait 1.5
expect /tab_count 6
expect /active/url "@PAGES@/input.html"
# New window.
do new_window
wait 2
expect /windows 2
# Pop-ups blocked: no tab, a bar that offers to allow them.
set /privacy/permission_defaults {"popups": "block"}
open @PAGES@/basics.html
waitload
click 60 85
wait 1.5
expect /tab_count 1
expect /active/prompts 1
shot popup-blocked
status done
quit
