159 lines
8.1 KiB
Python
159 lines
8.1 KiB
Python
"""Verify Settings scale gestures and removal of the former favorites panel."""
|
|
import ast
|
|
import contextlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sqlite3
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
from ui_driver import UiDriver
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUTPUT = ROOT / "build/settings-sidebar-test"
|
|
OUTPUT.mkdir(parents=True, exist_ok=True)
|
|
KEYS = ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS")
|
|
assert all(not os.environ.get(key) for key in KEYS), "Inherited desktop environment"
|
|
BINARY = Path(sys.argv[1] if len(sys.argv) > 1 else ROOT / "build/bin/linux/breeze-linux-x86_64")
|
|
|
|
|
|
def stop(process):
|
|
if process.poll() is None:
|
|
process.terminate()
|
|
process.wait(timeout=5)
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="inbe-settings-") as temporary, contextlib.ExitStack() as stack:
|
|
profile = Path(temporary)
|
|
driver = UiDriver(OUTPUT / "driver")
|
|
env = {key: value for key, value in os.environ.items() if key not in KEYS}
|
|
env.update(driver.environment())
|
|
env.update(YUE_DESKTOP_RECOVERY="0", APP_NO_TRAY="1", SDL_AUDIODRIVER="dummy",
|
|
APP_DATA_ROOT=str(profile), INBE_DEBUG_ROUTE="1")
|
|
display_log = stack.enter_context((OUTPUT / "display.log").open("w"))
|
|
display = subprocess.Popen(["Xvfb", "-noreset", "-displayfd", "1", "-screen", "0", "1280x900x24",
|
|
"-nolisten", "tcp"], env=env, stdout=subprocess.PIPE, stderr=display_log)
|
|
stack.callback(stop, display)
|
|
number = display.stdout.readline().decode().strip()
|
|
display.stdout.close()
|
|
assert number.isdecimal()
|
|
env["DISPLAY"] = ":" + number
|
|
|
|
def command(*args):
|
|
return subprocess.run(args, env=env, check=True, capture_output=True, text=True, timeout=5).stdout.strip()
|
|
|
|
def settings():
|
|
with sqlite3.connect(profile / "inbe.db", timeout=3) as db:
|
|
return dict(db.execute("SELECT key,value FROM settings"))
|
|
|
|
def wait_setting(key, expected):
|
|
deadline = time.monotonic() + 5
|
|
while settings().get(key) != str(expected):
|
|
assert time.monotonic() < deadline, (key, expected, settings().get(key))
|
|
time.sleep(.05)
|
|
|
|
def order():
|
|
saved = settings()
|
|
return [int(saved[f"launcher_favorite_{i}"]) for i in range(int(saved["launcher_favorite_count"]))]
|
|
|
|
def sidebars():
|
|
"""Every widget left of the Appearance panel, where it sits."""
|
|
return [(node["key"], node["x"], node["y"], node["width"], node["height"])
|
|
for node in driver.tree() if node["visible"] and node["x"] + node["width"] <= 344]
|
|
|
|
@contextlib.contextmanager
|
|
def application(name):
|
|
log_path = OUTPUT / (name + ".log")
|
|
with log_path.open("w") as log:
|
|
app = subprocess.Popen([str(BINARY)], cwd=ROOT, env=env, stdout=log, stderr=subprocess.STDOUT)
|
|
driver.attach(app, log_path)
|
|
try:
|
|
deadline = time.monotonic() + 15
|
|
window = ""
|
|
while time.monotonic() < deadline:
|
|
assert app.poll() is None, log_path.read_text()
|
|
found = subprocess.run(["xdotool", "search", "--onlyvisible", "--pid", str(app.pid)],
|
|
env=env, capture_output=True, text=True, timeout=2)
|
|
if found.returncode == 0 and (profile / "inbe.db").exists():
|
|
window = found.stdout.splitlines()[0]
|
|
break
|
|
time.sleep(.05)
|
|
assert window, log_path.read_text()
|
|
command("xdotool", "windowsize", window, "900", "720")
|
|
command("xdotool", "windowmove", window, "0", "0")
|
|
driver.wait_idle(frames=3)
|
|
yield window, log_path
|
|
assert app.poll() is None, log_path.read_text()
|
|
assert "frame rejected" not in log_path.read_text(), log_path.read_text()
|
|
finally:
|
|
stop(app)
|
|
|
|
# Create the real storage schema, then seed only this disposable profile.
|
|
with application("prepare"):
|
|
pass
|
|
with sqlite3.connect(profile / "inbe.db") as db:
|
|
user = db.execute("SELECT id FROM users WHERE kind='local' LIMIT 1").fetchone()[0]
|
|
values = {"language": "en", "language_system": 0, "language_setup_done": 1,
|
|
"apps_setup_done": 1, "launcher_guide_seen": 1,
|
|
"enabled_apps": 22, "lumi_introduced": 1,
|
|
"main_tab": 1, "tutorial_seen": 1, "habits_guide_seen": 1, "lumi_guides_seen": 127, "ui_scale": 10, "navigation_placement": 1,
|
|
"navigation_collapsed": 0, "package_updates_allowed": 0,
|
|
"apps_last_update_check": 1900000000,
|
|
"launcher_favorite_count": 2, "launcher_favorite_0": 12, "launcher_favorite_1": 1,
|
|
"bottom_nav_route_count": 4, "bottom_nav_route_0": 12,
|
|
"bottom_nav_route_1": 1, "bottom_nav_route_2": 2, "bottom_nav_route_3": 4}
|
|
for bit, name in enumerate(("lists", "habits", "practices", "diary", "lumi", "leaderboard")):
|
|
values["app_used_" + name] = int(bool(int(values["enabled_apps"]) & (1 << bit)))
|
|
for key, value in values.items():
|
|
db.execute("INSERT INTO settings(user_id,key,value,updated_at) VALUES(?,?,?,2) "
|
|
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value,updated_at=excluded.updated_at", (user, key, str(value)))
|
|
db.execute("INSERT INTO elist_lists(id,user_id,title,sort_order,deleted_at,updated_at) "
|
|
"VALUES('settings-preserved-list',?,'Keep this saved list',0,0,1)", (user,))
|
|
db.execute("INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,updated_at) "
|
|
"VALUES('settings-preserved-habit',?,'Keep this habit',1,2,3,0,0,0,1)", (user,))
|
|
|
|
with application("gestures") as (window, log):
|
|
driver.press(label="Apps", role="button")
|
|
driver.press(label="Settings", role="button")
|
|
# The Settings app, not another one, opened on its categories.
|
|
driver.wait(label="Device", role="button")
|
|
driver.press(contains="Appearance")
|
|
driver.wait(contains="Scale factor")
|
|
slider = driver.wait(role="slider")
|
|
x, y = UiDriver.center(slider)
|
|
driver.pointer(x, y)
|
|
driver.pointer(x, y, down=True)
|
|
driver.wait_idle(frames=3)
|
|
before = sidebars()
|
|
assert before, "No sidebar widgets to compare during the drag"
|
|
left, right = slider["x"] + 4, slider["x"] + slider["width"] - 4
|
|
for x_moved, y_moved in ((left, y + 10), (right, y + 12), (left + 30, y - 8), (right - 15, y + 5)):
|
|
driver.pointer(x_moved, y_moved, down=True)
|
|
assert settings()["ui_scale"] == "10", "Scale changed while the slider was held"
|
|
moved = [node for node in sidebars() if node not in before]
|
|
assert not moved, f"Sidebars moved during drag: {moved}"
|
|
driver.pointer(right - 15, y + 5, down=False)
|
|
driver.release_pointer()
|
|
deadline = time.monotonic() + 5
|
|
while settings()["ui_scale"] == "10":
|
|
assert time.monotonic() < deadline, "Release did not commit the scale"
|
|
time.sleep(.05)
|
|
driver.key(ord("0"), control=True)
|
|
wait_setting("ui_scale", 10)
|
|
driver.wait_idle(frames=3)
|
|
assert not driver.find(contains="Apps and favorites"), "Removed panel remains in Settings"
|
|
assert order() == [12, 1], "Settings changed the favorite order"
|
|
assert settings()["enabled_apps"] == "22"
|
|
|
|
with application("restart") as (window, log):
|
|
assert order() == [12, 1], "Settings changes altered saved favorites"
|
|
assert settings()["enabled_apps"] == "22"
|
|
with sqlite3.connect(profile / "inbe.db") as db:
|
|
assert db.execute("SELECT title FROM elist_lists WHERE id='settings-preserved-list'").fetchone() == ("Keep this saved list",)
|
|
assert db.execute("SELECT name FROM habits WHERE id='settings-preserved-habit'").fetchone() == ("Keep this habit",)
|
|
|
|
print("Settings: scale commits on release; Apps and Favorites removed; saved data preserved")
|