# Heavy real-site use (R4-07): DuckDuckGo, Wikipedia, YouTube load, take clicks, typing and the wheel, and play
# video (Wikipedia's <video>, YouTube).
# NEEDS INTERNET. Direct connections only: never a VPN, Tor or proxy (keep Nacre's VPN off; the profile is new).
# Run with SMOKE_TIMEOUT=600 tools/smoke.sh tests/smoke/heavy-web.txt; any failed check fails the run.
# Sites change their markup: when a selector stops matching, `waitfor` times out or the log says `locate -> None`.
# Enter is typed as its own step (as a person types).
# DuckDuckGo may answer "Oops… server error" after many runs in a row (its rate limit): wait and run again.
wait 3
# DuckDuckGo: type a search, get results, scroll, open one.
open https://duckduckgo.com/
waitfor 60 !!document.querySelector("textarea[name=q], input[name=q]")
wait 1
shot ddg-home
locate textarea[name=q], input[name=q]
wait 1
click @
wait 0.5
pagetype webkit browser engine
wait 1
pagetype {enter}
waitfor 60 location.search.includes("q=webkit") && document.querySelectorAll("a[data-testid=result-title-a]").length > 0
wait 2
shot ddg-results
pagescroll 400 300 800
waitfor 10 window.scrollY > 0
locate a[data-testid=result-title-a]
wait 1
click @
waitfor 60 location.hostname !== "duckduckgo.com" && document.readyState !== "loading"
wait 2
shot ddg-result-opened
# Wikipedia: an article, scroll, follow a link, search, play the article's video file.
open https://en.wikipedia.org/wiki/Web_browser
waitfor 60 document.title.includes("Web browser") && document.readyState === "complete"
wait 1
pagescroll 400 300 1200
waitfor 10 window.scrollY > 0
shot wiki-article
locate #mw-content-text p a[title]
wait 1
click @
waitfor 60 location.pathname !== "/wiki/Web_browser" && location.pathname.startsWith("/wiki/") && document.readyState !== "loading"
open https://en.wikipedia.org/wiki/Special:Search
waitfor 60 !!document.querySelector("#searchText input")
wait 1
locate #searchText input
wait 1
click @
wait 0.5
pagetype WebKit (software)
wait 2
# Enter in this widget doesn't submit with the selftest's keys (a plain form does, see input.txt); click Search.
locate #searchText ~ * button[type=submit], #mw-search-top-table button[type=submit], button[type=submit]
wait 1
click @
waitfor 60 document.title.includes("WebKit")
wait 1
shot wiki-search
# The article's video file (VP8 WebM, ranged requests) plays; the article's own <video> is a placeholder its
# player script fills on click.
open https://upload.wikimedia.org/wikipedia/commons/c/c1/Web_browser_demo.webm
waitfor 60 !!document.querySelector("video")
js (() => { const v = document.querySelector("video"); v.muted = true; v.play(); return "play"; })()
waitfor 90 document.querySelector("video").currentTime > 0.5
shot wiki-video
# YouTube in one go (S006/S007/S009): home, search, a video from the results, playback, ad blocking, picture in
# picture (D-008: PiP reloads the page in its own web view and seeks). Shots and status for each step.
open https://www.youtube.com/
waitfor 120 [...document.querySelectorAll("input[name=search_query]")].some(e => e.getBoundingClientRect().width > 0)
wait 3
shot yt-home
status yt-home
locate input[name=search_query]
wait 1
click @
wait 0.5
pagetype webkit browser
wait 1
pagetype {enter}
waitfor 120 location.pathname === "/results" && !!document.querySelector("ytd-video-renderer")
wait 2
shot yt-results
# The video is opened by address (the result list's markup changes often).
open https://www.youtube.com/watch?v=jNQXAC9IVRw
waitfor 120 location.pathname === "/watch" && !!document.querySelector("video")
wait 5
js JSON.stringify({ MediaSource: typeof MediaSource, ManagedMediaSource: typeof ManagedMediaSource, src: document.querySelector("video").currentSrc.slice(0, 60), error: document.querySelector("#movie_player .ytp-error") ? document.querySelector("#movie_player .ytp-error").innerText.slice(0, 80) : null })
js (() => { const v = document.querySelector("video"); v.muted = true; v.play(); return "play"; })()
waitfor 60 document.querySelector("video").currentTime > 1
shot yt-video
status yt-video
# Ad blocking: no ad slots on the page, and the shield counts blocked requests.
assert ![...document.querySelectorAll("ytd-ad-slot-renderer, ytd-in-feed-ad-layout-renderer, ytd-player-legacy-desktop-watch-ads-renderer, .ytp-ad-player-overlay, .ytp-ad-text")].some(e => e.getBoundingClientRect().height > 0)
expect /active/blocked > 0
flyout shield
wait 1
shot yt-shield
flyout none
# Picture in picture (needs a video with a source: fails with YouTube until playback works).
cmd pip
wait 8
expect /active/pip true
shot yt-pip pip
status yt-pip
cmd exitpip
wait 3
expect /active/pip false
shot yt-pip-back
status done
quit
