Datasets:
File size: 22,027 Bytes
c1c6a0c | 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 | #!/usr/bin/env python3
"""COMPUTATION lane — Doodle live-wallpaper customization.
Core function of this app is the SLIDER: dragging a SeekBar changes a value that
is READABLE from the view tree. Each `slider_*` SeekBar has a sibling SeekBar whose
`content-desc="Value, <X>"` carries the current value. So the input->output
observation is: drag the slider (trigger) -> re-dump -> read the sibling's
"Value, X" (observation). Because the pixel->value mapping is not perfectly
deterministic, the robust verdict is DIRECTION: after dragging fully one way to a
baseline, dragging the other way STRICTLY changes the parsed number. The scale
slider additionally has a reset button that returns it to its default "×1.2".
Everything is dump-readable, so this lane is nearly all rule assertions. The 2 VLM
records target the rendered slider THUMB/FILL POSITION on the track — a rendered
property whose exact placement is visual, not a text value.
"""
import os
import re
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,F401
# TESTS is auto-populated at import (bottom of file) from every module-level
# `test_*` function in definition order, so nothing can silently go unregistered.
TESTS = []
# ──────────────────────────────────────────────────────────────────────────────
# Slider helpers — locate the "Value, X" sibling, parse its number, drag the track
# ──────────────────────────────────────────────────────────────────────────────
def _value_desc(nodes, rid):
"""The sibling value-SeekBar's 'Value, X' content-desc for slider `rid`.
The value SeekBar is a CHILD contained within the parent SeekBar's bounds and
carries the content-desc; the parent slider itself has an empty content-desc.
Returns the raw string (e.g. 'Value, 30ms') or None.
"""
sl = node_by_id(nodes, rid)
if not sl:
return None
pb = sl.get("_bounds")
if not pb:
return None
px1, py1, px2, py2 = pb
for n in nodes:
if n is sl:
continue
cd = n.get("content-desc", "")
if not cd.startswith("Value,"):
continue
nb = n.get("_bounds")
if not nb:
continue
nx1, ny1, nx2, ny2 = nb
if nx1 >= px1 - 5 and nx2 <= px2 + 5 and ny1 >= py1 - 5 and ny2 <= py2 + 5:
return cd
return None
def _num(desc):
"""First number in a 'Value, X' string, ignoring '×'/units. 'Value, ×1.2' ->
1.2 ; 'Value, 30ms' -> 30.0 ; 'Value, 0 degrees' -> 0.0. None if absent."""
if not desc:
return None
m = re.search(r"[-+]?\d*\.?\d+", desc.replace("×", ""))
return float(m.group()) if m else None
def _slider_num(nodes, rid):
return _num(_value_desc(nodes, rid))
def _drag(sl, direction, frac=0.7):
"""Drag the SeekBar thumb horizontally from mid-track. `frac` of the track
width toward 'right' (increase) or 'left' (decrease)."""
if not sl or "_bounds" not in sl:
return False
x1, y1, x2, y2 = sl["_bounds"]
cy = (y1 + y2) // 2
span = x2 - x1
sx = x1 + int(span * 0.5)
if direction == "right":
ex = x1 + int(span * (0.5 + frac))
else:
ex = x1 + int(span * (0.5 - frac))
ex = max(x1 + 2, min(x2 - 2, ex))
swipe(sx, cy, ex, cy, ms=400) # noqa: F405
return True
def _find_slider_scrolling(rid, max_scrolls=5):
"""Return (nodes, slider_node) with `rid` on-screen, scrolling if needed.
A lazy/off-screen slider is scrolled into view; re-dumps between swipes."""
for _ in range(max_scrolls + 1):
nodes = ui() # noqa: F405
sl = node_by_id(nodes, rid) # noqa: F405
if sl and sl.get("_bounds") and (sl["_bounds"][3] - sl["_bounds"][1]) > 5:
# ensure fully on screen (not clipped at the bottom)
s = get_screen_info() # noqa: F405
if sl["_bounds"][3] <= s["height"] - 20:
return nodes, sl
scroll_down(0.4) # noqa: F405
nodes = ui() # noqa: F405
return nodes, node_by_id(nodes, rid) # noqa: F405
# ──────────────────────────────────────────────────────────────────────────────
# Navigation — each backs a depth=1 claim (Home -> fragment, arrival verified)
# ──────────────────────────────────────────────────────────────────────────────
def _reach_fragment(row_rid, unique_slider_rid):
"""Home -> fragment. Tap the Overview `row_rid`, then PROVE arrival: a slider
that only exists on the destination fragment is now present, and the source
Overview row is gone. Counts one surface via and_enter(). Returns True/False.
Verifying by a fragment-unique slider id (not the toolbar title) avoids the
trap that some fragment titles equal their Overview row label, which would
make them look already-present in the "before" surface.
"""
restart_app() # noqa: F405
wait_for_foreground() # noqa: F405
nodes = ui() # noqa: F405
row = node_by_id(nodes, row_rid) # noqa: F405
if not row:
return False
if not tap_node(row): # noqa: F405
return False
settle("tap") # noqa: F405
after = ui() # noqa: F405
arrived = node_by_id(after, unique_slider_rid) is not None # noqa: F405
source_gone = node_by_id(after, row_rid) is None # noqa: F405
if arrived and source_gone:
and_enter(unique_slider_rid) # noqa: F405
return True
return False
def and_enter_parallax():
"""Home -> Parallax. Arrival proven by slider_parallax_swipe appearing and the
Overview Parallax row vanishing. Backs depth=1."""
return _reach_fragment("linear_overview_parallax", "slider_parallax_swipe")
def and_enter_size():
"""Home -> Shape size. Arrival proven by slider_size_scale appearing and the
Overview Shape-size row vanishing. Backs depth=1."""
return _reach_fragment("linear_overview_size", "slider_size_scale")
def and_enter_other():
"""Home -> Other options. Arrival proven by slider_screen_off_delay appearing
and the Overview Other-options row vanishing. Backs depth=1."""
return _reach_fragment("linear_overview_other", "slider_screen_off_delay")
def _enable_tilt(nodes):
"""Turn ON switch_parallax_tilt so the tilt-group sliders (tilt, refresh_rate,
damping, threshold) become enabled and draggable. Returns fresh nodes.
The enable state needs a moment to propagate to the sub-sliders, so this
settles twice after the tap (observed necessary during recon)."""
sw = node_by_id(nodes, "switch_parallax_tilt") # noqa: F405
if sw and sw.get("checked") != "true":
tap_node(sw) # noqa: F405
settle("tap") # noqa: F405
settle("tap") # noqa: F405
return ui() # noqa: F405
# ──────────────────────────────────────────────────────────────────────────────
# Generic driver: baseline one extreme, drag the other way, assert strict change
# ──────────────────────────────────────────────────────────────────────────────
def _drive_slider(name, entered, rid, primary, expect_str, *,
pre=None, add_vlm=False, vlm_q="", vlm_tag="position"):
"""Given the fragment is already navigated to (`entered`), (optionally
pre-enable a gate), find the slider (scrolling if needed), push it to the
OPPOSITE extreme to establish a baseline value, then drag in `primary`
direction and assert the parsed number STRICTLY moved the expected way. Robust
to the slider's persisted start value.
Navigation is done by the caller (a direct and_enter_* call in the test body,
so the depth auditor can see the backing call); this driver only records.
"""
if not entered:
record(name, False, "setup_failed: could not navigate to the fragment", # noqa: F405
depth=1, jump_kind="value", expect=expect_str)
if add_vlm:
record(name + "_vlm", False, # noqa: F405
"setup_failed: could not navigate to the fragment",
depth=1, jump_kind="none", tag=vlm_tag)
return
if pre:
pre()
nodes, sl = _find_slider_scrolling(rid)
if not sl or sl.get("enabled") != "true":
record(name, False, # noqa: F405
f"feature_missing: slider {rid} not present/enabled", depth=1,
jump_kind="value", expect=expect_str)
if add_vlm:
record(name + "_vlm", False, # noqa: F405
f"feature_missing: slider {rid} not present/enabled",
depth=1, jump_kind="none", tag=vlm_tag)
return
opposite = "left" if primary == "right" else "right"
# Establish a deterministic baseline at the opposite extreme.
_drag(sl, opposite, 1.0)
nodes = ui() # noqa: F405
base = _slider_num(nodes, rid)
sl = node_by_id(nodes, rid) # noqa: F405
# Drag in the primary direction.
_drag(sl, primary, 0.7)
nodes = ui() # noqa: F405
now = _slider_num(nodes, rid)
if base is None or now is None:
ok = False
msg = f"behavior_wrong: could not read 'Value, X' for {rid} (base={base}, now={now})"
elif primary == "right":
ok = now > base
msg = "" if ok else f"behavior_wrong: {rid} did not increase after right drag ({base} -> {now})"
else:
ok = now < base
msg = "" if ok else f"behavior_wrong: {rid} did not decrease after left drag ({base} -> {now})"
record(name, ok, msg, depth=1, jump_kind="value", expect=expect_str) # noqa: F405
if add_vlm:
vlm_assert(name, vlm_q, RESULTS_DIR, depth=1, jump_kind="none", tag=vlm_tag) # noqa: F405
# ══════════════════════════════════════════════════════════════════════════════
# PARALLAX fragment
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_parallax_swipe_increase",))
def test_parallax_swipe_increase():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_swipe_increase", entered,
"slider_parallax_swipe", "right",
"swipe slider value strictly increases after dragging right (min ~1 -> higher)")
@and_test(expects=("computation_parallax_swipe_decrease",))
def test_parallax_swipe_decrease():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_swipe_decrease", entered,
"slider_parallax_swipe", "left",
"swipe slider value strictly decreases after dragging left (max 5 -> lower)")
@and_test(expects=("computation_parallax_tilt_increase",))
def test_parallax_tilt_increase():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_tilt_increase", entered,
"slider_parallax_tilt", "right",
"tilt slider value strictly increases after dragging right (range 1..8)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
@and_test(expects=("computation_parallax_tilt_decrease",))
def test_parallax_tilt_decrease():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_tilt_decrease", entered,
"slider_parallax_tilt", "left",
"tilt slider value strictly decreases after dragging left (range 1..8)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
@and_test(expects=("computation_parallax_refresh_rate_increase",))
def test_parallax_refresh_rate_increase():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_refresh_rate_increase", entered,
"slider_parallax_refresh_rate", "right",
"refresh-rate slider ms value strictly increases after dragging right (from 30ms)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
@and_test(expects=("computation_parallax_damping_decrease",))
def test_parallax_damping_decrease():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_damping_decrease", entered,
"slider_parallax_damping", "left",
"damping slider value strictly decreases after dragging left (range 1..20)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
@and_test(expects=("computation_parallax_damping_increase",))
def test_parallax_damping_increase():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_damping_increase", entered,
"slider_parallax_damping", "right",
"damping slider value strictly increases after dragging right (range 1..20)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
@and_test(expects=("computation_parallax_threshold_increase",))
def test_parallax_threshold_increase():
entered = and_enter_parallax()
_drive_slider(
"computation_parallax_threshold_increase", entered,
"slider_parallax_threshold", "right",
"threshold slider value strictly increases after dragging right (range 1..10)",
pre=lambda: _enable_tilt(ui())) # noqa: F405
# ══════════════════════════════════════════════════════════════════════════════
# SHAPE SIZE fragment
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_size_scale_increase", "computation_size_scale_increase_vlm"))
def test_size_scale_increase():
entered = and_enter_size()
_drive_slider(
"computation_size_scale_increase", entered,
"slider_size_scale", "right",
"scale multiplier strictly increases after dragging right (\u00d70.8 min -> higher)",
add_vlm=True, vlm_tag="position",
vlm_q=("Look at the top slider labelled 'Scale'. Is its filled (darker) "
"track and round handle positioned at the far RIGHT end of the "
"slider track (track almost completely filled)?"))
@and_test(expects=("computation_size_scale_decrease", "computation_size_scale_decrease_vlm"))
def test_size_scale_decrease():
entered = and_enter_size()
_drive_slider(
"computation_size_scale_decrease", entered,
"slider_size_scale", "left",
"scale multiplier strictly decreases after dragging left (\u00d72 max -> lower)",
add_vlm=True, vlm_tag="position",
vlm_q=("Look at the top slider labelled 'Scale'. Is its round handle "
"positioned near the far LEFT end of the slider track (track mostly "
"empty)?"))
@and_test(expects=("computation_size_scale_reset",))
def test_size_scale_reset():
"""Change scale away from default, tap the reset button, assert it returns to
the observed default '\u00d71.2'. This is an exact-value observation, not merely a
direction."""
name = "computation_size_scale_reset"
expect = "scale returns to default \u00d71.2 (numeric 1.2) after tapping reset"
entered = and_enter_size()
if not entered:
record(name, False, "setup_failed: could not navigate to Shape size", # noqa: F405
depth=1, jump_kind="value", expect=expect)
return
nodes, sl = _find_slider_scrolling("slider_size_scale")
rb = node_by_id(nodes, "button_size_scale_reset") # noqa: F405
if not sl or not rb:
record(name, False, "feature_missing: scale slider or reset button absent", # noqa: F405
depth=1, jump_kind="value", expect=expect)
return
# Move the scale away from default first.
_drag(sl, "right", 0.9)
nodes = ui() # noqa: F405
moved = _slider_num(nodes, "slider_size_scale")
# Tap reset.
rb = node_by_id(nodes, "button_size_scale_reset") # noqa: F405
tap_node(rb) # noqa: F405
settle("tap") # noqa: F405
nodes = ui() # noqa: F405
after = _slider_num(nodes, "slider_size_scale")
ok = (moved is not None and after is not None
and abs(after - 1.2) < 1e-6 and moved > 1.2)
msg = "" if ok else (f"behavior_wrong: reset did not restore x1.2 "
f"(moved to {moved}, after reset {after})")
record(name, ok, msg, depth=1, jump_kind="value", expect=expect) # noqa: F405
@and_test(expects=("computation_size_zoom_increase",))
def test_size_zoom_increase():
entered = and_enter_size()
_drive_slider(
"computation_size_zoom_increase", entered,
"slider_size_zoom", "right",
"zoom intensity value strictly increases after dragging right (range 1..5)")
@and_test(expects=("computation_size_zoom_decrease",))
def test_size_zoom_decrease():
entered = and_enter_size()
_drive_slider(
"computation_size_zoom_decrease", entered,
"slider_size_zoom", "left",
"zoom intensity value strictly decreases after dragging left (range 1..5)")
@and_test(expects=("computation_size_rotation_increase",))
def test_size_rotation_increase():
entered = and_enter_size()
_drive_slider(
"computation_size_rotation_increase", entered,
"slider_size_zoom_rotation", "right",
"rotation degrees strictly increase after dragging right (0 -> up to 100)")
@and_test(expects=("computation_size_rotation_decrease",))
def test_size_rotation_decrease():
entered = and_enter_size()
_drive_slider(
"computation_size_rotation_decrease", entered,
"slider_size_zoom_rotation", "left",
"rotation degrees strictly decrease after dragging left (100 -> down to 0)")
@and_test(expects=("computation_size_zoom_duration_increase",))
def test_size_zoom_duration_increase():
entered = and_enter_size()
_drive_slider(
"computation_size_zoom_duration_increase", entered,
"slider_size_zoom_duration", "right",
"zoom duration ms strictly increases after dragging right (500..1500)")
@and_test(expects=("computation_size_zoom_damping_decrease",))
def test_size_zoom_damping_decrease():
entered = and_enter_size()
_drive_slider(
"computation_size_zoom_damping_decrease", entered,
"slider_size_zoom_damping", "left",
"zoom-damping value strictly decreases after dragging left (range 5..15)")
@and_test(expects=("computation_size_zoom_damping_increase",))
def test_size_zoom_damping_increase():
entered = and_enter_size()
_drive_slider(
"computation_size_zoom_damping_increase", entered,
"slider_size_zoom_damping", "right",
"zoom-damping value strictly increases after dragging right (range 5..15)")
# ══════════════════════════════════════════════════════════════════════════════
# OTHER OPTIONS fragment
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_screen_off_delay_increase",))
def test_screen_off_delay_increase():
entered = and_enter_other()
_drive_slider(
"computation_screen_off_delay_increase", entered,
"slider_screen_off_delay", "right",
"screen-off-delay ms strictly increases after dragging right (0ms -> up to 1000ms)")
@and_test(expects=("computation_screen_off_delay_decrease",))
def test_screen_off_delay_decrease():
entered = and_enter_other()
_drive_slider(
"computation_screen_off_delay_decrease", entered,
"slider_screen_off_delay", "left",
"screen-off-delay ms strictly decreases after dragging left (1000ms -> down to 0ms)")
# Register every module-level test in definition order.
TESTS = [obj for name, obj in sorted(
((n, o) for n, o in list(globals().items())
if n.startswith("test_") and callable(o)),
key=lambda kv: kv[1].__code__.co_firstlineno)]
if __name__ == "__main__":
run_suite(TESTS, "computation") # noqa: F405
|