#!/usr/bin/env python3 """NAVIGATION lane — surface REACHABILITY + back-stack integrity for Aegis Authenticator (TOTP/2FA). Sole owner of jump_kind="reach" and of depth>=2 chains. Every jump is proven by and_reach(before, after, target, source): the TARGET surface's discriminating element APPEARED and the SOURCE surface's element DISAPPEARED. No element that was already in the tree is ever asserted as a "reach". Reaching a screen by relaunching is NOT navigation — every chain navigates from within the app via and_enter*/and_reach* calls that back the declared depth. Discriminators were read off the running app (uiautomator dump), because a surface here is the SET of visible element keys, not the Activity: * Main toolbar title .......... 'AegisDev' * Overflow popup items ........ 'Settings', 'About' (Main toolbar not in tree) * PreferencesActivity root .... title 'Settings' + 'Navigate up' + category rows * A settings SUB-screen ....... the 'Settings' title is REPLACED by the section title, so 'Settings' leaving + a section-only child appearing proves the deeper jump * Search active ............... 'Clear query' appears, 'AegisDev' leaves * FAB menu (overlay) .......... 'Enter manually' appears, 'AegisDev' stays * Add / Edit entry ............ title 'Add new entry' / 'Edit entry', 'AegisDev' gone Run: python3 test_android_navigation.py """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,F401 # ══════════════════════════════════════════════════════════════════════════════ # Entry-point + shared navigation helpers. # The and_enter_() / and_reach_() NAMES are what the depth audit # looks for to back a depth>=1 / jump_kind="reach"; the implementations are ours. # ══════════════════════════════════════════════════════════════════════════════ def and_enter_main(): """Clean launch to MainActivity. Clears data so onboarding is deterministic, then skips it entirely by resource-id (portable to the recreation). Chooses rb_none so the vault never locks and every restart lands on Main.""" clear_data() launch_app() wait_for_foreground() settle("launch") nodes = ui() if node_by_id(nodes, "btnNext"): tap_node(node_by_id(ui(), "btnNext")) # Welcome -> Security tap_node(node_by_id(ui(), "rb_none")) # None = no password tap_node(node_by_id(ui(), "btnNext")) # Security -> Setup completed tap_node(node_by_id(ui(), "btnNext")) # Setup completed -> Main return ui() def on_main(nodes=None): """True iff the Main entry list is showing (toolbar title 'AegisDev').""" nodes = ui() if nodes is None else nodes return find_node(nodes, text="AegisDev") is not None def on_settings_root(nodes=None): """True iff the Settings ROOT is showing: the 'Settings' title is present and at least two category rows are visible (a sub-screen shows neither).""" nodes = ui() if nodes is None else nodes return (find_node(nodes, text="Settings") is not None and find_node_ci(nodes, "Behavior") is not None and find_node_ci(nodes, "Security") is not None) def _esc_hide_keyboard(): """Dismiss the soft keyboard WITHOUT navigating. KEYCODE_ESCAPE closes the IME on this build but never pops the surface (BACK sometimes does), which the add-entry form is sensitive to.""" if keyboard_visible(): press_key("KEYCODE_ESCAPE") settle("keyboard") def _fill_field(rid, text): """Focus an EditText by resource-id suffix and type ASCII into it, then drop the keyboard. Re-dumps to verify focus (an unfocused field swallows input).""" node = node_by_id(ui(), rid) if not node: return False tap_node(node) settle("keyboard") fresh = node_by_id(ui(), rid) if fresh and fresh.get("focused") != "true": tap_node(fresh) settle("keyboard") adb_shell("input", "text", text) settle("text") _esc_hide_keyboard() return True def create_entry(name="TestAcc", secret="JBSWY3DPEHPK3PXP"): """Main -> FAB -> Enter manually -> fill name + secret -> SAVE. Returns True when a row (rlCardEntry) is present on Main afterwards. This is SETUP for the navigate-to-a-record tests; the creation itself is the interaction lane's.""" tap_node(node_by_id(ui(), "fab")) settle("tap") enter = node_by_id(ui(), "fab_menu_item_enter") if not enter or not tap_node(enter): return False settle("launch") _fill_field("text_name", name) _fill_field("text_secret", secret) save = node_by_id(ui(), "action_save") if not save or not tap_node(save): return False settle("launch") return node_by_id(ui(), "rlCardEntry") is not None def open_overflow(): """Tap the toolbar 'More options' and return the fresh tree (the overflow popup shows only 'Settings' and 'About'; the Main toolbar leaves the tree).""" mo = find_node(ui(), content_desc="More options") if mo: tap_node(mo) settle("tap") return ui() def and_reach_settings(): """Main -> overflow -> Settings root. The overflow popup already contains a 'Settings' menu item, so the ARRIVAL is proven by the PreferencesActivity's 'Navigate up' affordance appearing and the sibling 'About' menu item leaving. Counts one surface.""" open_overflow() item = find_node_ci(ui(), "Settings") return bool(item) and and_reach_surface(item, "Navigate up", "About") # Each settings section echoes its name in BOTH the root row and the sub-screen # title, so the title is NOT a valid "appeared" key. The reliable arrival proof # is: the root 'Settings' title LEAVES (replaced by the section title) and a # section-ONLY child element APPEARS. These children were read off each screen. _SECTION_CHILD = { "Appearance": "Dynamic colors", "Behavior": "Haptic feedback", "Security": "Encryption", "Audit log": "No reported events", "Import": "Import from file", "Backups": "Automatic backups", "Icon packs": "No icon packs", } def and_reach_settings_section(label, child): """From the Settings ROOT, tap a category row and prove its sub-screen arrived: `child` (a section-only element) APPEARED and the root 'Settings' title LEFT. `label` is matched by prefix so the entity-escaped 'Import & Export' row resolves from 'Import'. Counts one surface.""" trigger = None for n in ui(): if n.get("resource-id", "").endswith("title") and \ n.get("text", "").lower().startswith(label.lower()): trigger = n break if trigger is None: trigger = find_node_ci(ui(), label) if trigger is None: return False return and_reach_surface(trigger, child, "Settings") # ══════════════════════════════════════════════════════════════════════════════ # Top-level destinations (depth 1) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("navigation_open_overflow_menu",)) def test_open_overflow_menu(): and_enter_main() before = and_showing() # Main (no Settings/About yet) mo = find_node(ui(), content_desc="More options") ok = False if mo: tap_node(mo) and_enter("overflow") after = and_showing() # The popup overlays Main; assert both items appeared and Main title left. ok = (and_reach(before, after, "Settings", "AegisDev") and find_node_ci(ui(), "About") is not None) record("navigation_open_overflow_menu", ok, "" if ok else "feature_missing: overflow menu with Settings/About not reachable", depth=1, jump_kind="reach", expect="Overflow popup 'Settings'/'About' appeared; Main 'AegisDev' title gone") @and_test(expects=("navigation_reach_settings", "navigation_reach_settings_vlm")) def test_reach_settings(): and_enter_main() ok = and_reach_settings() record("navigation_reach_settings", ok, "" if ok else "behavior_wrong: Settings root not reached (no 'Navigate up' / 'About' stayed)", depth=1, jump_kind="reach", expect="PreferencesActivity 'Navigate up' appeared; overflow 'About' item gone") vlm_assert("navigation_reach_settings", "Is there a back/up arrow icon at the far top-left of the top app bar " "(to the left of the 'Settings' title)?", RESULTS_DIR, tag="position") @and_test(expects=("navigation_reach_about", "navigation_reach_about_vlm")) def test_reach_about(): and_enter_main() open_overflow() item = find_node_ci(ui(), "About") # From the open overflow: About screen title appears, the 'Settings' menu # item (sibling in the popup) leaves. ok = bool(item) and and_reach_surface(item, "Aegis Authenticator", "Settings") record("navigation_reach_about", ok, "" if ok else "behavior_wrong: About not reached / overflow 'Settings' item stayed", depth=1, jump_kind="reach", expect="AboutActivity 'Aegis Authenticator' appeared; overflow 'Settings' item gone") vlm_assert("navigation_reach_about", "Is there a small app logo icon immediately to the LEFT of the " "'Aegis Authenticator' text, near the top of the screen?", RESULTS_DIR, tag="position") @and_test(expects=("navigation_fab_menu_open", "navigation_fab_menu_open_vlm")) def test_fab_menu_open(): and_enter_main() before = and_showing() fab = node_by_id(ui(), "fab") ok = False if fab: tap_node(fab) and_enter("fab_menu") after = and_showing() # FAB menu is an overlay: 'AegisDev' stays, so assert the target only. ok = (and_reach(before, after, "Enter manually") and find_node_ci(ui(), "Scan QR code") is not None) record("navigation_fab_menu_open", ok, "" if ok else "feature_missing: FAB add-entry menu did not open", depth=1, jump_kind="reach", expect="FAB menu options 'Enter manually' and 'Scan QR code' appeared over Main") vlm_assert("navigation_fab_menu_open", "Are there three labelled rounded option cards ('Scan QR code', " "'Scan image', 'Enter manually') stacked vertically in the " "lower-right area of the screen?", RESULTS_DIR, tag="position") @and_test(expects=("navigation_reach_add_entry", "navigation_reach_add_entry_vlm")) def test_reach_add_entry(): and_enter_main() tap_node(node_by_id(ui(), "fab")) settle("tap") and_enter("fab_menu") enter = node_by_id(ui(), "fab_menu_item_enter") # FAB menu -> Enter manually IS a real surface jump: the form title appears # and Main's 'AegisDev' (still behind the FAB overlay) leaves. ok = bool(enter) and and_reach_surface(enter, "Add new entry", "AegisDev") record("navigation_reach_add_entry", ok, "" if ok else "behavior_wrong: EditEntryActivity 'Add new entry' not reached", depth=2, jump_kind="reach", expect="EditEntryActivity 'Add new entry' shown; Main 'AegisDev' gone") vlm_assert("navigation_reach_add_entry", "Is there a 'SAVE' action button in the top-right area of the top app bar?", RESULTS_DIR, tag="position") @and_test(expects=("navigation_search_open", "navigation_search_open_vlm")) def test_search_open(): and_enter_main() sb = node_by_id(ui(), "search_button") ok = False if sb: before = and_showing() tap_node(sb) and_enter("search") after = and_showing() # In-toolbar SearchView: the 'Clear query' button appears, 'AegisDev' goes. ok = and_reach(before, after, "Clear query", "AegisDev") record("navigation_search_open", ok, "" if ok else "behavior_wrong: in-toolbar search field did not appear", depth=1, jump_kind="reach", expect="SearchView 'Clear query' affordance appeared; toolbar 'AegisDev' gone") vlm_assert("navigation_search_open", "Does the top app bar now contain a wide text input field that spans " "most of the bar's width (a search box)?", RESULTS_DIR, tag="layout") # ══════════════════════════════════════════════════════════════════════════════ # Depth-2 chains: Main -> Settings -> sub-screen (navigation lane owns depth>=2) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("navigation_reach_appearance", "navigation_reach_appearance_vlm")) def test_reach_appearance(): and_enter_main() deep = and_reach_settings() # hop 1 (depth 1) ok = deep and and_reach_settings_section("Appearance", _SECTION_CHILD["Appearance"]) record("navigation_reach_appearance", ok, # hop 2 (depth 2) "" if ok else "behavior_wrong: Settings->Appearance sub-screen not reached", depth=2, jump_kind="reach", expect="Appearance sub-screen 'Dynamic colors' appeared; Settings root title gone") vlm_assert("navigation_reach_appearance", "Is there a vertical list of settings rows, where each row has a " "label with a smaller grey description line beneath it?", RESULTS_DIR, tag="layout") @and_test(expects=("navigation_reach_behavior",)) def test_reach_behavior(): and_enter_main() deep = and_reach_settings() ok = deep and and_reach_settings_section("Behavior", _SECTION_CHILD["Behavior"]) record("navigation_reach_behavior", ok, "" if ok else "behavior_wrong: Settings->Behavior sub-screen not reached", depth=2, jump_kind="reach", expect="Behavior sub-screen 'Haptic feedback' appeared; Settings root title gone") @and_test(expects=("navigation_reach_security",)) def test_reach_security(): and_enter_main() deep = and_reach_settings() ok = deep and and_reach_settings_section("Security", _SECTION_CHILD["Security"]) record("navigation_reach_security", ok, "" if ok else "behavior_wrong: Settings->Security sub-screen not reached", depth=2, jump_kind="reach", expect="Security sub-screen 'Encryption' appeared; Settings root title gone") @and_test(expects=("navigation_reach_audit_log",)) def test_reach_audit_log(): and_enter_main() deep = and_reach_settings() ok = deep and and_reach_settings_section("Audit log", _SECTION_CHILD["Audit log"]) record("navigation_reach_audit_log", ok, "" if ok else "behavior_wrong: Settings->Audit log sub-screen not reached", depth=2, jump_kind="reach", expect="Audit log sub-screen 'No reported events' appeared; Settings root title gone") @and_test(expects=("navigation_reach_import_export",)) def test_reach_import_export(): and_enter_main() deep = and_reach_settings() # Dump text is the entity-escaped 'Import & Export'; match the row by the # 'Import' prefix and assert the section-only 'Import from file' arrived. ok = deep and and_reach_settings_section("Import", _SECTION_CHILD["Import"]) record("navigation_reach_import_export", ok, "" if ok else "behavior_wrong: Settings->Import & Export sub-screen not reached", depth=2, jump_kind="reach", expect="Import & Export sub-screen 'Import from file' appeared; Settings root title gone") @and_test(expects=("navigation_reach_backups",)) def test_reach_backups(): and_enter_main() deep = and_reach_settings() ok = deep and and_reach_settings_section("Backups", _SECTION_CHILD["Backups"]) record("navigation_reach_backups", ok, "" if ok else "behavior_wrong: Settings->Backups sub-screen not reached", depth=2, jump_kind="reach", expect="Backups sub-screen 'Automatic backups' appeared; Settings root title gone") @and_test(expects=("navigation_reach_icon_packs",)) def test_reach_icon_packs(): and_enter_main() deep = and_reach_settings() ok = deep and and_reach_settings_section("Icon packs", _SECTION_CHILD["Icon packs"]) record("navigation_reach_icon_packs", ok, "" if ok else "behavior_wrong: Settings->Icon packs sub-screen not reached", depth=2, jump_kind="reach", expect="Icon packs sub-screen 'No icon packs' appeared; Settings root title gone") # ══════════════════════════════════════════════════════════════════════════════ # Back-stack integrity — BACK unwinds hop by hop, deepest surface back to home # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("navigation_settings_back_to_main",)) def test_settings_back_to_main(): and_enter_main() deep = and_reach_settings() # depth 1 home = False if deep: before = and_showing() # Settings root and_back() # pop Settings after = and_showing() home = and_reach(before, after, "AegisDev", "Settings") and on_main() record("navigation_settings_back_to_main", deep and home, "" if deep and home else "behavior_wrong: BACK from Settings did not restore Main", depth=1, jump_kind="reach", expect="Main 'AegisDev' restored and 'Settings' title gone after one BACK") @and_test(expects=("navigation_appearance_back_to_settings",)) def test_appearance_back_to_settings(): """Depth-2 chain, then ONE BACK must land on the Settings ROOT (depth 1), NOT jump straight to Main — proves the intermediate surface is on the back stack.""" and_enter_main() deep = (and_reach_settings() and and_reach_settings_section("Appearance", _SECTION_CHILD["Appearance"])) to_settings = False if deep: before = and_showing() # Appearance sub-screen and_back() # pop Appearance -> Settings root after = and_showing() # The 'Behavior' root row reappears; the section-only 'Dynamic colors' # leaves; and we are provably NOT on Main. to_settings = (and_reach(before, after, "Behavior", "Dynamic colors") and on_settings_root() and not on_main()) record("navigation_appearance_back_to_settings", deep and to_settings, "" if deep and to_settings else "behavior_wrong: BACK from Appearance did not return to the Settings root", depth=2, jump_kind="reach", expect="Settings root ('Behavior' row) restored after one BACK; 'Dynamic colors' gone; not Main") @and_test(expects=("navigation_backstack_2hop_unwind",)) def test_backstack_2hop_unwind(): """Main -> Settings -> Behavior, then two BACKs unwind it hop by hop: Behavior -> Settings root, then Settings root -> Main.""" and_enter_main() deep = (and_reach_settings() and and_reach_settings_section("Behavior", _SECTION_CHILD["Behavior"])) step1 = step2 = False if deep: b1 = and_showing() # Behavior sub-screen and_back() # Behavior -> Settings root a1 = and_showing() # Settings root re-shows the 'Appearance' row; 'Haptic feedback' leaves. step1 = (and_reach(b1, a1, "Appearance", "Haptic feedback") and on_settings_root() and not on_main()) b2 = and_showing() # Settings root and_back() # Settings root -> Main a2 = and_showing() step2 = and_reach(b2, a2, "AegisDev", "Settings") and on_main() ok = deep and step1 and step2 record("navigation_backstack_2hop_unwind", ok, "" if ok else "behavior_wrong: two BACKs did not unwind Behavior->Settings->Main", depth=2, jump_kind="reach", expect="BACK #1 restores Settings root ('Appearance' row); BACK #2 restores Main 'AegisDev'") # ══════════════════════════════════════════════════════════════════════════════ # Navigate to a record created in setup: entry -> (long-press) edit -> BACK # ══════════════════════════════════════════════════════════════════════════════ def and_reach_edit_entry(): """From Main with a row present: long-press the row -> action mode -> action_edit -> EditEntryActivity 'Edit entry'. The Main title 'AegisDev' persists behind the contextual bar, so it is the disappearing source once the editor opens. Counts one surface.""" row = node_by_id(ui(), "rlCardEntry") if not row: return False long_press(row) settle("tap") # let the action mode animate in edit = node_by_id(ui(), "action_edit") if not edit: return False return and_reach_surface(edit, "Edit entry", "AegisDev") @and_test(expects=("navigation_reach_edit_entry",)) def test_reach_edit_entry(): and_enter_main() made = create_entry() # SETUP (interaction lane owns it) ok = made and and_reach_edit_entry() record("navigation_reach_edit_entry", ok, "" if ok else ("setup_failed: could not create an entry to edit" if not made else "behavior_wrong: long-press -> Edit did not reach 'Edit entry'"), depth=1, jump_kind="reach", expect="EditEntryActivity 'Edit entry' shown; Main 'AegisDev' gone") @and_test(expects=("navigation_edit_entry_back_to_main",)) def test_edit_entry_back_to_main(): and_enter_main() made = create_entry() reached = made and and_reach_edit_entry() # depth 1 (Edit entry) home = False if reached: before = and_showing() and_back() # pop Edit entry -> Main after = and_showing() home = and_reach(before, after, "AegisDev", "Edit entry") and on_main() ok = reached and home record("navigation_edit_entry_back_to_main", ok, "" if ok else ("setup_failed: could not reach the entry editor" if not reached else "behavior_wrong: BACK from 'Edit entry' did not restore Main"), depth=1, jump_kind="reach", expect="Main 'AegisDev' restored and 'Edit entry' gone after one BACK") TESTS = [ test_open_overflow_menu, test_reach_settings, test_reach_about, test_fab_menu_open, test_reach_add_entry, test_search_open, test_reach_appearance, test_reach_behavior, test_reach_security, test_reach_audit_log, test_reach_import_export, test_reach_backups, test_reach_icon_packs, test_settings_back_to_main, test_appearance_back_to_settings, test_backstack_2hop_unwind, test_reach_edit_entry, test_edit_entry_back_to_main, ] if __name__ == "__main__": if not device_online(): print("device offline — aborting") sys.exit(2) run_suite(TESTS, "navigation")