#!/usr/bin/env python3 """TEXT lane — FlorisBoard (Jetpack Compose keyboard/IME settings + keyboard preview). This lane OWNS exact-string equality: CONTENT strings an action PRODUCES — the top-bar title that appears after navigating into a section, switch/preference SUMMARIES, computed summary values, dialog option labels, warning text, and one functional content-desc. Opaque CANVAS text (keyboard key glyphs, symbol glyphs, smartbar word suggestions) is the only thing routed to the VLM, because those never reach the view tree. The tree is FLAT and resource-id is almost always empty (Compose + JetPref), so matching is by class + visible text/content-desc. Section labels containing "&" appear in the XML as `&` ("Addons & Extensions"), so ampersand-bearing targets are matched by an ampersand-free prefix / substring. Run: python3 test_android_text.py """ import os import sys os.environ.setdefault("ADB_PATH", "/opt/android/platform-tools/adb") sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # ── local matchers the kit has no equivalent of (per recon.md) ────────────────── def find_node_startswith(nodes, prefix): """First node whose visible text (case-insensitive) starts with `prefix`. Used for ampersand-bearing labels ("Addons & Extensions" -> "Addons").""" p = prefix.strip().lower() for n in nodes: if n.get("text", "").strip().lower().startswith(p): return n return None def all_text(nodes): """Every visible text string joined — the haystack for a contains-match.""" return " | ".join(n.get("text", "") for n in nodes if n.get("text")) def all_text_and_desc(nodes): """text + content-desc joined — for content-desc-only controls.""" parts = [] for n in nodes: if n.get("text"): parts.append(n["text"]) if n.get("content-desc"): parts.append(n["content-desc"]) return " | ".join(parts) def top_bar_title(nodes, title): """The section title lives at the TOP of the screen (small y). Return the matching node only if it is in the top ~18% band, so a home-row entry with the same words (which sits far lower) can never satisfy a title assertion.""" s = get_screen_info() band = s["height"] * 0.18 t = title.strip().lower() for n in nodes: if n.get("text", "").strip().lower() != t: continue b = n.get("_bounds") if b and b[1] <= band: return n return None def open_section(section_label, target_title, source="Welcome to FlorisBoard"): """Home -> tap a section row -> PROVE the jump (target title appeared, home banner vanished). Counts one surface via and_reach_surface. Returns (ok, nodes) where nodes is a fresh dump on the section screen. `section_label` is matched exactly first, then by ampersand-free prefix, so "Addons" reaches "Addons & Extensions".""" row = find_node_ci(ui(), section_label) or find_node_startswith(ui(), section_label) if not row: return False, [] ok = and_reach_surface(row, target=target_title, source=source) return ok, ui() # ══════════════════════════════════════════════════════════════════════════════ # 1) SECTION TITLES as content after navigating (top-bar title band) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_title_keyboard",)) def test_title_keyboard(): restart_app() wait_for_foreground() absent = top_bar_title(ui(), "Keyboard") is None ok_nav, nodes = open_section("Keyboard", "Keyboard") title = top_bar_title(nodes, "Keyboard") ok = absent and ok_nav and title is not None msg = "" if not ok: if not ok_nav: msg = "setup_failed: could not navigate Home -> Keyboard" elif title is None: msg = "behavior_wrong: top-bar title 'Keyboard' not present after navigating" else: msg = "behavior_wrong: 'Keyboard' title already present on Home (dead shell)" record("text_title_keyboard", ok, msg, depth=1, jump_kind="transition", expect="top-bar title == 'Keyboard'") @and_test(expects=("text_title_clipboard",)) def test_title_clipboard(): restart_app() wait_for_foreground() absent = top_bar_title(ui(), "Clipboard") is None ok_nav, nodes = open_section("Clipboard", "Clipboard") title = top_bar_title(nodes, "Clipboard") ok = absent and ok_nav and title is not None record("text_title_clipboard", ok, "" if ok else "behavior_wrong: top-bar title 'Clipboard' did not appear after navigating", depth=1, jump_kind="transition", expect="top-bar title == 'Clipboard'") @and_test(expects=("text_title_emojis",)) def test_title_emojis(): restart_app() wait_for_foreground() absent = top_bar_title(ui(), "Emojis") is None ok_nav, nodes = open_section("Emojis", "Emojis") title = top_bar_title(nodes, "Emojis") ok = absent and ok_nav and title is not None record("text_title_emojis", ok, "" if ok else "behavior_wrong: top-bar title 'Emojis' did not appear after navigating", depth=1, jump_kind="transition", expect="top-bar title == 'Emojis'") @and_test(expects=("text_title_about",)) def test_title_about(): restart_app() wait_for_foreground() absent = top_bar_title(ui(), "About") is None ok_nav, nodes = open_section("About", "About") title = top_bar_title(nodes, "About") ok = absent and ok_nav and title is not None record("text_title_about", ok, "" if ok else "behavior_wrong: top-bar title 'About' did not appear after navigating", depth=1, jump_kind="transition", expect="top-bar title == 'About'") # ══════════════════════════════════════════════════════════════════════════════ # 2) SWITCH / PREFERENCE SUMMARIES (exact, distinctive strings) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_summary_number_row",)) def test_summary_number_row(): restart_app() wait_for_foreground() want = "Show a number row above the character layout" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Keyboard", "Keyboard") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_number_row", ok, "" if ok else "behavior_wrong: 'Number row' summary text not found on Keyboard screen", depth=1, jump_kind="transition", expect=want) @and_test(expects=("text_summary_utility_key",)) def test_summary_utility_key(): restart_app() wait_for_foreground() want = "Shows a configurable utility key next to space bar" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Keyboard", "Keyboard") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_utility_key", ok, "" if ok else "behavior_wrong: 'Show utility key' summary not found on Keyboard screen", depth=1, jump_kind="transition", expect=want) @and_test(expects=("text_summary_display_suggestions",)) def test_summary_display_suggestions(): restart_app() wait_for_foreground() want = "Provides suggestions while you type" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Typing", "Typing") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_display_suggestions", ok, "" if ok else "behavior_wrong: 'Display suggestions' summary not found on Typing screen", depth=1, jump_kind="transition", expect=want) @and_test(expects=("text_summary_offensive_words",)) def test_summary_offensive_words(): restart_app() wait_for_foreground() want = "Prevents possibly offensive words from being suggested while you type" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Typing", "Typing") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_offensive_words", ok, "" if ok else "behavior_wrong: 'Block possibly offensive words' summary not found on Typing screen", depth=1, jump_kind="transition", expect=want) @and_test(expects=("text_summary_smartbar",)) def test_summary_smartbar(): restart_app() wait_for_foreground() want = "Will show on top of the keyboard" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Smartbar", "Smartbar") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_smartbar", ok, "" if ok else "behavior_wrong: 'Enable Smartbar' summary not found on Smartbar screen", depth=1, jump_kind="transition", expect=want) @and_test(expects=("text_summary_internal_clipboard",)) def test_summary_internal_clipboard(): restart_app() wait_for_foreground() want = "Use an internal clipboard instead of the system clipboard" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Clipboard", "Clipboard") present = find_node_ci(nodes, want) is not None ok = absent and ok_nav and present record("text_summary_internal_clipboard", ok, "" if ok else "behavior_wrong: 'Use internal clipboard' summary not found on Clipboard screen", depth=1, jump_kind="transition", expect=want) # ══════════════════════════════════════════════════════════════════════════════ # 3) COMPUTED SUMMARY values (ListPreference / slider summary lines) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_summary_font_size",)) def test_summary_font_size(): """Keyboard 'Font size multiplier' summary reads '100% / 100%'. Its label may sit below the fold, so scroll it into view before reading.""" restart_app() wait_for_foreground() want = "100% / 100%" ok_nav, _ = open_section("Keyboard", "Keyboard") n = scroll_into_view("Font size multiplier") if ok_nav else None nodes = ui() present = want in all_text(nodes) ok = ok_nav and (n is not None) and present msg = "" if not ok: msg = ("setup_failed: could not reach 'Font size multiplier' on Keyboard screen" if not (ok_nav and n) else "behavior_wrong: 'Font size multiplier' summary is not '100% / 100%'") record("text_summary_font_size", ok, msg, depth=1, jump_kind="transition", expect="Font size multiplier summary == '100% / 100%'") @and_test(expects=("text_summary_grid_columns",)) def test_summary_grid_columns(): """Clipboard 'Number of grid columns' summary reads 'Auto / Auto'.""" restart_app() wait_for_foreground() want = "Auto / Auto" ok_nav, _ = open_section("Clipboard", "Clipboard") n = scroll_into_view("Number of grid columns") if ok_nav else None nodes = ui() present = want in all_text(nodes) label = find_node_ci(nodes, "Number of grid columns") is not None ok = ok_nav and label and present record("text_summary_grid_columns", ok, "" if ok else "behavior_wrong: 'Number of grid columns' summary is not 'Auto / Auto'", depth=1, jump_kind="transition", expect="grid columns summary == 'Auto / Auto'") @and_test(expects=("text_summary_emoji_max_items",)) def test_summary_emoji_max_items(): """Emojis 'Maximum items to keep' summary reads 'Unlimited / 90 items'.""" restart_app() wait_for_foreground() want = "Unlimited / 90 items" ok_nav, _ = open_section("Emojis", "Emojis") n = scroll_into_view("Maximum items to keep") if ok_nav else None nodes = ui() present = want in all_text(nodes) ok = ok_nav and (n is not None) and present record("text_summary_emoji_max_items", ok, "" if ok else "behavior_wrong: 'Maximum items to keep' summary is not 'Unlimited / 90 items'", depth=1, jump_kind="transition", expect="Maximum items to keep summary == 'Unlimited / 90 items'") @and_test(expects=("text_summary_sunrise_sunset",)) def test_summary_sunrise_sunset(): """Theme screen renders 'Sunrise time / 6:00 AM' and 'Sunset time / 6:00 PM' (locale default; asserted together so a single wrong value fails).""" restart_app() wait_for_foreground() ok_nav, nodes = open_section("Theme", "Theme") hay = all_text(nodes) sunrise = find_node_ci(nodes, "Sunrise time") is not None and "6:00 AM" in hay sunset = find_node_ci(nodes, "Sunset time") is not None and "6:00 PM" in hay ok = ok_nav and sunrise and sunset record("text_summary_sunrise_sunset", ok, "" if ok else "behavior_wrong: Sunrise/Sunset summaries are not '6:00 AM' / '6:00 PM'", depth=1, jump_kind="transition", expect="Sunrise '6:00 AM' and Sunset '6:00 PM'") # ══════════════════════════════════════════════════════════════════════════════ # 4) DIALOG OPTION labels (depth 2: section -> ListPreference dialog) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_dialog_utility_key_options",)) def test_dialog_utility_key_options(): """Keyboard 'Utility key action' opens a ListPreference dialog whose radio options include 'Switch to emojis' and 'Switch keyboard app'. Assert both option strings appear only AFTER opening the dialog.""" restart_app() wait_for_foreground() ok_nav, _ = open_section("Keyboard", "Keyboard") trigger = scroll_into_view("Utility key action") if ok_nav else None if not (ok_nav and trigger): record("text_dialog_utility_key_options", False, "setup_failed: could not reach 'Utility key action' on Keyboard screen", depth=2, jump_kind="transition", expect="dialog shows 'Switch to emojis' + 'Switch keyboard app'") return before = all_text(ui()) absent = "Switch keyboard app" not in before before_keys = and_showing() tapped = safe_tap(trigger) and_enter("Utility key action dialog") # depth 2: dialog surface opened after_nodes = ui() after_keys = and_showing() dialog_opened = surface_changed(before_keys, after_keys) opt_emojis = find_node_ci(after_nodes, "Switch to emojis") is not None opt_kbapp = find_node_ci(after_nodes, "Switch keyboard app") is not None ok = tapped and absent and dialog_opened and opt_emojis and opt_kbapp msg = "" if not ok: if not (tapped and dialog_opened): msg = "setup_failed: 'Utility key action' dialog did not open" else: msg = "behavior_wrong: dialog missing option 'Switch to emojis' and/or 'Switch keyboard app'" record("text_dialog_utility_key_options", ok, msg, depth=2, jump_kind="transition", expect="dialog options 'Switch to emojis' and 'Switch keyboard app'") # ══════════════════════════════════════════════════════════════════════════════ # 5) WARNING / STATUS text (contains-match, ampersand-free substring) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_warning_glide_typing",)) def test_warning_glide_typing(): """Gestures & Glide typing screen renders the 'Glide typing is currently not available…' warning banner. The full sentence contains '&', so match the ampersand-free leading substring.""" restart_app() wait_for_foreground() want = "Glide typing is currently not available" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Gestures", "Gestures") present = want in all_text(nodes) ok = absent and ok_nav and present record("text_warning_glide_typing", ok, "" if ok else "behavior_wrong: glide-typing warning not found on Gestures screen", depth=1, jump_kind="transition", expect="'Glide typing is currently not available' warning") @and_test(expects=("text_warning_no_subtypes",)) def test_warning_no_subtypes(): """Languages & Layouts renders the fallback warning '…haven't configured any subtypes…'. Match the apostrophe-free substring 'configured any subtypes'.""" restart_app() wait_for_foreground() want = "configured any subtypes" absent = want not in all_text(ui()) ok_nav, nodes = open_section("Languages", "Languages") present = want in all_text(nodes) ok = absent and ok_nav and present record("text_warning_no_subtypes", ok, "" if ok else "behavior_wrong: 'no subtypes configured' warning not found on Languages screen", depth=1, jump_kind="transition", expect="warning contains 'configured any subtypes'") # ══════════════════════════════════════════════════════════════════════════════ # 6) FUNCTIONAL content-desc (app-agnostic; Languages 'Add subtype' button) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_content_desc_add_subtype",)) def test_content_desc_add_subtype(): """Languages & Layouts has an icon control with content-desc 'Add subtype' (a functional, app-name-agnostic description). Assert it is present only after navigating into the section.""" restart_app() wait_for_foreground() want = "Add subtype" absent = find_node(ui(), content_desc=want) is None ok_nav, nodes = open_section("Languages", "Languages") present = (find_node(nodes, content_desc=want) is not None or find_node_ci(nodes, want) is not None) ok = absent and ok_nav and present record("text_content_desc_add_subtype", ok, "" if ok else "feature_missing: no 'Add subtype' control on Languages screen", depth=1, jump_kind="transition", expect="content-desc/label 'Add subtype'") # ══════════════════════════════════════════════════════════════════════════════ # 7) DEPTH-2 content strings # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_depth2_licenses",)) def test_depth2_licenses(): """About -> Third-party licenses -> a scrollable list where the license label 'Apache License 2.0' is rendered (app-agnostic; every library row shows it).""" restart_app() wait_for_foreground() ok_nav, _ = open_section("About", "About") if not ok_nav: record("text_depth2_licenses", False, "setup_failed: could not navigate Home -> About", depth=2, jump_kind="transition", expect="'Apache License 2.0' on licenses screen") return trigger = scroll_into_view("Third-party licenses") if not trigger: record("text_depth2_licenses", False, "setup_failed: 'Third-party licenses' row not found on About screen", depth=2, jump_kind="transition", expect="'Apache License 2.0' on licenses screen") return reached = and_reach_surface(trigger, target="Third-party licenses", source="Version") nodes = ui() present = "Apache License 2.0" in all_text(nodes) ok = reached and present msg = "" if not ok: msg = ("setup_failed: did not reach the Third-party licenses list surface" if not reached else "behavior_wrong: 'Apache License 2.0' license label not rendered in the list") record("text_depth2_licenses", ok, msg, depth=2, jump_kind="transition", expect="'Apache License 2.0' on third-party licenses list") @and_test(expects=("text_depth2_theme_extensions",)) def test_depth2_theme_extensions(): """Addons & Extensions -> Theme extensions -> the manager screen shows a 'Theme extensions' heading (top-bar title).""" restart_app() wait_for_foreground() ok_nav, _ = open_section("Addons", "Addons") if not ok_nav: record("text_depth2_theme_extensions", False, "setup_failed: could not navigate Home -> Addons & Extensions", depth=2, jump_kind="transition", expect="'Theme extensions' manager heading") return trigger = scroll_into_view("Theme extensions") if not trigger: record("text_depth2_theme_extensions", False, "setup_failed: 'Theme extensions' row not found on Addons screen", depth=2, jump_kind="transition", expect="'Theme extensions' manager heading") return before = and_showing() tapped = safe_tap(trigger) and_enter("Theme extension manager") # depth 2 nodes = ui() after = and_showing() changed = surface_changed(before, after) title = top_bar_title(nodes, "Theme extensions") ok = tapped and changed and title is not None msg = "" if not ok: msg = ("setup_failed: Theme extension manager surface did not open" if not (tapped and changed) else "behavior_wrong: manager screen has no 'Theme extensions' heading") record("text_depth2_theme_extensions", ok, msg, depth=2, jump_kind="transition", expect="manager top-bar heading == 'Theme extensions'") # ══════════════════════════════════════════════════════════════════════════════ # 8) VLM (exactly 4) — OPAQUE canvas keyboard text only (tag="content") # The keyboard runs in a separate IME window; keys are drawn on a Compose # canvas and never reach the dump, so these are legitimately VLM-only. # ══════════════════════════════════════════════════════════════════════════════ def _open_preview_keyboard(): """Home -> tap 'Try out your setup' -> the FlorisBoard keyboard animates in (2 launch settles). Returns True on success.""" restart_app() wait_for_foreground() n = find_node_ci(ui(), "Try out your setup") if not n: return False if not tap_node(n): return False settle("launch") settle("launch") return True def _tap_key(char, row): """Tap a calibrated QWERTY key centre (fractions from recon.md, resolved via get_screen_info() — never a pixel literal).""" s = get_screen_info() w, h = s["width"], s["height"] layouts = {1: ("qwertyuiop", 0.705, 0.05, 0.90, 9), 2: ("asdfghjkl", 0.795, 0.09, 0.82, 8), 3: ("zxcvbnm", 0.855, 0.18, 0.64, 6)} letters, yf, x0, span, denom = layouts[row] i = letters.index(char) x = (x0 + span * (i / denom)) * w y = yf * h tap(int(x), int(y)) @and_test(expects=("text_kb_letter_glyphs_vlm",)) def test_kb_letter_glyphs_vlm(): """The keyboard renders lowercase letter glyphs on a canvas (not in the dump).""" if not _open_preview_keyboard(): record("text_kb_letter_glyphs_vlm", False, "setup_failed: could not open the keyboard preview", depth=1, jump_kind="transition", expect="QWERTY letter glyphs rendered", tag="content") return vlm_assert("text_kb_letter_glyphs", "Is an on-screen keyboard visible showing rows of lowercase letter " "keys arranged in a QWERTY layout (top row q w e r t y u i o p)?", RESULTS_DIR, depth=1, jump_kind="transition", tag="content") @and_test(expects=("text_kb_symbol_glyphs_vlm",)) def test_kb_symbol_glyphs_vlm(): """After '?123' the keyboard renders symbol/digit glyphs on the canvas.""" if not _open_preview_keyboard(): record("text_kb_symbol_glyphs_vlm", False, "setup_failed: could not open the keyboard preview", depth=1, jump_kind="transition", expect="symbol glyphs rendered", tag="content") return # ?123 sits on the space row, leftmost (x=0.08, y=0.915) per recon.md. s = get_screen_info() tap(int(0.08 * s["width"]), int(0.915 * s["height"])) settle("tap") vlm_assert("text_kb_symbol_glyphs", "Does the on-screen keyboard now show a symbols layout — a top row " "of digits 1 2 3 4 5 6 7 8 9 0 and punctuation/symbol keys such as " "@ # $ & - + ( ) below them?", RESULTS_DIR, depth=1, jump_kind="transition", tag="content") @and_test(expects=("text_kb_suggestions_vlm",)) def test_kb_suggestions_vlm(): """The smartbar shows candidate word suggestions (canvas text) after typing.""" if not _open_preview_keyboard(): record("text_kb_suggestions_vlm", False, "setup_failed: could not open the keyboard preview", depth=1, jump_kind="transition", expect="word suggestions rendered", tag="content") return for ch in "the": _tap_key(ch, 1 if ch in "qwertyuiop" else 2) settle("tap") vlm_assert("text_kb_suggestions", "Is there a horizontal suggestion strip directly above the keyboard " "keys showing one or more candidate words as text?", RESULTS_DIR, depth=1, jump_kind="transition", tag="content") @and_test(expects=("text_kb_shifted_uppercase_vlm",)) def test_kb_shifted_uppercase_vlm(): """Tapping shift renders the letter glyphs in UPPERCASE on the canvas.""" if not _open_preview_keyboard(): record("text_kb_shifted_uppercase_vlm", False, "setup_failed: could not open the keyboard preview", depth=1, jump_kind="transition", expect="uppercase letter glyphs rendered", tag="content") return # SHIFT at x=0.08, y=0.855 (row 3 left) per recon.md. s = get_screen_info() tap(int(0.08 * s["width"]), int(0.855 * s["height"])) settle("tap") vlm_assert("text_kb_shifted_uppercase", "Are the letter keys on the on-screen keyboard now displayed as " "UPPERCASE letters (A W E R T Y ...) rather than lowercase?", RESULTS_DIR, depth=1, jump_kind="transition", tag="content") TESTS = [ # section titles test_title_keyboard, test_title_clipboard, test_title_emojis, test_title_about, # switch/preference summaries test_summary_number_row, test_summary_utility_key, test_summary_display_suggestions, test_summary_offensive_words, test_summary_smartbar, test_summary_internal_clipboard, # computed summaries test_summary_font_size, test_summary_grid_columns, test_summary_emoji_max_items, test_summary_sunrise_sunset, # dialog options test_dialog_utility_key_options, # warnings test_warning_glide_typing, test_warning_no_subtypes, # content-desc test_content_desc_add_subtype, # depth-2 content test_depth2_licenses, test_depth2_theme_extensions, # VLM (opaque canvas) test_kb_letter_glyphs_vlm, test_kb_symbol_glyphs_vlm, test_kb_suggestions_vlm, test_kb_shifted_uppercase_vlm, ] if __name__ == "__main__": run_suite(TESTS, "text")