Datasets:
File size: 24,868 Bytes
966ca88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | #!/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 <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,F401
# ══════════════════════════════════════════════════════════════════════════════
# Entry-point + shared navigation helpers.
# The and_enter_<surface>() / and_reach_<target>() 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")
|