#!/usr/bin/env python3 """NAVIGATION lane — QuickTile Settings (Jetpack Compose, single Activity). Owns surface REACHABILITY and back-stack integrity: every reach is proven with and_reach(before, after, target, source) — the TARGET surface's discriminating element APPEARED *and* the SOURCE surface's element DISAPPEARED. No test reaches a screen by relaunching the app (that is a deep link, not navigation). Surfaces (verified live on this emulator): S0 Main / Private DNS tab — title "QuickTile Settings"; card "Private DNS Tile"; DNS-tab-only element "Add Custom Hostname". S0b Main / USB Debugging tab — "USB Debugging Tile" / "USB Debug On" appear. S1 Shortcut Actions screen — title "Shortcut Actions"; "Active shortcuts: 0 / 15". Dialogs (full-modal overlays; opening one hides all of S0): About (Help "?" icon) — "Features"/"Developer"/"Permission Setup Help". Add Hostname ("Add Custom Hostname") — "Display Name" field; Cancel/Save. DNS Info ("Info about Cloudflare (1.1.1.1)") — title "About Cloudflare (1.1.1.1)". Network Type Info ("Network Type Detection" icon) — title + Close. Permission (About -> "Permission Setup Help") — "Permission Required" (depth 2). Discriminator traps handled: * "Private DNS Tile" is reused as a Shortcut-screen group header -> for the shortcut reach the source is the DNS-tab-only "Add Custom Hostname", never "Private DNS Tile". * The DNS-Info title "About Cloudflare (1.1.1.1)" is a SUBSTRING of the S0 icon desc "Info about Cloudflare (1.1.1.1)" -> the DNS-Info reach keys off the dialog-only body fragment "is known for its high speed" instead. * Because a modal hides all of S0, "Add Custom Hostname" reappearing is a sound proof that a dialog closed and S0 was restored. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # DNS-tab-only S0 element. Present on S0, hidden by every S0-hosted modal and by the # Shortcut Actions screen; reappears when we return to S0. The safest source/target # for "left S0" / "returned to S0" proofs on this app. S0_MARK = "Add Custom Hostname" # DNS-Info dialog body fragment — unique to that dialog, collides with nothing. CF_FRAG = "is known for its high speed" def _open_app_default(): """Virgin state (preferences survive restart_app; a toggled checkbox would stay ON), then wait for the first frame before the first ui().""" clear_data() launch_app() wait_for_foreground() def _find(nodes, *, text=None, desc=None): n = None if text is not None: n = find_node(nodes, text=text) or find_node_ci(nodes, text) if n is None and desc is not None: n = find_node(nodes, content_desc=desc) return n # ── depth-family helpers (the and_reach_* NAME is what the depth audit keys off) ── def and_reach_usb_tab(): """S0 -> S0b: tap the 'USB Debugging' tab; prove the USB card swapped in.""" tab = _find(ui(), text="USB Debugging") return bool(tab) and and_reach_surface(tab, "USB Debugging Tile", "Private DNS Tile") def and_reach_dns_tab(): """S0b -> S0: tap the 'Private DNS' tab; prove the DNS card swapped back.""" tab = _find(ui(), text="Private DNS") return bool(tab) and and_reach_surface(tab, "Private DNS Tile", "USB Debug On") def and_reach_shortcut_actions(): """S0 -> S1 via the top-bar shortcut icon. Source is the DNS-tab-only marker (NOT 'Private DNS Tile', which is reused as an S1 group header).""" trig = _find(ui(), desc="Open shortcut settings") return bool(trig) and and_reach_surface(trig, "Shortcut Actions", S0_MARK) def and_reach_about_dialog(): """S0 -> About overlay via the Help '?' icon (WSS granted => About, not Permission).""" trig = _find(ui(), desc="Help / Grant Permission") return bool(trig) and and_reach_surface(trig, "Permission Setup Help", S0_MARK) def and_reach_permission_dialog(): """About -> Permission overlay via the 'Permission Setup Help' button (hop 2).""" trig = _find(ui(), text="Permission Setup Help") return bool(trig) and and_reach_surface(trig, "Permission Required", "Permission Setup Help") def and_reach_addhost_dialog(): """S0 -> Add Hostname overlay via the 'Add Custom Hostname' button.""" trig = _find(ui(), text=S0_MARK) return bool(trig) and and_reach_surface(trig, "Display Name", "Enable auto-revert after a delay") def and_reach_dnsinfo_dialog(): """S0 -> DNS Info overlay via the Cloudflare info icon. Keys off the dialog-only body fragment to dodge the 'About Cloudflare' ⊂ 'Info about Cloudflare' collision.""" trig = _find(ui(), desc="Info about Cloudflare (1.1.1.1)") return bool(trig) and and_reach_surface(trig, CF_FRAG, S0_MARK) def and_reach_netinfo_dialog(): """S0 -> Network Type Info overlay via the info icon next to network-type detection. On open the S0 icon 'View|Network Type Detection' is removed and a new 'TextView|Network Type Detection' (the dialog title) appears.""" trig = _find(ui(), desc="Network Type Detection") return bool(trig) and and_reach_surface(trig, "Network Type Detection", S0_MARK) # ══════════════════════════════════════════════════════════════════════════════ # Tabs (S0 <-> S0b): a HorizontalPager page swap in the same Activity. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_tab_dns_to_usb", "nav_tab_dns_to_usb_vlm")) def test_tab_dns_to_usb(): _open_app_default() ok = and_reach_usb_tab() record("nav_tab_dns_to_usb", ok, "" if ok else "behavior_wrong: USB tab content did not swap in " "(USB Debugging Tile absent or Private DNS Tile still shown)", depth=1, jump_kind="reach", expect="'USB Debugging Tile' appeared and 'Private DNS Tile' disappeared " "after tapping the USB Debugging tab") vlm_assert("nav_tab_dns_to_usb", "In the top app bar of this screen, are there two icon buttons at the " "far right end of the bar (to the right of the 'QuickTile Settings' " "title)?", RESULTS_DIR, tag="position") @and_test(expects=("nav_tab_usb_to_dns",)) def test_tab_usb_to_dns(): _open_app_default() # Get onto the USB tab first (its own reach), then reverse — the assertion under # test is the reverse hop. if not and_reach_usb_tab(): record("nav_tab_usb_to_dns", False, "setup_failed: could not reach the USB tab to test the reverse hop", depth=1, jump_kind="reach", expect="'Private DNS Tile' restored after tapping the Private DNS tab") return ok = and_reach_dns_tab() record("nav_tab_usb_to_dns", ok, "" if ok else "behavior_wrong: DNS tab content did not swap back " "(Private DNS Tile absent or USB Debug On still shown)", depth=1, jump_kind="reach", expect="'Private DNS Tile' appeared and 'USB Debug On' disappeared after " "tapping the Private DNS tab") # ══════════════════════════════════════════════════════════════════════════════ # Shortcut Actions (S0 <-> S1) + back-stack. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_shortcut", "nav_reach_shortcut_vlm")) def test_reach_shortcut(): _open_app_default() ok = and_reach_shortcut_actions() record("nav_reach_shortcut", ok, "" if ok else "feature_missing: no reachable Shortcut Actions surface " "(title 'Shortcut Actions' never appeared)", depth=1, jump_kind="reach", expect="'Shortcut Actions' title appeared and DNS-tab 'Add Custom " "Hostname' disappeared after tapping the shortcut-settings icon") vlm_assert("nav_reach_shortcut", "Is this a screen titled 'Shortcut Actions' with a left-pointing back " "arrow at the top-left corner of the app bar?", RESULTS_DIR, tag="position") @and_test(expects=("nav_shortcut_back_icon",)) def test_shortcut_back_icon(): _open_app_default() if not and_reach_shortcut_actions(): record("nav_shortcut_back_icon", False, "setup_failed: could not reach Shortcut Actions to test the back icon", depth=1, jump_kind="reach", expect="S0 restored after tapping 'Back to tile settings'") return back_icon = _find(ui(), desc="Back to tile settings") ok = bool(back_icon) and and_reach_surface(back_icon, S0_MARK, "Shortcut Actions") record("nav_shortcut_back_icon", ok, "" if ok else "behavior_wrong: 'Back to tile settings' icon did not return " "to S0 (Add Custom Hostname absent or title still shown)", depth=1, jump_kind="reach", expect="DNS-tab 'Add Custom Hostname' reappeared and 'Shortcut Actions' " "disappeared after tapping the back icon") @and_test(expects=("nav_shortcut_back_system",)) def test_shortcut_back_system(): """Back-stack: one system BACK pops S1 back to S0.""" _open_app_default() if not and_reach_shortcut_actions(): record("nav_shortcut_back_system", False, "setup_failed: could not reach Shortcut Actions to test system BACK", depth=1, jump_kind="reach", expect="S0 restored after one system BACK from S1") return before = and_showing() and_back() # press BACK, pop one surface after = and_showing() ok = and_reach(before, after, S0_MARK, "Shortcut Actions") record("nav_shortcut_back_system", ok, "" if ok else "behavior_wrong: system BACK did not pop Shortcut Actions " "back to the tile-settings home", depth=1, jump_kind="reach", expect="DNS-tab 'Add Custom Hostname' restored and 'Shortcut Actions' gone " "after one system BACK") # ══════════════════════════════════════════════════════════════════════════════ # About dialog (D1) open + close. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_about_open", "nav_about_open_vlm")) def test_about_open(): _open_app_default() ok = and_reach_about_dialog() record("nav_about_open", ok, "" if ok else "feature_missing: Help icon did not open the About dialog " "('Permission Setup Help' never appeared)", depth=1, jump_kind="reach", expect="About-dialog 'Permission Setup Help' appeared and S0 'Add Custom " "Hostname' disappeared after tapping the Help icon") vlm_assert("nav_about_open", "Is a dialog card displayed in the center of the screen, layered over a " "dimmed/greyed-out background, with a 'Close' button near its " "bottom-right?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_about_close",)) def test_about_close(): _open_app_default() if not and_reach_about_dialog(): record("nav_about_close", False, "setup_failed: About dialog never opened, cannot test close", depth=1, jump_kind="reach", expect="S0 restored after closing the About dialog") return close_btn = _find(ui(), text="Close") ok = bool(close_btn) and and_reach_surface(close_btn, S0_MARK, "Permission Setup Help") record("nav_about_close", ok, "" if ok else "behavior_wrong: Close did not dismiss the About dialog back " "to S0", depth=1, jump_kind="reach", expect="S0 'Add Custom Hostname' reappeared and About 'Permission Setup " "Help' disappeared after tapping Close") # ══════════════════════════════════════════════════════════════════════════════ # Add Hostname dialog (D2) open + cancel. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_addhost_open", "nav_addhost_open_vlm")) def test_addhost_open(): _open_app_default() ok = and_reach_addhost_dialog() record("nav_addhost_open", ok, "" if ok else "feature_missing: 'Add Custom Hostname' did not open the Add " "Hostname dialog ('Display Name' field never appeared)", depth=1, jump_kind="reach", expect="'Display Name' field appeared and S0 'Enable auto-revert after a " "delay' disappeared after tapping Add Custom Hostname") vlm_assert("nav_addhost_open", "Is a dialog card shown over a dimmed background containing two text " "input fields stacked vertically, with 'Cancel' and 'Save' buttons " "below them?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_addhost_cancel",)) def test_addhost_cancel(): _open_app_default() if not and_reach_addhost_dialog(): record("nav_addhost_cancel", False, "setup_failed: Add Hostname dialog never opened, cannot test cancel", depth=1, jump_kind="reach", expect="S0 restored after cancelling the Add Hostname dialog") return cancel_btn = _find(ui(), text="Cancel") ok = bool(cancel_btn) and and_reach_surface(cancel_btn, S0_MARK, "Display Name") record("nav_addhost_cancel", ok, "" if ok else "behavior_wrong: Cancel did not dismiss the Add Hostname " "dialog back to S0", depth=1, jump_kind="reach", expect="S0 'Add Custom Hostname' reappeared and 'Display Name' field " "disappeared after tapping Cancel") # ══════════════════════════════════════════════════════════════════════════════ # DNS Info dialog (D4, Cloudflare) open + close. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_dnsinfo_open", "nav_dnsinfo_open_vlm")) def test_dnsinfo_open(): _open_app_default() ok = and_reach_dnsinfo_dialog() record("nav_dnsinfo_open", ok, "" if ok else "feature_missing: Cloudflare info icon did not open the DNS " "Info dialog (body text never appeared)", depth=1, jump_kind="reach", expect="DNS-Info body fragment 'is known for its high speed' appeared and " "S0 'Add Custom Hostname' disappeared after tapping the info icon") vlm_assert("nav_dnsinfo_open", "Is a dialog card titled about Cloudflare shown over a dimmed " "background, with a paragraph of description text and a single 'Close' " "button at its bottom-right?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_dnsinfo_close",)) def test_dnsinfo_close(): _open_app_default() if not and_reach_dnsinfo_dialog(): record("nav_dnsinfo_close", False, "setup_failed: DNS Info dialog never opened, cannot test close", depth=1, jump_kind="reach", expect="S0 restored after closing the DNS Info dialog") return close_btn = _find(ui(), text="Close") ok = bool(close_btn) and and_reach_surface(close_btn, S0_MARK, CF_FRAG) record("nav_dnsinfo_close", ok, "" if ok else "behavior_wrong: Close did not dismiss the DNS Info dialog " "back to S0", depth=1, jump_kind="reach", expect="S0 'Add Custom Hostname' reappeared and the DNS-Info body fragment " "disappeared after tapping Close") # ══════════════════════════════════════════════════════════════════════════════ # Network Type Info dialog (D5) open + close. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_netinfo_open",)) def test_netinfo_open(): _open_app_default() ok = and_reach_netinfo_dialog() record("nav_netinfo_open", ok, "" if ok else "feature_missing: network-type info icon did not open the " "Network Type Info dialog", depth=1, jump_kind="reach", expect="Network-Type-Info dialog title 'Network Type Detection' appeared " "and S0 'Add Custom Hostname' disappeared after tapping the info icon") @and_test(expects=("nav_netinfo_close",)) def test_netinfo_close(): _open_app_default() if not and_reach_netinfo_dialog(): record("nav_netinfo_close", False, "setup_failed: Network Type Info dialog never opened, cannot test close", depth=1, jump_kind="reach", expect="S0 restored after closing the Network Type Info dialog") return close_btn = _find(ui(), text="Close") # 'Close' is dialog-only here (S0 has no 'Close'); its disappearance proves the # dialog dismissed while S0's 'Add Custom Hostname' reappears. ok = bool(close_btn) and and_reach_surface(close_btn, S0_MARK, "Close") record("nav_netinfo_close", ok, "" if ok else "behavior_wrong: Close did not dismiss the Network Type Info " "dialog back to S0", depth=1, jump_kind="reach", expect="S0 'Add Custom Hostname' reappeared and the dialog's 'Close' button " "disappeared after tapping Close") # ══════════════════════════════════════════════════════════════════════════════ # DEPTH>=2 chain: Main -> About -> Permission, and its BACK unwind to home. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_chain_main_about_permission",)) def test_chain_main_about_permission(): """Two real hops: S0 -> About overlay -> Permission overlay. Each hop is proven by its own and_reach_* helper, so the declared depth=2 is backed by navigation.""" _open_app_default() hop1 = and_reach_about_dialog() # S0 -> About (depth 1) hop2 = hop1 and and_reach_permission_dialog() # About -> Permission (depth 2) # Extra content proof that we really landed on the Permission surface. has_wss = hop2 and any("WRITE_SECURE_SETTINGS" in n.get("text", "") for n in ui()) ok = bool(hop2 and has_wss) record("nav_chain_main_about_permission", ok, "" if ok else "behavior_wrong: Main->About->Permission chain broke " "(a hop did not swap surfaces or the Permission dialog " "lacked its WRITE_SECURE_SETTINGS text)", depth=2, jump_kind="reach", expect="hop1 About 'Permission Setup Help' appeared; hop2 'Permission " "Required' appeared while 'Permission Setup Help' left; the " "Permission dialog shows WRITE_SECURE_SETTINGS") @and_test(expects=("nav_chain_backstack_unwind", "nav_chain_backstack_unwind_vlm")) def test_chain_backstack_unwind(): """Back-stack from the deepest surface (Permission) back to home. Opening 'Permission Setup Help' closes About and replaces it with the Permission overlay, so exactly one BACK returns the Permission overlay to S0 — verified live.""" _open_app_default() deep = and_reach_about_dialog() and and_reach_permission_dialog() if not deep: record("nav_chain_backstack_unwind", False, "setup_failed: could not build the Main->About->Permission chain to " "unwind", depth=2, jump_kind="reach", expect="home (S0) restored after backing out of the Permission overlay") vlm_assert("nav_chain_backstack_unwind", "Are two tabs labelled 'Private DNS' and 'USB Debugging' visible in " "a row directly below the 'QuickTile Settings' title at the top of " "this screen?", RESULTS_DIR, tag="position") return before = and_showing() and_back() # pop Permission overlay -> S0 after = and_showing() ok = and_reach(before, after, S0_MARK, "Permission Required") record("nav_chain_backstack_unwind", ok, "" if ok else "behavior_wrong: BACK from the Permission overlay did not " "return to the tile-settings home", depth=2, jump_kind="reach", expect="S0 'Add Custom Hostname' restored and 'Permission Required' gone " "after one BACK from the Permission overlay") vlm_assert("nav_chain_backstack_unwind", "Are two tabs labelled 'Private DNS' and 'USB Debugging' visible in a " "row directly below the 'QuickTile Settings' title at the top of this " "screen?", RESULTS_DIR, tag="position") TESTS = [ test_tab_dns_to_usb, test_tab_usb_to_dns, test_reach_shortcut, test_shortcut_back_icon, test_shortcut_back_system, test_about_open, test_about_close, test_addhost_open, test_addhost_cancel, test_dnsinfo_open, test_dnsinfo_close, test_netinfo_open, test_netinfo_close, test_chain_main_about_permission, test_chain_backstack_unwind, ] if __name__ == "__main__": run_suite(TESTS, "navigation")