#!/bin/bash
# Reproduce: password generation popup overlaps permission prompt.
#
# Prereqs:
#   * Apply chromium-changes.patch to the source tree
#   * autoninja -C out/asan chrome
#   * Start the HTTP server:  python3 server.py <port> &
#
# This host has no X11/Wayland display, so chrome runs with
# --ozone-platform=headless. The patch shims HeadlessScreen::IsHeadless()
# to false so PermissionRequestManager creates the permission bubble exactly
# as it would on a real desktop (where IsHeadless() is always false).

set -e
SRC=${CHROMIUM_SRC:-/chromium/chromium/src}
PORT=${1:-19234}
PROFILE=/tmp/chrome-poc-profile

rm -rf "$PROFILE"
timeout 25 "$SRC/out/asan/chrome" \
  --no-sandbox \
  --ozone-platform=headless \
  --ozone-override-screen-size=1600,1200 \
  --no-first-run --no-default-browser-check --ignore-gpu-blocklist \
  --disable-gpu \
  --enable-logging=stderr --v=0 \
  --window-size=1400,1000 --window-position=0,0 \
  --user-data-dir="$PROFILE" \
  "http://127.0.0.1:${PORT}/poc.html?poc-trigger" 2>&1 \
  | grep -E 'POC|CONSOLE'
