RecreationBench / android /markusfisch-shadereditor /tests /test_android_navigation.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 3)
c1c6a0c verified
Raw History Blame Contribute Delete
22.3 kB
#!/usr/bin/env python3
"""NAVIGATION eval for Shader Editor — surface REACHABILITY + back-stack integrity.
This lane owns jump_kind="reach" and every depth>=2 chain. Each jump is proven with
and_reach(before, after, target, source): the TARGET surface's element APPEARED and
the SOURCE surface's element DISAPPEARED — a screen that was in the tree all along is
never "reached". Back-stack tests use and_back() (BACK + pop one surface) on the
sub-ACTIVITIES (Settings / Add uniform / Load sample) and their dialogs, where BACK
reliably unwinds one hop. Every surface/id/behavior below was verified on the running
original.
python3 test_android_navigation.py <PACKAGE> <RESULTS_DIR>
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
# ── Portable launch: land on MainActivity, NOT LeakCanary's leak list ────────────
# The debug build ships LeakCanary, which registers a SECOND MAIN/LAUNCHER activity,
# so the kit's launch_app()/restart_app() land on the wrong screen. Resolve the
# app's own non-leakcanary LAUNCHER activity at runtime (works for the recreation
# too, which has no LeakCanary), verify the editor toolbar appeared, and retry.
# Uses only PACKAGE, so it is fully portable.
def launch_editor():
out = adb_shell("cmd", "package", "query-activities", "--brief",
"-a", "android.intent.action.MAIN",
"-c", "android.intent.category.LAUNCHER", PACKAGE)
comp = next((ln.strip() for ln in out.splitlines()
if ln.strip().startswith(PACKAGE + "/")
and "leakcanary" not in ln.lower()), "")
for _ in range(4):
force_stop()
if comp:
adb_shell("am", "start", "-n", comp)
else:
launch_app() # recreation: no explicit launcher listing
settle("launch")
wait_for_foreground()
if node_by_id(ui(), "menu_btn") or node_by_id(ui(), "editor"):
return True
back()
settle("tap") # dismiss whatever we landed on, then retry
return False
# ── Depth-family helpers. The and_enter_*/and_reach_* NAME is what the depth audit
# looks for; the implementation is ours. Each crosses exactly one surface. ────────
def and_reach_menu():
"""Editor -> overflow popup. Proven jump: a menu button appeared, the editor's
hamburger disappeared. Returns True on a clean reach (counts one surface)."""
mb = node_by_id(ui(), "menu_btn")
if mb is None:
return False
return and_reach_surface(mb, "Settings", "Open drawer")
def and_reach_settings():
"""Editor -> menu -> Preferences activity (crosses menu, then the activity)."""
if not launch_editor():
return False
if not and_reach_menu():
return False
settings_btn = node_by_id(ui(), "settings")
return settings_btn is not None and and_reach_surface(
settings_btn, "Preferences", "Settings")
def and_reach_add_uniform():
"""Editor -> menu -> Add uniform/texture activity."""
if not launch_editor():
return False
if not and_reach_menu():
return False
add_btn = node_by_id(ui(), "add_uniform")
return add_btn is not None and and_reach_surface(
add_btn, "Add uniform/texture", "Settings")
def and_enter_uniform_search():
"""Add uniform -> expanded SearchView (the search bar collapses the title).
Source is the 'Add uniform/texture' title (it disappears into the search bar),
NOT the 'Search' button: the expanded field's own 'Search…' hint contains the
substring 'search', so a source='Search' verdict could never clear."""
search_btn = node_by_id(ui(), "search")
if search_btn is None:
return False
return and_reach_surface(search_btn, "Collapse", "Add uniform/texture")
def and_reach_textsize_dialog():
"""Editor -> menu -> Settings -> Text size list dialog (3 surfaces crossed)."""
if not and_reach_settings():
return False
row = find_node_ci(ui(), "Text size")
# The dialog covers the whole Preferences surface: 'Medium' (a dialog choice)
# appears and the 'Preferences' title disappears.
return row is not None and and_reach_surface(row, "Medium", "Preferences")
def and_reach_load_sample():
"""Editor -> menu -> Load sample activity. Target is a sample NAME ('Circles')
that appears fresh — the activity's own title text collides with the menu
button label, so a sample row is the honest discriminator."""
if not launch_editor():
return False
if not and_reach_menu():
return False
load_btn = node_by_id(ui(), "load_sample")
return load_btn is not None and and_reach_surface(load_btn, "Circles", "Settings")
def and_reach_rename_dialog():
"""Editor -> drawer -> long-press the shader row -> Rename shader dialog."""
if not launch_editor():
return False
ham = find_node(ui(), content_desc="Open drawer")
if ham is None or not and_reach_surface(ham, "Close drawer", "Open drawer"):
return False
settle("tap") # let the drawer animation finish fully
st = node_by_id(ui(), "shader_title")
if st is None:
return False
before = and_showing()
long_press(st, ms=1200)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "Rename shader", "Close drawer")
if ok:
and_enter("Rename shader")
return ok
# ══════════════════════════════════════════════════════════════════════════════
# 1. Editor -> Settings (depth 2) + back-stack
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_settings", "nav_reach_settings_vlm"))
def test_reach_settings():
ok = and_reach_settings() # editor -(menu)-> -(activity)-> Preferences
record("nav_reach_settings", ok,
"" if ok else "feature_missing: Settings/Preferences not reachable from menu",
depth=2, jump_kind="reach",
expect="Preferences title appeared; the 'Settings' menu button no longer showing")
vlm_assert("nav_reach_settings",
"Is this a Preferences/Settings screen showing a vertical list of "
"labelled option rows with a left-pointing back arrow at the top-left?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_back_settings_to_editor",))
def test_back_settings_to_editor():
deep = and_reach_settings()
home = False
if deep:
and_back() # BACK pops the Preferences activity
en = ui()
home = (node_by_id(en, "menu_btn") is not None
and find_node_ci(en, "Preferences") is None)
record("nav_back_settings_to_editor", deep and home,
"" if (deep and home) else "behavior_wrong: BACK did not return to the editor",
depth=2, jump_kind="reach",
expect="editor toolbar (menu_btn) restored and Preferences gone after one BACK")
# ══════════════════════════════════════════════════════════════════════════════
# 2. Editor -> Add uniform/texture (depth 2) + back-stack + tab + search
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_add_uniform", "nav_reach_add_uniform_vlm"))
def test_reach_add_uniform():
ok = and_reach_add_uniform()
record("nav_reach_add_uniform", ok,
"" if ok else "feature_missing: Add uniform/texture not reachable from menu",
depth=2, jump_kind="reach",
expect="'Add uniform/texture' title appeared; the 'Settings' menu button gone")
vlm_assert("nav_reach_add_uniform",
"Near the top are there three tabs (preset, sampler2D, samplerCube) "
"with a magnifier/search icon at the top-right of the toolbar?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_back_add_uniform_to_editor",))
def test_back_add_uniform_to_editor():
deep = and_reach_add_uniform()
home = False
if deep:
and_back()
en = ui()
home = (node_by_id(en, "menu_btn") is not None
and find_node_ci(en, "Add uniform/texture") is None)
record("nav_back_add_uniform_to_editor", deep and home,
"" if (deep and home) else "behavior_wrong: BACK did not return to the editor",
depth=2, jump_kind="reach",
expect="editor toolbar restored and Add-uniform title gone after one BACK")
@and_test(expects=("nav_uniform_tab_sampler2d",))
def test_uniform_tab_sampler2d():
deep = and_reach_add_uniform()
ok = False
if deep:
tab = find_node(ui(), text="sampler2D")
# preset->sampler2D: the 'Add texture' FAB appears, the 'battery (float)'
# preset row disappears. Robust whether or not textures already exist.
ok = tab is not None and and_reach_surface(tab, "Add texture", "battery (float)")
record("nav_uniform_tab_sampler2d", deep and ok,
"" if (deep and ok) else "behavior_wrong: sampler2D tab did not swap the list",
depth=2, jump_kind="reach",
expect="'Add texture' control appeared; the 'battery (float)' preset row gone")
@and_test(expects=("nav_uniform_search",))
def test_uniform_search():
deep = and_reach_add_uniform()
ok = deep and and_enter_uniform_search() # tap Search -> SearchView expands
record("nav_uniform_search", ok,
"" if ok else "behavior_wrong: search did not expand into a search field",
depth=3, jump_kind="reach",
expect="expanded search bar (Collapse affordance) appeared; the Add-uniform title gone")
# ══════════════════════════════════════════════════════════════════════════════
# 3. Editor -> Load sample (depth 2) + back-stack
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_load_sample", "nav_reach_load_sample_vlm"))
def test_reach_load_sample():
ok = and_reach_load_sample()
record("nav_reach_load_sample", ok,
"" if ok else "feature_missing: Load sample not reachable from menu",
depth=2, jump_kind="reach",
expect="sample row 'Circles' appeared; the 'Settings' menu button gone")
vlm_assert("nav_reach_load_sample",
"Is this a vertical list of shader samples where several rows show a "
"small colorful preview thumbnail on the left and a name with a short "
"description to its right?",
RESULTS_DIR, tag="layout")
@and_test(expects=("nav_back_load_sample_to_editor",))
def test_back_load_sample_to_editor():
deep = and_reach_load_sample()
home = False
if deep:
and_back()
en = ui()
home = (node_by_id(en, "menu_btn") is not None
and find_node_ci(en, "Load sample") is None)
record("nav_back_load_sample_to_editor", deep and home,
"" if (deep and home) else "behavior_wrong: BACK did not return to the editor",
depth=2, jump_kind="reach",
expect="editor toolbar restored and Load-sample list gone after one BACK")
# ══════════════════════════════════════════════════════════════════════════════
# 4. Editor -> drawer (depth 1) and Editor -> overflow menu (depth 1)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_drawer", "nav_reach_drawer_vlm"))
def test_reach_drawer():
ok = False
if launch_editor():
ham = find_node(ui(), content_desc="Open drawer")
# Drawer slides over the editor: the hamburger flips to a 'Close drawer'
# arrow and the 'shaders' list appears.
ok = ham is not None and and_reach_surface(ham, "Close drawer", "Open drawer")
record("nav_reach_drawer", ok,
"" if ok else "feature_missing: navigation drawer did not open",
depth=1, jump_kind="reach",
expect="'Close drawer' affordance + shaders list appeared; 'Open drawer' hamburger gone")
vlm_assert("nav_reach_drawer",
"Near the top-left, is a small multi-colored square icon shown "
"directly to the left of the text 'Default' (a shader row of the "
"opened drawer)?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_reach_menu",))
def test_reach_menu():
ok = False
if launch_editor():
ok = and_reach_menu() # menu button appeared, editor hamburger gone
record("nav_reach_menu", ok,
"" if ok else "feature_missing: overflow menu did not open",
depth=1, jump_kind="reach",
expect="'Settings' menu button appeared; the editor 'Open drawer' hamburger gone")
# ══════════════════════════════════════════════════════════════════════════════
# 5. Deep chains into Settings dialogs (depth 3) + a 2-hop back-stack unwind
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_textsize_dialog", "nav_reach_textsize_dialog_vlm"))
def test_reach_textsize_dialog():
ok = and_reach_textsize_dialog()
record("nav_reach_textsize_dialog", ok,
"" if ok else "feature_missing: Text size dialog not reachable from Settings",
depth=3, jump_kind="reach",
expect="'Medium' choice appeared; the Preferences title gone (dialog open)")
vlm_assert("nav_reach_textsize_dialog",
"Is a small dialog open showing a short vertical list of choices, "
"each preceded by a round radio-button selector?",
RESULTS_DIR, tag="shape")
@and_test(expects=("nav_back_textsize_dialog",))
def test_back_textsize_dialog():
deep = and_reach_textsize_dialog()
back_ok = False
if deep:
and_back() # dismiss the dialog, back to Preferences
n = ui()
back_ok = (find_node_ci(n, "Preferences") is not None
and find_node(n, text="Medium") is None)
record("nav_back_textsize_dialog", deep and back_ok,
"" if (deep and back_ok) else "behavior_wrong: BACK did not dismiss the dialog to Settings",
depth=3, jump_kind="reach",
expect="Preferences restored and the 'Medium' choice gone after one BACK")
@and_test(expects=("nav_backstack_settings_dialog_2hop",))
def test_backstack_settings_dialog():
# editor -(menu)-> -(activity)-> Preferences -(dialog)-> Text size (3 surfaces),
# then BACK unwinds hop by hop: dialog -> Preferences -> editor. Keyboard-free.
deep = and_reach_textsize_dialog()
step1 = step2 = False
if deep:
and_back() # pop the dialog -> Preferences
n1 = ui()
step1 = (find_node_ci(n1, "Preferences") is not None
and find_node(n1, text="Medium") is None)
and_back() # pop the activity -> editor
n2 = ui()
step2 = (node_by_id(n2, "menu_btn") is not None
and find_node_ci(n2, "Preferences") is None)
ok = deep and step1 and step2
record("nav_backstack_settings_dialog_2hop", ok,
"" if ok else "behavior_wrong: BACK did not unwind dialog->Settings->editor hop by hop",
depth=3, jump_kind="reach",
expect="1st BACK restores Preferences (dialog gone); 2nd BACK restores the editor toolbar")
@and_test(expects=("nav_reach_runmode_dialog",))
def test_reach_runmode_dialog():
ok = False
if and_reach_settings():
row = find_node_ci(ui(), "Run mode")
# 'Run manually' is a dialog-only choice (the screen only shows the summary
# 'Auto run on change'), so it is a clean 'appeared'.
ok = row is not None and and_reach_surface(row, "Run manually", "Preferences")
record("nav_reach_runmode_dialog", ok,
"" if ok else "feature_missing: Run mode dialog not reachable from Settings",
depth=3, jump_kind="reach",
expect="'Run manually' choice appeared; the Preferences title gone (dialog open)")
# ══════════════════════════════════════════════════════════════════════════════
# 6. Editor -> drawer -> Rename dialog (depth 2) + dialog dismiss
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_rename_dialog", "nav_reach_rename_dialog_vlm"))
def test_reach_rename_dialog():
ok = and_reach_rename_dialog()
record("nav_reach_rename_dialog", ok,
"" if ok else "feature_missing: Rename dialog not reachable via drawer long-press",
depth=2, jump_kind="reach",
expect="'Rename shader' dialog title appeared; the drawer's Close-drawer affordance gone")
vlm_assert("nav_reach_rename_dialog",
"Is a dialog titled 'Rename shader' showing a single-line text field "
"and Cancel / OK buttons?",
RESULTS_DIR, tag="content")
@and_test(expects=("nav_dismiss_rename_dialog",))
def test_dismiss_rename_dialog():
deep = and_reach_rename_dialog()
dismissed = False
if deep:
cancel = node_by_id(ui(), "button2") or find_node_ci(ui(), "Cancel")
if safe_tap(cancel):
n = ui()
dismissed = find_node_ci(n, "Rename shader") is None
record("nav_dismiss_rename_dialog", deep and dismissed,
"" if (deep and dismissed) else "behavior_wrong: Cancel did not dismiss the Rename dialog",
depth=2, jump_kind="reach",
expect="Rename dialog gone after tapping Cancel (returned to the drawer)")
# ══════════════════════════════════════════════════════════════════════════════
# 7. Toolbar affordance + BACK end-state (VLM), on a reached sub-activity
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_settings_toolbar_backarrow_vlm",))
def test_settings_toolbar_backarrow():
reached = and_reach_settings()
if reached:
vlm_assert("nav_settings_toolbar_backarrow",
"Is there a left-pointing back/up arrow at the very top-left of "
"the toolbar (to the left of the 'Preferences' title)?",
RESULTS_DIR, tag="position", depth=2, jump_kind="reach")
else:
record("nav_settings_toolbar_backarrow_vlm", False,
"setup_failed: could not reach Settings to inspect its toolbar",
depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_back_to_editor_vlm",))
def test_back_to_editor_endstate():
deep = and_reach_settings()
if deep:
and_back() # return to the editor
ui()
vlm_assert("nav_back_to_editor",
"Is a code editor with a top toolbar showing again — lines of "
"source code, NOT a settings screen or a list of options?",
RESULTS_DIR, tag="layout", depth=1, jump_kind="reach")
else:
record("nav_back_to_editor_vlm", False,
"setup_failed: could not reach Settings to test the BACK end-state",
depth=1, jump_kind="reach", tag="layout")
TESTS = [
test_reach_settings,
test_back_settings_to_editor,
test_reach_add_uniform,
test_back_add_uniform_to_editor,
test_uniform_tab_sampler2d,
test_uniform_search,
test_reach_load_sample,
test_back_load_sample_to_editor,
test_reach_drawer,
test_reach_menu,
test_reach_textsize_dialog,
test_back_textsize_dialog,
test_backstack_settings_dialog,
test_reach_runmode_dialog,
test_reach_rename_dialog,
test_dismiss_rename_dialog,
test_settings_toolbar_backarrow,
test_back_to_editor_endstate,
]
if __name__ == "__main__":
if not device_online():
print("Device not reachable — aborting (a whole module of setup_failed "
"usually means the emulator/tunnel died, not that the app is broken)")
sys.exit(2)
run_suite(TESTS, "navigation")