#!/usr/bin/env python3 """NAVIGATION-lane behavioral suite for FlashDim. Owns surface REACHABILITY and BACK-STACK integrity: tapping a nav trigger (toolbar action, quick-action button, preference row) lands on the intended surface, and BACK unwinds it hop by hop. This lane is the SOLE owner of jump_kind="reach" and of the depth>=2 chains — every jump is PROVEN with and_reach(before, after, target, source): the TARGET surface's discriminating element APPEARED *and* the SOURCE surface's element DISAPPEARED. A screen that was in the dump all along was never reached, and a dead shell that never opens the dialog FAILS. CEDES: dialog CONTENT strings -> text; state flips (radio/switch) -> states; displayed values (level, counter) -> computation; tree SHAPE counts -> structure. Here we assert only that we crossed a surface boundary and that BACK returns us. All target/source strings below were observed live on the original app: home --morse_button--> "Flash morse code" (Off disappears) home --interval_button--> "Interval Flash" (Off disappears) home --icon_credits_action->"Show Icon Credits" (Off disappears) [About] home --links_action--> "Repository on GitHub" (Off disappears) [Links] home --settings_action--> "Flashlight controls" (Off disappears) [Settings] About --Show Icon Credits--> "Open Pictogrammers" (Show Icon Credits gone) [d2] Settings --Preferred level-->"Set preferred level" (Context awareness gone) [d2] Settings --about row--> "Repository on GitHub" (Flashlight controls gone)[d2] """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else "/workspace/testgen/eval/results" # ────────────────────────────────────────────────────────────────────────────── # Depth-family helpers. A declared depth>=1 / jump_kind="reach" must be backed by # a real and_enter_*/and_reach_* call so the depth audit sees genuine navigation # (never a relaunch). The and_reach_* helpers return the reach VERDICT (bool) and # count one surface via and_reach_surface(); the and_enter_* helpers open a # surface and return its fresh node list for chaining. # ────────────────────────────────────────────────────────────────────────────── def _home(): """Restart to a settled MainActivity and return its node list.""" restart_app() wait_for_foreground() return ui() def and_reach_morse_dialog(home): """home --morse_button--> Morse dialog. Verdict: title appears, Off gone.""" n = node_by_id(home, "morse_button") return bool(n) and and_reach_surface(n, "Flash morse code", "Off") def and_reach_interval_dialog(home): """home --interval_button--> Interval dialog.""" n = node_by_id(home, "interval_button") return bool(n) and and_reach_surface(n, "Interval Flash", "Off") def and_reach_about_dialog(home): """home --icon_credits_action--> About dialog (button 'Show Icon Credits').""" n = node_by_id(home, "icon_credits_action") return bool(n) and and_reach_surface(n, "Show Icon Credits", "Off") def and_reach_links_dialog(home): """home --links_action--> Links dialog (row 'Repository on GitHub').""" n = node_by_id(home, "links_action") return bool(n) and and_reach_surface(n, "Repository on GitHub", "Off") def and_enter_about_dialog(home): """Open the About dialog and return its fresh node list (for chaining).""" if not and_reach_about_dialog(home): return None return ui() def and_reach_icon_credits(about): """About --Show Icon Credits--> Icon Credits dialog (button 'Open Pictogrammers'); the 'Show Icon Credits' button disappears.""" n = node_by_id(about, "button1") # "Show Icon Credits" return bool(n) and and_reach_surface(n, "Open Pictogrammers", "Show Icon Credits") def and_reach_settings(home): """home --settings_action--> SettingsActivity. Verdict: 'Flashlight controls' category appears, home 'Quick Actions' label disappears (home 'Off' cannot be the source: the Settings summaries contain the substring 'off').""" n = node_by_id(home, "settings_action") return bool(n) and and_reach_surface(n, "Flashlight controls", "Quick Actions") def and_enter_settings(home): """Open Settings and return its fresh node list (for chaining).""" if not and_reach_settings(home): return None return ui() def and_reach_preferred_level(settings): """Settings --Preferred level row--> 'Set preferred level' dialog; the 'Context awareness' row disappears (its own title, not the row we tapped, because 'Set preferred level' contains 'preferred level' as a substring).""" row = find_node_ci(settings, "Preferred level") return bool(row) and and_reach_surface(row, "Set preferred level", "Context awareness") def and_reach_settings_links(settings): """Settings --about row ('by Cyb3rKo')--> Links dialog. 'Repository on GitHub' appears; the 'Flashlight controls' category disappears.""" row = find_node_ci(settings, "by Cyb3rKo") or find_node_ci(settings, "FlashDim Dev") return bool(row) and and_reach_surface(row, "Repository on GitHub", "Flashlight controls") def _home_restored(): """True iff we are back on the MainActivity home surface (Off button visible and NOT on a blank/dead screen).""" nodes = ui() return (node_by_id(nodes, "off_button") is not None and find_node_ci(nodes, "Quick Actions") is not None) # ══════════════════════════════════════════════════════════════════════════════ # DEPTH-1 reach: each top-level destination reached from home. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_morse", "nav_reach_morse_vlm")) def test_reach_morse(): home = _home() ok = and_reach_morse_dialog(home) record("nav_reach_morse", ok, "" if ok else "feature_missing: Morse dialog ('Flash morse code') did " "not appear / home 'Off' did not disappear after tapping morse_button", depth=1, jump_kind="reach", expect="'Flash morse code' dialog title visible; home 'Off' button gone") vlm_assert("nav_reach_morse", "Is a dialog titled 'Flash morse code' shown with a single-line " "text input field above a 'Flash' button?", RESULTS_DIR, tag="layout") @and_test(expects=("nav_reach_interval",)) def test_reach_interval(): home = _home() ok = and_reach_interval_dialog(home) record("nav_reach_interval", ok, "" if ok else "feature_missing: Interval dialog ('Interval Flash') did " "not appear / home 'Off' did not disappear after tapping interval_button", depth=1, jump_kind="reach", expect="'Interval Flash' dialog title visible; home 'Off' button gone") @and_test(expects=("nav_reach_interval_vlm",)) def test_reach_interval_vlm(): home = _home() ok = and_reach_interval_dialog(home) record("nav_reach_interval_probe", ok, "" if ok else "setup_failed: could not open Interval dialog for VLM", depth=1, jump_kind="reach", expect="'Interval Flash' dialog reached for screenshot") vlm_assert("nav_reach_interval", "Is a dialog shown with two side-by-side radio toggles labelled " "'TIME' and 'BPM' and a numeric input field?", RESULTS_DIR, tag="position") @and_test(expects=("nav_reach_links", "nav_reach_links_vlm")) def test_reach_links(): home = _home() ok = and_reach_links_dialog(home) record("nav_reach_links", ok, "" if ok else "feature_missing: Links dialog ('Repository on GitHub') " "did not appear / home 'Off' did not disappear after tapping links_action", depth=1, jump_kind="reach", expect="'Repository on GitHub' row visible; home 'Off' button gone") vlm_assert("nav_reach_links", "Is a dialog titled 'Links' shown listing several rows, each row " "having a button labelled 'Visit' on its right side?", RESULTS_DIR, tag="position") @and_test(expects=("nav_reach_about",)) def test_reach_about(): home = _home() ok = and_reach_about_dialog(home) record("nav_reach_about", ok, "" if ok else "feature_missing: About dialog ('Show Icon Credits' " "button) did not appear / home 'Off' did not disappear after tapping " "icon_credits_action", depth=1, jump_kind="reach", expect="'Show Icon Credits' button visible; home 'Off' button gone") @and_test(expects=("nav_reach_settings", "nav_reach_settings_vlm")) def test_reach_settings(): home = _home() ok = and_reach_settings(home) # A single-Activity app cannot discriminate by activity, but FlashDim uses a # real SettingsActivity, so corroborate the surface jump with it. on_settings = "SettingsActivity" in get_current_activity() record("nav_reach_settings", ok and on_settings, "" if ok and on_settings else "feature_missing: Settings surface " "('Flashlight controls') did not appear / SettingsActivity not resumed", depth=1, jump_kind="reach", expect="'Flashlight controls' category visible in SettingsActivity; " "home 'Quick Actions' label gone") vlm_assert("nav_reach_settings", "Is a settings screen shown as a vertical scrollable list of " "labelled rows, several rows having an on/off toggle switch on the " "right, with a back arrow at the top-left?", RESULTS_DIR, tag="position") # ══════════════════════════════════════════════════════════════════════════════ # DEPTH-2 chains (owned by this lane). Each chains two and_enter/and_reach hops. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_reach_icon_credits_d2", "nav_reach_icon_credits_d2_vlm")) def test_reach_icon_credits_depth2(): home = _home() about = and_enter_about_dialog(home) # hop 1: home -> About deep = about is not None and and_reach_icon_credits(about) # hop 2 -> Icon Credits record("nav_reach_icon_credits_d2", deep, "" if deep else "feature_missing: Icon Credits dialog ('Open " "Pictogrammers') not reached from About via 'Show Icon Credits'", depth=2, jump_kind="reach", expect="'Open Pictogrammers' button visible; 'Show Icon Credits' gone " "(home -> About -> Icon Credits)") vlm_assert("nav_reach_icon_credits_d2", "Is a dialog titled 'Icon Credits' shown, listing icon credit lines " "and a button reading 'Open Pictogrammers'?", RESULTS_DIR, tag="content") @and_test(expects=("nav_reach_preferred_level_d2", "nav_reach_preferred_level_d2_vlm")) def test_reach_preferred_level_depth2(): home = _home() settings = and_enter_settings(home) # hop 1: home -> Settings deep = settings is not None and and_reach_preferred_level(settings) # hop 2 record("nav_reach_preferred_level_d2", deep, "" if deep else "feature_missing: 'Set preferred level' dialog not " "reached from Settings via the 'Preferred level' row", depth=2, jump_kind="reach", expect="'Set preferred level' dialog visible; 'Context awareness' row " "gone (home -> Settings -> preferred-level dialog)") vlm_assert("nav_reach_preferred_level_d2", "In the centered pop-up dialog, is there a wide horizontal " "light-purple / lavender bar with a row of small evenly-spaced dots " "along it?", RESULTS_DIR, tag="shape") @and_test(expects=("nav_reach_settings_links_d2",)) def test_reach_settings_links_depth2(): home = _home() settings = and_enter_settings(home) # hop 1: home -> Settings deep = settings is not None and and_reach_settings_links(settings) # hop 2 record("nav_reach_settings_links_d2", deep, "" if deep else "feature_missing: Links dialog not reached from the " "Settings 'about' row (home -> Settings -> Links)", depth=2, jump_kind="reach", expect="'Repository on GitHub' visible; 'Flashlight controls' category " "gone (home -> Settings -> Links)") # ══════════════════════════════════════════════════════════════════════════════ # BACK-STACK integrity: BACK returns to where we came from, hop by hop. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("nav_back_morse_to_home",)) def test_back_from_morse_returns_home(): home = _home() deep = and_reach_morse_dialog(home) # one BACK pops the dialog; home 'Off'/'Quick Actions' must be restored and it # must NOT be a blank/dead screen. back_ok = deep and and_back() == 0 and _home_restored() record("nav_back_morse_to_home", back_ok, "" if back_ok else "behavior_wrong: BACK from the Morse dialog did not " "restore the home surface (Off / Quick Actions not visible)", depth=1, jump_kind="reach", expect="home 'Off' button + 'Quick Actions' restored after one BACK") @and_test(expects=("nav_back_settings_to_home",)) def test_back_from_settings_returns_home(): home = _home() deep = and_reach_settings(home) back_ok = deep and and_back() == 0 and _home_restored() on_home = "MainActivity" in get_current_activity() record("nav_back_settings_to_home", back_ok and on_home, "" if back_ok and on_home else "behavior_wrong: BACK from Settings did " "not return to the home MainActivity surface", depth=1, jump_kind="reach", expect="MainActivity home restored (Off visible) after one BACK from " "Settings") @and_test(expects=("nav_up_arrow_settings_to_home",)) def test_up_arrow_from_settings_returns_home(): home = _home() deep = and_reach_settings(home) # The toolbar Up affordance (content-desc 'Navigate up') is the intended way # back from Settings; assert it lands on home. up = find_node(ui(), content_desc="Navigate up") if deep else None tapped = up is not None and tap_node(up) if tapped: settle("launch") and_reset_depth() # the Up affordance popped the surface (no BACK keypress) up_ok = tapped and _home_restored() and "MainActivity" in get_current_activity() record("nav_up_arrow_settings_to_home", up_ok, "" if up_ok else "behavior_wrong: the Settings toolbar Up arrow did not " "return to the home MainActivity surface", depth=1, jump_kind="reach", expect="MainActivity home restored after tapping the 'Navigate up' arrow") @and_test(expects=("nav_backstack_icon_credits_unwinds",)) def test_backstack_icon_credits_unwinds(): """Back-stack from the DEEPEST surface to home. We descend two hops (home -> About -> Icon Credits, depth 2). OBSERVED on the original: About and Icon Credits share one AlertDialog instance (its content is swapped in place), so a single BACK from the deepest surface dismisses the whole dialog straight to home rather than re-showing About. Assert that observed unwind: BACK from Icon Credits restores home (Off + Quick Actions) and it is NOT a blank screen, and the deepest surface's 'Open Pictogrammers' is gone.""" home = _home() about = and_enter_about_dialog(home) deep = about is not None and and_reach_icon_credits(about) # depth 2 unwound = False if deep: and_back() # pop the shared dialog after = ui() unwound = (_home_restored() and find_node_ci(after, "Open Pictogrammers") is None and "MainActivity" in get_current_activity()) ok = deep and unwound record("nav_backstack_icon_credits_unwinds", ok, "" if ok else "behavior_wrong: BACK from the depth-2 Icon Credits " "surface did not return to the home MainActivity (Off / Quick Actions)", depth=2, jump_kind="reach", expect="one BACK from Icon Credits (depth 2) restores home ('Off' + " "'Quick Actions'); 'Open Pictogrammers' gone") @and_test(expects=("nav_backstack_preferred_level_unwinds",)) def test_backstack_preferred_level_unwinds(): """home -> Settings -> Set-preferred-level dialog, then BACK -> Settings, BACK -> home.""" home = _home() settings = and_enter_settings(home) deep = settings is not None and and_reach_preferred_level(settings) # depth 2 # pop 1: dialog -> Settings (the 'Context awareness' row reappears; the dialog # title 'Set preferred level' is gone). pop1 = False if deep: and_back() mid = ui() pop1 = (find_node_ci(mid, "Context awareness") is not None and find_node_ci(mid, "Set preferred level") is None) # pop 2: Settings -> home. pop2 = False if pop1: and_back() pop2 = _home_restored() and "MainActivity" in get_current_activity() ok = deep and pop1 and pop2 record("nav_backstack_preferred_level_unwinds", ok, "" if ok else "behavior_wrong: BACK did not unwind the preferred-level " "dialog -> Settings -> home one hop at a time", depth=2, jump_kind="reach", expect="BACK #1 restores Settings ('Context awareness'); BACK #2 " "restores home MainActivity ('Off')") @and_test(expects=("nav_back_links_to_home",)) def test_back_from_links_returns_home(): home = _home() deep = and_reach_links_dialog(home) back_ok = deep and and_back() == 0 and _home_restored() record("nav_back_links_to_home", back_ok, "" if back_ok else "behavior_wrong: BACK from the Links dialog did not " "restore the home surface", depth=1, jump_kind="reach", expect="home 'Off' + 'Quick Actions' restored after one BACK from Links") @and_test(expects=("nav_back_about_to_home",)) def test_back_from_about_returns_home(): home = _home() deep = and_reach_about_dialog(home) back_ok = deep and and_back() == 0 and _home_restored() record("nav_back_about_to_home", back_ok, "" if back_ok else "behavior_wrong: BACK from the About dialog did not " "restore the home surface", depth=1, jump_kind="reach", expect="home 'Off' + 'Quick Actions' restored after one BACK from About") TESTS = [ # depth-1 reach test_reach_morse, test_reach_interval, test_reach_interval_vlm, test_reach_links, test_reach_about, test_reach_settings, # depth-2 chains test_reach_icon_credits_depth2, test_reach_preferred_level_depth2, test_reach_settings_links_depth2, # back-stack integrity test_back_from_morse_returns_home, test_back_from_settings_returns_home, test_up_arrow_from_settings_returns_home, test_backstack_icon_credits_unwinds, test_backstack_preferred_level_unwinds, test_back_from_links_returns_home, test_back_from_about_returns_home, ] if __name__ == "__main__": run_suite(TESTS, "navigation")