#!/usr/bin/env python3 """TEXT lane for DetoxDroid (com.flx_apps.digitaldetox). Owns CONTENT / OUTPUT strings that a user INTERACTION PRODUCES or CHANGES, and is the sole owner of exact-string equality. Every test here TRIGGERS an action (tap the FAB, tap a segment/checkbox, navigate into a surface, create a rule) and then asserts the EXACT string the app now renders — proving the string is ABSENT before the trigger and PRESENT after wherever the surface allows it. A hardcoded label that is already on screen at launch is deliberately NOT asserted on its own (that is structure's gate); this lane drives the app to make the string appear or change. Ground-truth strings — every one OBSERVED on the running original before shipping: HOME status word (FAB Start/Deny) : "Stopped" -> "Running" -> "Stopped". (The extended-FAB LABEL never reaches the view tree on this build; the status TextView is the dump-readable content the toggle produces.) Commitment Password feature-lock : "0 of 5 features selected" (None), counter "1 of 5 features selected" (+1 checkbox), "5 of 5 features selected" (All). App Exceptions counter (depth 2) : "Active in all apps except 0 selected." -> check one app row : "Active in all apps except 1 selected." -> scope "Only selected apps" : "Active only in 0 selected apps." Feature Schedule (depth 2) : empty state contains "No rules yet." and "This feature is active all the time."; after creating ONE rule the feature detail's schedule subtitle flips "The feature is active all the time." -> "1 rules are set.". Feature detail subtitles produced by opening a feature: Break Infinite Scrolling : "Doom-scrolling checks are active in 0 apps." Disable Apps : "0 apps listed for deactivation". Grayscale schedule tile : "The feature is active all the time.". About screen tagline : "Make digital detox your default." (The "Version 2.4.0" line is NOT asserted — a faithful recreation may carry a different version, so it would be unfair rather than discriminating.) Portability: the package is sys.argv[1] via the kit; no literal package, path, coordinate, or serial appears here. The app PERSISTS its last-viewed screen across force-stop, so fresh_home() restarts and pops BACK until the home FAB is showing rather than assuming restart_app() lands on home. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # Home discriminator — unique to the home surface, absent on every child screen. HOME_FAB = "Run/Stop DetoxDroid" # ── surface helpers ─────────────────────────────────────────────────────────── def fresh_home(): """Isolate a test on a fresh HOME surface. The app restores its last screen across a restart, so after relaunching we pop BACK until the home FAB shows.""" restart_app() if not wait_for_foreground(): return ui() for _ in range(5): nodes = ui() if find_node(nodes, content_desc=HOME_FAB): return nodes if find_node(nodes, content_desc="Back"): back() settle("tap") continue return nodes return ui() def all_text(nodes): return " | ".join(n.get("text", "") for n in nodes if n.get("text")) def status_word(nodes): """The home status TextView content ('Stopped' / 'Running' / 'Paused ...').""" for n in nodes: t = n.get("text", "") if t in ("Stopped", "Running") or t.startswith("Paused"): return t return "" def counter_selected(nodes): """The Commitment 'N of M features selected' counter text, or ''.""" for n in nodes: if "features selected" in n.get("text", ""): return n.get("text", "") return "" def counter_active(nodes): """The App Exceptions 'Active ...' counter text, or ''.""" for n in nodes: t = n.get("text", "") if t.startswith("Active") and "apps" in t: return t return "" def dismiss_battery_dialog(): """After the first FAB Start a system 'run in background?' dialog can appear. Tapping Deny is the safe dismissal (never Allow).""" n = find_node_ci(ui(), "Deny") if n: tap_node(n) settle("tap") # ── named depth helpers (back the declared depth for the audit) ─────────────── def and_enter_feature(title): """HOME -> a feature detail. Scrolls the tile into view, taps it, counts one surface via and_enter. Returns the detail's node list (or None).""" nodes = fresh_home() tile = scroll_into_view(title) if not tile: return None if not tap_node(tile): return None and_enter(title) return ui() def and_enter_app_exceptions(feature_title): """HOME -> feature -> App Exceptions (depth 2), via the 'Manage App Scope' tile.""" if and_enter_feature(feature_title) is None: return None tile = find_node(ui(), content_desc="Manage App Scope") if not tile or not tap_node(tile): return None and_enter("App Exceptions") return ui() def and_enter_schedule(feature_title): """HOME -> feature -> Feature Schedule (depth 2), via the 'Manage Schedule' tile.""" if and_enter_feature(feature_title) is None: return None tile = find_node(ui(), content_desc="Manage Schedule") if not tile or not tap_node(tile): return None and_enter("Feature Schedule") return ui() # ══════════════════════════════════════════════════════════════════════════════ # HOME (depth 0) — status word the FAB toggle produces # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_fab_status_running", "text_fab_status_running_vlm")) def test_fab_status_running(): # Tap the Start FAB (dismiss the battery dialog with Deny) and assert the # status content flips Stopped -> Running. nodes = fresh_home() before = status_word(nodes) fab = find_node(nodes, content_desc=HOME_FAB) if before != "Stopped" or not fab: record("text_fab_status_running", False, "setup_failed: home did not show 'Stopped' status / FAB before toggling " f"(saw status={before!r})", depth=0, jump_kind="transition", expect="status text 'Stopped' -> 'Running'") else: tap_node(fab) settle("tap") dismiss_battery_dialog() after = status_word(ui()) ok = after == "Running" record("text_fab_status_running", ok, "" if ok else "behavior_wrong: status did not read 'Running' after " f"starting DetoxDroid (saw {after!r})", depth=0, jump_kind="transition", expect="status text 'Stopped' -> 'Running'") # The status row carries a colored indicator dot next to the word; running is # green. This is a precise rendered property the toggle produces. vlm_assert("text_fab_status_running", "Is there a small round GREEN colored dot immediately to the left of " "the status word near the top-left of the screen?", RESULTS_DIR, depth=0, jump_kind="transition", tag="color") # Restore to Stopped so later tests start clean. fab2 = find_node(ui(), content_desc=HOME_FAB) if fab2: tap_node(fab2) settle("tap") @and_test(expects=("text_fab_status_stopped",)) def test_fab_status_stopped(): # From Running, tap the FAB and assert the status content flips back to # 'Stopped'. Drives Running first inside this isolated test. nodes = fresh_home() fab = find_node(nodes, content_desc=HOME_FAB) if not fab: record("text_fab_status_stopped", False, "setup_failed: home FAB 'Run/Stop DetoxDroid' not found", depth=0, jump_kind="transition", expect="status text 'Running' -> 'Stopped'") return tap_node(fab) settle("tap") dismiss_battery_dialog() running = status_word(ui()) if running != "Running": record("text_fab_status_stopped", False, f"setup_failed: could not reach 'Running' before stopping (saw {running!r})", depth=0, jump_kind="transition", expect="status text 'Running' -> 'Stopped'") return fab2 = find_node(ui(), content_desc=HOME_FAB) tap_node(fab2) settle("tap") after = status_word(ui()) ok = after == "Stopped" record("text_fab_status_stopped", ok, "" if ok else "behavior_wrong: status did not read 'Stopped' after " f"stopping DetoxDroid (saw {after!r})", depth=0, jump_kind="transition", expect="status text 'Running' -> 'Stopped'") @and_test(expects=("text_home_donut_vlm",)) def test_home_donut(): # OPAQUE CORE: the screen-time donut is drawn on a Canvas (co.yml.charts) and # never reaches the view tree, so this is the one legitimate content VLM. fresh_home() vlm_assert("text_home_donut", "Is there a circular donut/ring chart with one or more colored ring " "segments in the upper portion of the screen?", RESULTS_DIR, depth=0, jump_kind="none", tag="content") # ══════════════════════════════════════════════════════════════════════════════ # Commitment Password feature-lock counter (depth 1) — value strings a tap makes # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_commitment_none_zero",)) def test_commitment_none_zero(): nodes = and_enter_feature("Commitment Password") if nodes is None: record("text_commitment_none_zero", False, "setup_failed: could not open Commitment Password settings", depth=1, jump_kind="value", expect="'0 of 5 features selected'") return none_btn = find_node(ui(), text="None") if not none_btn: record("text_commitment_none_zero", False, "feature_missing: 'None' button not on the Commitment settings screen", depth=1, jump_kind="value", expect="'0 of 5 features selected'") return tap_node(none_btn) settle("tap") txt = counter_selected(ui()) ok = txt.strip().casefold() == "0 of 5 features selected" record("text_commitment_none_zero", ok, "" if ok else "behavior_wrong: counter did not read '0 of 5 features " f"selected' after tapping None (saw {txt!r})", depth=1, jump_kind="value", expect="'0 of 5 features selected'") @and_test(expects=("text_commitment_check_one",)) def test_commitment_check_one(): nodes = and_enter_feature("Commitment Password") if nodes is None: record("text_commitment_check_one", False, "setup_failed: could not open Commitment Password settings", depth=1, jump_kind="value", expect="'1 of 5 features selected'") return # Start from a known 0 baseline, then check exactly one feature checkbox. none_btn = find_node(ui(), text="None") if none_btn: tap_node(none_btn) settle("tap") boxes = [n for n in ui() if n.get("checkable") == "true" and "CheckBox" in n.get("class", "")] if not boxes: record("text_commitment_check_one", False, "feature_missing: no feature-lock checkboxes on the Commitment screen", depth=1, jump_kind="value", expect="'1 of 5 features selected'") return tap_node(boxes[0]) settle("tap") txt = counter_selected(ui()) if not txt: scroll_into_view("features selected") txt = counter_selected(ui()) ok = txt.strip().casefold() == "1 of 5 features selected" record("text_commitment_check_one", ok, "" if ok else "behavior_wrong: counter did not read '1 of 5 features " f"selected' after checking one feature (saw {txt!r})", depth=1, jump_kind="value", expect="'1 of 5 features selected'") # Clean up: return the selection to 0 so state does not leak. nb = find_node(ui(), text="None") if nb: tap_node(nb) settle("tap") @and_test(expects=("text_commitment_all_five",)) def test_commitment_all_five(): nodes = and_enter_feature("Commitment Password") if nodes is None: record("text_commitment_all_five", False, "setup_failed: could not open Commitment Password settings", depth=1, jump_kind="value", expect="'5 of 5 features selected'") return all_btn = find_node(ui(), text="All") if not all_btn: record("text_commitment_all_five", False, "feature_missing: 'All' button not on the Commitment settings screen", depth=1, jump_kind="value", expect="'5 of 5 features selected'") return tap_node(all_btn) settle("tap") txt = counter_selected(ui()) if not txt: scroll_into_view("features selected") txt = counter_selected(ui()) ok = txt.strip().casefold() == "5 of 5 features selected" record("text_commitment_all_five", ok, "" if ok else "behavior_wrong: counter did not read '5 of 5 features " f"selected' after tapping All (saw {txt!r})", depth=1, jump_kind="value", expect="'5 of 5 features selected'") # Clean up: return the selection to 0. nb = find_node(ui(), text="None") if nb: tap_node(nb) settle("tap") # ══════════════════════════════════════════════════════════════════════════════ # Feature-detail subtitles a navigation PRODUCES (depth 1) — value strings # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_break_app_scope_subtitle",)) def test_break_app_scope_subtitle(): EXPECT = "Doom-scrolling checks are active in 0 apps." absent = EXPECT.casefold() not in all_text(fresh_home()).casefold() nodes = and_enter_feature("Break Infinite Scrolling") if nodes is None: record("text_break_app_scope_subtitle", False, "setup_failed: could not open Break Infinite Scrolling detail", depth=1, jump_kind="value", expect=repr(EXPECT)) return present = EXPECT.casefold() in all_text(ui()).casefold() ok = absent and present record("text_break_app_scope_subtitle", ok, "" if ok else "behavior_wrong: Break detail App Exceptions subtitle did " f"not read {EXPECT!r} (absent_before={absent}, present_after={present})", depth=1, jump_kind="value", expect=repr(EXPECT)) @and_test(expects=("text_disable_deactivated_subtitle",)) def test_disable_deactivated_subtitle(): EXPECT = "0 apps listed for deactivation" absent = EXPECT.casefold() not in all_text(fresh_home()).casefold() nodes = and_enter_feature("Disable Apps") if nodes is None: record("text_disable_deactivated_subtitle", False, "setup_failed: could not open Disable Apps detail", depth=1, jump_kind="value", expect=repr(EXPECT)) return present = EXPECT.casefold() in all_text(ui()).casefold() ok = absent and present record("text_disable_deactivated_subtitle", ok, "" if ok else "behavior_wrong: Disable Apps 'Manage Deactivated Apps' " f"subtitle did not read {EXPECT!r} " f"(absent_before={absent}, present_after={present})", depth=1, jump_kind="value", expect=repr(EXPECT)) @and_test(expects=("text_grayscale_schedule_subtitle",)) def test_grayscale_schedule_subtitle(): # The Feature Schedule tile subtitle on a fresh feature detail reads the # "active all the time" default — the content opening the feature produces. EXPECT = "The feature is active all the time." clear_data() # guarantee no leftover rule that would change this subtitle nodes = and_enter_feature("Automatic Grayscale") if nodes is None: record("text_grayscale_schedule_subtitle", False, "setup_failed: could not open Automatic Grayscale detail", depth=1, jump_kind="value", expect=repr(EXPECT)) return present = EXPECT.casefold() in all_text(ui()).casefold() record("text_grayscale_schedule_subtitle", present, "" if present else "behavior_wrong: Grayscale Feature Schedule subtitle " f"did not read {EXPECT!r}", depth=1, jump_kind="value", expect=repr(EXPECT)) @and_test(expects=("text_about_tagline",)) def test_about_tagline(): # About is reached by tapping the About tile; the tagline is content that # navigation produces. Assert ABSENT on home, PRESENT on the About screen. EXPECT = "Make digital detox your default." absent = EXPECT.casefold() not in all_text(fresh_home()).casefold() nodes = and_enter_feature("About") if nodes is None: record("text_about_tagline", False, "setup_failed: could not open the About screen", depth=1, jump_kind="value", expect=repr(EXPECT)) return present = EXPECT.casefold() in all_text(ui()).casefold() ok = absent and present record("text_about_tagline", ok, "" if ok else "behavior_wrong: About tagline did not read " f"{EXPECT!r} (absent_before={absent}, present_after={present})", depth=1, jump_kind="value", expect=repr(EXPECT)) # ══════════════════════════════════════════════════════════════════════════════ # App Exceptions counter (depth 2) — value + transition strings a tap produces # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_appexc_check_one",)) def test_appexc_check_one(): nodes = and_enter_app_exceptions("Automatic Grayscale") if nodes is None: record("text_appexc_check_one", False, "setup_failed: could not reach Grayscale App Exceptions screen", depth=2, jump_kind="value", expect="'Active in all apps except 1 selected.'") return before = counter_active(ui()) if before.strip().casefold() != "active in all apps except 0 selected.": record("text_appexc_check_one", False, f"setup_failed: App Exceptions counter baseline was not 0 (saw {before!r})", depth=2, jump_kind="value", expect="'Active in all apps except 1 selected.'") return boxes = [n for n in ui() if n.get("checkable") == "true" and n.get("_bounds", (0, 0, 0, 0))[1] > 700] if not boxes: record("text_appexc_check_one", False, "feature_missing: no app-row checkbox on the App Exceptions screen", depth=2, jump_kind="value", expect="'Active in all apps except 1 selected.'") return tap_node(boxes[0]) settle("tap") after = counter_active(ui()) ok = after.strip().casefold() == "active in all apps except 1 selected." record("text_appexc_check_one", ok, "" if ok else "behavior_wrong: counter did not read 'Active in all apps " f"except 1 selected.' after checking one app (saw {after!r})", depth=2, jump_kind="value", expect="'Active in all apps except 1 selected.'") # Clean up: uncheck the app row so state does not leak. boxes2 = [n for n in ui() if n.get("checkable") == "true" and n.get("_bounds", (0, 0, 0, 0))[1] > 700] if boxes2: tap_node(boxes2[0]) settle("tap") @and_test(expects=("text_appexc_scope_change",)) def test_appexc_scope_change(): nodes = and_enter_app_exceptions("Automatic Grayscale") if nodes is None: record("text_appexc_scope_change", False, "setup_failed: could not reach Grayscale App Exceptions screen", depth=2, jump_kind="transition", expect="'Active in all apps except 0 selected.' -> " "'Active only in 0 selected apps.'") return before = counter_active(ui()) seg = find_node(ui(), text="Only selected apps") if not seg: record("text_appexc_scope_change", False, "feature_missing: 'Only selected apps' scope segment not present", depth=2, jump_kind="transition", expect="'Active in all apps except 0 selected.' -> " "'Active only in 0 selected apps.'") return tap_node(seg) settle("tap") after = counter_active(ui()) ok = (before.strip().casefold() == "active in all apps except 0 selected." and after.strip().casefold() == "active only in 0 selected apps.") record("text_appexc_scope_change", ok, "" if ok else "behavior_wrong: scope-change counter did not flip to " f"'Active only in 0 selected apps.' (before={before!r}, after={after!r})", depth=2, jump_kind="transition", expect="'Active in all apps except 0 selected.' -> " "'Active only in 0 selected apps.'") # Clean up: restore the default scope. back_seg = find_node(ui(), text="All apps except selected") if back_seg: tap_node(back_seg) settle("tap") # ══════════════════════════════════════════════════════════════════════════════ # Feature Schedule (depth 2) — empty-state text and the rule-creation consequence # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("text_schedule_empty_state",)) def test_schedule_empty_state(): # Reaching the schedule screen with no rules produces the empty-state text. clear_data() # guarantee a genuinely empty schedule nodes = and_enter_schedule("Automatic Grayscale") if nodes is None: record("text_schedule_empty_state", False, "setup_failed: could not reach Grayscale Feature Schedule screen", depth=2, jump_kind="value", expect="empty state contains 'No rules yet.' and 'active all the time.'") return blob = all_text(ui()).casefold() ok = "no rules yet." in blob and "this feature is active all the time." in blob record("text_schedule_empty_state", ok, "" if ok else "behavior_wrong: schedule empty state did not contain " "'No rules yet.' and 'This feature is active all the time.'", depth=2, jump_kind="value", expect="empty state contains 'No rules yet.' and 'active all the time.'") @and_test(expects=("text_schedule_rule_hint",)) def test_schedule_rule_hint(): # Create exactly one rule, then read the feature detail's schedule subtitle, # which changes to "1 rules are set." — a multi-surface interaction consequence. # clear_data() first so we count from zero; delete the rule at the end. EXPECT = "1 rules are set." clear_data() nodes = and_enter_schedule("Automatic Grayscale") if nodes is None: record("text_schedule_rule_hint", False, "setup_failed: could not reach Grayscale Feature Schedule screen", depth=2, jump_kind="value", expect=repr(EXPECT)) return add = find_node(ui(), content_desc="Add") if not add or not tap_node(add): record("text_schedule_rule_hint", False, "setup_failed: could not open the Add-rule sheet", depth=2, jump_kind="value", expect=repr(EXPECT)) return settle("tap") save = find_node(ui(), text="Save") or find_node_ci(ui(), "Save") if not save or not tap_node(save): record("text_schedule_rule_hint", False, "setup_failed: 'Save' not found in the Add-rule sheet", depth=2, jump_kind="value", expect=repr(EXPECT)) return settle("tap") # Back to the feature detail — the schedule subtitle should now read the hint. back() settle("tap") present = EXPECT.casefold() in all_text(ui()).casefold() record("text_schedule_rule_hint", present, "" if present else "behavior_wrong: feature detail schedule subtitle did " f"not read {EXPECT!r} after creating one rule", depth=2, jump_kind="value", expect=repr(EXPECT)) # Clean up: delete the rule we created (safe — it is our own data). sched_tile = find_node(ui(), content_desc="Manage Schedule") if sched_tile and tap_node(sched_tile): settle("tap") row = find_node(ui(), text="Every day") if row and tap_node(row): settle("tap") dele = find_node(ui(), text="Delete") if dele: tap_node(dele) settle("tap") TESTS = [ test_fab_status_running, test_fab_status_stopped, test_home_donut, test_commitment_none_zero, test_commitment_check_one, test_commitment_all_five, test_break_app_scope_subtitle, test_disable_deactivated_subtitle, test_grayscale_schedule_subtitle, test_about_tagline, test_appexc_check_one, test_appexc_scope_change, test_schedule_empty_state, test_schedule_rule_hint, ] if __name__ == "__main__": run_suite(TESTS, "text")