Datasets:
Download android/florisboard-florisboard/tests/test_android_navigation.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 21.7 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/florisboard-florisboard/tests/test_android_navigation.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/florisboard-florisboard/tests/test_android_navigation.py
-
curl -L -o test_android_navigation.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/florisboard-florisboard/tests/test_android_navigation.py
21.7 kB
| #!/usr/bin/env python3 | |
| """NAVIGATION lane — FlorisBoard. | |
| Owns surface REACHABILITY and back-stack integrity, and NOTHING else: | |
| * Home -> each of the 11 settings sub-screens as a proven `reach` | |
| (the destination's unique row APPEARED and the home title DISAPPEARED). | |
| * BACK from a sub-screen restores home (source reappears, sub-screen row gone). | |
| * DEPTH-2 chains proven hop-by-hop (list -> detail-style manager / editor), | |
| with a BACK unwind that pops one surface at a time back to home. This lane is | |
| the SOLE owner of jump_kind="reach" and of depth>=2 chains. | |
| * A ListPreference dialog opens as a real surface (options appear, the row | |
| behind it is covered) and Cancel returns to the screen. | |
| * The keyboard preview end-state (an EditText/keyboard appears) after tapping | |
| "Try out your setup" — a same-activity transition, declared honestly. | |
| Every jump is verified with and_reach / and_reach_surface: the TARGET surface's | |
| element newly appeared AND the SOURCE surface's element vanished. A flat tree that | |
| merely contains an element can never fake that. No content-value / widget-state / | |
| shape assertions live here — those are other lanes. | |
| The Compose tree is FLAT with empty resource-ids, so everything is matched by | |
| class + visible text/content-desc. Section labels containing "&" dump as the raw | |
| entity ("Languages & Layouts"), so they are matched by an ampersand-free | |
| prefix. Titles like "Keyboard"/"Theme" ALSO appear as rows on home, so every | |
| `reach` target is a UNIQUE inner row of the destination, never the title. | |
| """ | |
| import os | |
| import sys | |
| os.environ.setdefault("ADB_PATH", "/opt/android/platform-tools/adb") | |
| # DEVICE_SERIAL is supplied by the harness env; the kit already defaults it, so | |
| # no serial literal is written here (keeps the suite portable / lint-clean). | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403,E402 | |
| # ── Local matchers (kit has no ampersand/startswith helper; recon.md snippet) ── | |
| def find_node_startswith(nodes, prefix): | |
| """First node whose visible text starts with `prefix` (ampersand-free, so | |
| 'Languages' matches 'Languages & Layouts' which dumps as 'Languages &').""" | |
| p = prefix.lower() | |
| for n in nodes: | |
| if n.get("text", "").lower().startswith(p): | |
| return n | |
| return None | |
| HOME = "Welcome to FlorisBoard" # home-only title; gone on every sub-screen | |
| # section prefix (home row + destination title) -> a UNIQUE row that exists ONLY | |
| # on that sub-screen (verified on the running original). Used as the `reach` | |
| # target: it is absent from home, so it can only APPEAR by navigating. | |
| SECTION_ANCHOR = [ | |
| ("Languages", "Manage installed language packs"), | |
| ("Theme", "Day theme"), | |
| ("Keyboard", "Number row"), | |
| ("Smartbar", "Enable Smartbar"), | |
| ("Typing", "Display suggestions"), | |
| ("Gestures", "General gestures"), | |
| ("Clipboard", "Use internal clipboard"), | |
| ("Emojis", "Preferred emoji skin tone"), | |
| ("Addons", "Theme extensions"), | |
| ("Other", "Physical keyboard"), | |
| ("About", "Third-party licenses"), | |
| ] | |
| # ── Depth-backing helpers. Named and_reach_* / and_enter_* so and_audit_depth | |
| # accepts the depth>=1 / reach they produce. Each PROVES the hop (target | |
| # appeared, source vanished) and the kit's and_reach_surface bumps the surface | |
| # counter for us. ── | |
| def and_reach_section(section, anchor): | |
| """HOME -> a named settings sub-screen. Proven reach: `anchor` (a sub-screen | |
| -only row) appears and the home title disappears.""" | |
| nodes = ui() | |
| row = find_node_startswith(nodes, section) | |
| if not row: | |
| return False | |
| return and_reach_surface(row, target=anchor, source=HOME) | |
| def and_reach_licenses(): | |
| """HOME -> About -> Third-party licenses (depth 2), each hop proven.""" | |
| hop1 = and_reach_section("About", "Changelog") # About-only row | |
| if not hop1: | |
| return False | |
| n = find_node_ci(ui(), "Third-party licenses") | |
| # hop2: a library name appears; the About-only "Changelog" row is gone. | |
| return bool(n) and and_reach_surface(n, target="AboutLibraries", source="Changelog") | |
| def and_reach_theme_ext_from_addons(): | |
| """HOME -> Addons -> Theme extensions manager (depth 2), each hop proven.""" | |
| hop1 = and_reach_section("Addons", "Keyboard extensions") # Addons-only row | |
| if not hop1: | |
| return False | |
| n = find_node_ci(ui(), "Theme extensions") | |
| # hop2: a bundled theme name appears; the Addons-only "Keyboard extensions" gone. | |
| return bool(n) and and_reach_surface( | |
| n, target="FlorisBoard default themes", source="Keyboard extensions") | |
| def and_reach_theme_ext_from_theme(): | |
| """HOME -> Theme -> Go to Theme extensions manager (depth 2), each hop proven.""" | |
| hop1 = and_reach_section("Theme", "Day theme") # Theme-only row | |
| if not hop1: | |
| return False | |
| n = find_node_ci(ui(), "Go to Theme extensions") | |
| # hop2: a bundled theme name appears; the Theme-only "Day theme" row is gone. | |
| return bool(n) and and_reach_surface( | |
| n, target="FlorisBoard default themes", source="Day theme") | |
| def and_reach_subtype_editor(): | |
| """HOME -> Languages -> Add subtype editor (depth 2), each hop proven. The | |
| Add-subtype trigger is an icon-only View located by content-desc.""" | |
| hop1 = and_reach_section("Languages", "Manage installed language packs") | |
| if not hop1: | |
| return False | |
| add = find_node(ui(), content_desc="Add subtype") | |
| # hop2: the preset list header appears; the Languages-only manage-packs row gone. | |
| return bool(add) and and_reach_surface( | |
| add, target="Subtype presets", source="Manage installed language packs") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 1) Home -> each of the 11 sections (depth 1, jump_kind="reach") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _make_section_test(section, anchor): | |
| name = f"navigation_reach_{section.lower()}" | |
| def _test(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_section(section, anchor) | |
| record(name, ok, | |
| "" if ok else f"feature_missing: could not reach the {section} " | |
| f"sub-screen (row {anchor!r} did not appear / home title stayed)", | |
| depth=1, jump_kind="reach", | |
| expect=f"{section} sub-screen: row {anchor!r} appeared, " | |
| f"home title {HOME!r} no longer showing") | |
| _test.__name__ = f"test_{name}" | |
| return _test | |
| test_reach_languages = _make_section_test(*SECTION_ANCHOR[0]) | |
| test_reach_theme = _make_section_test(*SECTION_ANCHOR[1]) | |
| test_reach_keyboard = _make_section_test(*SECTION_ANCHOR[2]) | |
| test_reach_smartbar = _make_section_test(*SECTION_ANCHOR[3]) | |
| test_reach_typing = _make_section_test(*SECTION_ANCHOR[4]) | |
| test_reach_gestures = _make_section_test(*SECTION_ANCHOR[5]) | |
| test_reach_clipboard = _make_section_test(*SECTION_ANCHOR[6]) | |
| test_reach_emojis = _make_section_test(*SECTION_ANCHOR[7]) | |
| test_reach_addons = _make_section_test(*SECTION_ANCHOR[8]) | |
| test_reach_other = _make_section_test(*SECTION_ANCHOR[9]) | |
| test_reach_about = _make_section_test(*SECTION_ANCHOR[10]) | |
| # ── one section reach also gets a VLM: a sub-screen shows an up/back arrow ────── | |
| def test_reach_keyboard_toolbar(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_section("Keyboard", "Number row") | |
| record("navigation_reach_keyboard_toolbar", ok, | |
| "" if ok else "feature_missing: could not reach the Keyboard sub-screen", | |
| depth=1, jump_kind="reach", | |
| expect="Keyboard sub-screen reached (row 'Number row' appeared, home gone)") | |
| vlm_assert("navigation_reach_keyboard_toolbar", | |
| "Is there a left-pointing back/up arrow icon at the top-left of the " | |
| "screen, to the left of a screen title?", | |
| RESULTS_DIR, tag="position") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 2) BACK from a sub-screen restores home (proven: home reappears, sub-row gone) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _make_back_test(section, anchor): | |
| name = f"navigation_back_{section.lower()}_to_home" | |
| def _test(): | |
| restart_app() | |
| wait_for_foreground() | |
| deep = and_reach_section(section, anchor) # depth 1 | |
| before = and_showing() | |
| and_back() # pop one surface | |
| after = and_showing() | |
| home_back = and_reach(before, after, target=HOME, source=anchor) | |
| ok = deep and home_back | |
| record(name, ok, | |
| "" if ok else f"behavior_wrong: BACK from {section} did not restore " | |
| f"home (home title {HOME!r} absent or row {anchor!r} still showing)", | |
| depth=1, jump_kind="reach", | |
| expect=f"after BACK from {section}: home title {HOME!r} restored, " | |
| f"row {anchor!r} gone") | |
| _test.__name__ = f"test_{name}" | |
| return _test | |
| test_back_theme = _make_back_test("Theme", "Day theme") | |
| test_back_keyboard = _make_back_test("Keyboard", "Number row") | |
| test_back_about = _make_back_test("About", "Third-party licenses") | |
| # a back-to-home case that also carries a VLM end-state check | |
| def test_back_typing_to_home(): | |
| restart_app() | |
| wait_for_foreground() | |
| deep = and_reach_section("Typing", "Display suggestions") | |
| before = and_showing() | |
| and_back() | |
| after = and_showing() | |
| home_back = and_reach(before, after, target=HOME, source="Display suggestions") | |
| ok = deep and home_back | |
| record("navigation_back_typing_to_home", ok, | |
| "" if ok else "behavior_wrong: BACK from Typing did not restore the home list", | |
| depth=1, jump_kind="reach", | |
| expect="after BACK from Typing: home title 'Welcome to FlorisBoard' restored") | |
| vlm_assert("navigation_back_typing_to_home", | |
| "Is this a settings home screen showing a vertical list of section " | |
| "rows such as Theme, Keyboard, Smartbar and Clipboard?", | |
| RESULTS_DIR, tag="layout") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 3) DEPTH-2 chains (this lane OWNS depth>=2) — each hop proven | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_depth2_about_licenses(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_licenses() # home -> About -> Third-party licenses | |
| record("navigation_depth2_about_licenses", ok, | |
| "" if ok else "feature_missing: About -> Third-party licenses chain did " | |
| "not reach the library list (a library name never appeared)", | |
| depth=2, jump_kind="reach", | |
| expect="Third-party licenses reached at depth 2: 'AboutLibraries' library " | |
| "entry appeared, About-only 'Changelog' row gone") | |
| vlm_assert("navigation_depth2_about_licenses", | |
| "Is this a scrollable list of software library entries, each with a " | |
| "name and a licence label like 'Apache License 2.0'?", | |
| RESULTS_DIR, tag="layout") | |
| def test_depth2_addons_theme_ext(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_theme_ext_from_addons() | |
| record("navigation_depth2_addons_theme_ext", ok, | |
| "" if ok else "feature_missing: Addons -> Theme extensions chain did not " | |
| "reach the theme-extension manager", | |
| depth=2, jump_kind="reach", | |
| expect="Theme extension manager reached at depth 2: 'FlorisBoard default " | |
| "themes' appeared, Addons-only 'Keyboard extensions' row gone") | |
| def test_depth2_theme_theme_ext(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_theme_ext_from_theme() | |
| record("navigation_depth2_theme_theme_ext", ok, | |
| "" if ok else "feature_missing: Theme -> Go to Theme extensions chain did " | |
| "not reach the theme-extension manager", | |
| depth=2, jump_kind="reach", | |
| expect="Theme extension manager reached at depth 2: 'FlorisBoard default " | |
| "themes' appeared, Theme-only 'Day theme' row gone") | |
| def test_depth2_add_subtype(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_subtype_editor() | |
| record("navigation_depth2_add_subtype", ok, | |
| "" if ok else "feature_missing: Languages -> Add subtype chain did not " | |
| "reach the subtype editor (preset list header never appeared)", | |
| depth=2, jump_kind="reach", | |
| expect="Subtype editor reached at depth 2: 'Subtype presets' header " | |
| "appeared, Languages-only 'Manage installed language packs' gone") | |
| # ── depth-2 BACK unwind: from the deepest surface, BACK pops hop-by-hop to home ─ | |
| def test_depth2_backstack_unwind(): | |
| restart_app() | |
| wait_for_foreground() | |
| deep = and_reach_licenses() # depth 2 (About -> licenses) | |
| # pop 1: licenses -> About (About-only row returns, library name gone) | |
| b1 = and_showing() | |
| and_back() | |
| a1 = and_showing() | |
| pop1 = and_reach(b1, a1, target="Changelog", source="AboutLibraries") | |
| # pop 2: About -> home (home title returns, About-only row gone) | |
| b2 = and_showing() | |
| and_back() | |
| a2 = and_showing() | |
| pop2 = and_reach(b2, a2, target=HOME, source="Changelog") | |
| ok = deep and pop1 and pop2 | |
| record("navigation_depth2_backstack_unwind", ok, | |
| "" if ok else "behavior_wrong: BACK did not unwind the About->licenses " | |
| "stack one surface at a time back to home", | |
| depth=2, jump_kind="reach", | |
| expect="two BACKs unwind depth 2->1->0: licenses->About (Changelog back), " | |
| "then About->home (Welcome back)") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 4) ListPreference dialog is a real surface; Cancel returns to the screen | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def and_reach_utility_dialog(): | |
| """Keyboard screen -> open the 'Utility key action' ListPreference dialog. | |
| Proven reach: a dialog-only option appears and a Keyboard-screen row is | |
| covered.""" | |
| if not and_reach_section("Keyboard", "Number row"): | |
| return False | |
| trg = find_node_ci(ui(), "Utility key action") | |
| # target 'Switch keyboard app' exists only in the dialog; 'Number row' (a | |
| # Keyboard-screen row) is covered when the modal opens. | |
| return bool(trg) and and_reach_surface( | |
| trg, target="Switch keyboard app", source="Number row") | |
| def test_reach_utility_dialog(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok = and_reach_utility_dialog() # depth 2: home -> Keyboard -> dialog | |
| record("navigation_reach_utility_dialog", ok, | |
| "" if ok else "feature_missing: 'Utility key action' did not open a " | |
| "ListPreference dialog (option 'Switch keyboard app' never appeared)", | |
| depth=2, jump_kind="reach", | |
| expect="Utility-key-action dialog reached: option 'Switch keyboard app' " | |
| "appeared, Keyboard row 'Number row' covered") | |
| vlm_assert("navigation_reach_utility_dialog", | |
| "Is a modal dialog box shown on top of the screen with a list of " | |
| "radio-button options and Cancel and OK buttons at the bottom?", | |
| RESULTS_DIR, tag="layout") | |
| def test_dialog_cancel_returns(): | |
| restart_app() | |
| wait_for_foreground() | |
| opened = and_reach_utility_dialog() | |
| cancel = find_node_ci(ui(), "Cancel") | |
| before = and_showing() | |
| tapped = tap_node(cancel) if cancel else False | |
| settle("tap") | |
| after = and_showing() | |
| # dismiss proven: the Keyboard row returns, the dialog-only option is gone. | |
| returned = and_reach(before, after, target="Number row", source="Switch keyboard app") | |
| and_back() # pop the counter for the Keyboard surface we entered | |
| ok = opened and tapped and returned | |
| record("navigation_dialog_cancel_returns", ok, | |
| "" if ok else "behavior_wrong: Cancel did not dismiss the dialog back to " | |
| "the Keyboard screen (row 'Number row' absent or option still showing)", | |
| depth=1, jump_kind="reach", | |
| expect="after Cancel: Keyboard row 'Number row' restored, dialog option " | |
| "'Switch keyboard app' gone") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 5) Keyboard-preview end-state (same-activity transition, declared honestly) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def and_enter_keyboard_preview(): | |
| """Tap the bottom 'Try out your setup' bar; FlorisBoard's own keyboard opens | |
| in a separate IME window and a Compose EditText appears in the tree. Counts | |
| one surface. Same-activity, so the jump is declared 'transition' (a keyboard | |
| became visible), not a clean 'reach'.""" | |
| n = find_node_ci(ui(), "Try out your setup") | |
| if not n: | |
| return False, set(), set() | |
| before = and_showing() | |
| if not tap_node(n): | |
| return False, before, before | |
| settle("launch") | |
| settle("launch") # IME window animates in | |
| after = and_showing() | |
| has_editor = any(x.get("class", "").endswith("EditText") for x in ui()) | |
| ok = has_editor and keyboard_visible() and surface_changed(before, after) | |
| if ok: | |
| and_enter("keyboard-preview") | |
| return ok, before, after | |
| def test_open_keyboard_preview(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok, _before, _after = and_enter_keyboard_preview() | |
| record("navigation_open_keyboard_preview", ok, | |
| "" if ok else "feature_missing: tapping 'Try out your setup' did not bring " | |
| "up the keyboard preview (no EditText / keyboard window)", | |
| depth=1, jump_kind="transition", | |
| expect="keyboard preview end-state: a text field is focused and " | |
| "FlorisBoard's keyboard window is visible") | |
| vlm_assert("navigation_open_keyboard_preview", | |
| "Is an on-screen keyboard with rows of letter keys shown in the " | |
| "bottom portion of the screen?", | |
| RESULTS_DIR, tag="layout") | |
| TESTS = [ | |
| # 11 top-level section reaches (depth 1) | |
| test_reach_languages, test_reach_theme, test_reach_keyboard, test_reach_smartbar, | |
| test_reach_typing, test_reach_gestures, test_reach_clipboard, test_reach_emojis, | |
| test_reach_addons, test_reach_other, test_reach_about, | |
| test_reach_keyboard_toolbar, # + VLM: back arrow top-left | |
| # back-to-home | |
| test_back_theme, test_back_keyboard, test_back_about, | |
| test_back_typing_to_home, # + VLM: home list restored | |
| # depth-2 chains | |
| test_depth2_about_licenses, # + VLM: licenses list | |
| test_depth2_addons_theme_ext, | |
| test_depth2_theme_theme_ext, | |
| test_depth2_add_subtype, | |
| test_depth2_backstack_unwind, | |
| # dialog surface | |
| test_reach_utility_dialog, # + VLM: modal dialog | |
| test_dialog_cancel_returns, | |
| # keyboard preview end-state | |
| test_open_keyboard_preview, # + VLM: keyboard visible | |
| ] | |
| if __name__ == "__main__": | |
| run_suite(TESTS, "navigation") | |