Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ jobs:
save-if: 'true'

# The capture needs a rendered window, which xvfb gives; maximising one is a window
# manager's answer (`44_window_controls`), which openbox gives.
# manager's answer (journey 13), which openbox gives.
- name: X server
if: runner.os == 'Linux'
run: sudo apt-get install -y --no-install-recommends xvfb openbox
Expand Down
15 changes: 13 additions & 2 deletions crates/app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use platform::autostart::Autostart;
use platform::dialog::FileDialog;
use platform::shortcuts::Shortcuts;
use platform::tray::{NoTray, Picture, Tray};
use platform::updater::Source;
use platform::updater::{Source, Updater};
use ui::{Inbox, Input, Preferences, Settings};

/// Who sends a toast on Windows.
Expand All @@ -30,12 +30,23 @@ pub(crate) fn start(preferences: &Preferences, inbox: &Inbox) -> ui::Desktop {
autostart: autostart(),
notifier: platform::notify::system(METADATA.name, IDENTIFIER),
dialog: dialog(inbox.clone()),
updater: platform::updater::system(&UPDATES),
updater: updater(),
clipboard: platform::clipboard::system(),
opener: platform::desktop::system(),
}
}

#[cfg(not(feature = "e2e"))]
fn updater() -> Arc<dyn Updater + Send + Sync> {
platform::updater::system(&UPDATES)
}

/// A scenario is asked by nobody but the server it serves itself.
#[cfg(feature = "e2e")]
fn updater() -> Arc<dyn Updater + Send + Sync> {
platform::updater::from_scenario(&UPDATES)
}

fn dialog(inbox: Inbox) -> Arc<dyn FileDialog + Send + Sync> {
platform::dialog::system(move || inbox.post(Input::NoFileDialog))
}
Expand Down
7 changes: 7 additions & 0 deletions crates/platform/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
//! then installed once the application has finished leaving (D26). Nothing installs
//! without an explicit gesture, and deb and rpm packages do not update themselves.

#[cfg(feature = "e2e")]
mod scenario;
mod system;
#[cfg(test)]
mod tests;

#[cfg(feature = "e2e")]
pub use scenario::system as from_scenario;
pub use system::{Source, system};

/// Where a scenario serves the `latest.json` the `e2e` flavour asks for.
pub const E2E_UPDATES: &str = "DEVNOTES_E2E_UPDATES";

/// A version the updater found.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AvailableUpdate {
Expand Down
15 changes: 15 additions & 0 deletions crates/platform/src/updater/scenario.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! The `e2e` flavour's updater: the real one, on the server a scenario serves. ⚠️ Without one it
//! asks nobody: a published version would be offered in the middle of a scenario.

use std::sync::Arc;

use super::system::{Source, built};
use super::{E2E_UPDATES, NoUpdater, Updater};

pub fn system(source: &Source<'_>) -> Arc<dyn Updater + Send + Sync> {
let Ok(endpoint) = std::env::var(E2E_UPDATES) else {
return Arc::new(NoUpdater);
};
let served = Source { endpoint: &endpoint, ..*source };
built(&served, true).map_or_else(|| Arc::new(NoUpdater) as _, |updater| Arc::new(updater) as _)
}
1 change: 1 addition & 0 deletions crates/platform/src/updater/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cargo_packager_updater::{Config, Error, Update, UpdaterBuilder};
use super::{AvailableUpdate, DownloadError, NoUpdater, Updater};

/// Where the releases are, and who signs them.
#[derive(Clone, Copy)]
pub struct Source<'a> {
/// The running version.
pub version: &'a str,
Expand Down
31 changes: 31 additions & 0 deletions e2e/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ impl Tree {
found
}

/// The ids on the screen that begin so: a list's rows, each wearing its own.
pub(crate) fn all_starting(&self, start: &str) -> Vec<&str> {
let ids = self.nodes.iter().filter_map(|(_, node)| node.author_id());
ids.filter(|id| id.starts_with(start)).collect()
}

/// What each node wearing `id` says, in reading order.
pub(crate) fn texts(&self, id: &str) -> Vec<String> {
self.all(id).into_iter().map(said).collect()
}

pub(crate) fn count(&self, id: &str) -> usize {
self.all(id).len()
}
Expand Down Expand Up @@ -101,6 +112,16 @@ pub(crate) fn said(node: &Node) -> String {
node.label().or(node.value()).unwrap_or_default().to_owned()
}

/// Whether a node stands inside a place: a control of a card, a card of a zone.
pub(crate) fn within(node: &Node, place: Rect) -> bool {
node.bounds().is_some_and(|bounds| {
bounds.x0 >= place.x0 - 1.0
&& bounds.x1 <= place.x1 + 1.0
&& bounds.y0 >= place.y0 - 1.0
&& bounds.y1 <= place.y1 + 1.0
})
}

pub(crate) fn top(node: &Node) -> f64 {
node.bounds().map_or(f64::INFINITY, |bounds| bounds.y0)
}
Expand Down Expand Up @@ -171,10 +192,20 @@ impl Driver {
}
}

/// Until egui has nothing left to draw: not until the core has answered.
pub(crate) fn settle(&mut self) {
self.ask(&Request::Settle { max_steps: 10 });
}

pub(crate) fn apply(&mut self, events: Vec<Event>) {
self.ask(&Request::ApplyEvents { events });
}

/// The directory of the profile the application runs on.
pub(crate) fn profile(&self) -> &Path {
&self.profile
}

/// The window as it stands, as `<output>/<journey>/<name>.png`.
pub(crate) fn capture(&mut self, name: &str) {
match self.ask(&Request::GetScreenshot { pixels_per_point: Some(1.0) }) {
Expand Down
221 changes: 221 additions & 0 deletions e2e/src/sdk/act.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//! What the areas are made of: a control found by its id, waited for, acted on. A failure says, in
//! the step it stops, what the person would have seen: each act takes the control's name for it.

use std::time::{Duration, Instant};

use egui::accesskit::{Node, Rect};
use egui::{Event, Key, Modifiers, PointerButton, Pos2};

use super::{App, Shortcut};
use crate::current_step;
use crate::driver::{PATIENCE, Tree, middle};

/// How far down a card the middle of its title's band is, in points.
const CARD_BAND: f32 = 14.0;
/// Clicks closer than this are one gesture to egui.
const DOUBLE_CLICK: Duration = Duration::from_millis(300);

impl App {
pub(super) fn tree(&mut self) -> Tree {
self.driver.tree()
}

/// Reads the screen until `holds` is true of it: answers arrive from the core frames later.
pub(super) fn expect(&mut self, says: &str, holds: impl Fn(&Tree) -> bool) {
self.seen(says, |tree| holds(tree).then_some(()));
}

/// What the screen shows once egui has nothing left to draw: for what must not be there.
pub(super) fn expect_at_rest(&mut self, says: &str, holds: impl Fn(&Tree) -> bool) {
self.driver.settle();
assert!(holds(&self.tree()), "« {} »: {says}", current_step());
}

/// What `find` finds on the screen, once it does. No pause between reads: each one renders a
/// frame.
pub(super) fn seen<T>(&mut self, says: &str, find: impl Fn(&Tree) -> Option<T>) -> T {
let until = Instant::now() + PATIENCE;
loop {
let tree = self.tree();
if let Some(found) = find(&tree) {
return found;
}
assert!(
Instant::now() < until,
"« {} »: {says} — still not so after {PATIENCE:?}; the keyboard is {}",
current_step(),
tree.keyboard()
);
}
}

/// Where a control stands, once it holds still: a node joins the tree a frame before it has a
/// place, and one still moving would be clicked where it no longer is.
pub(super) fn place(&mut self, name: &str, find: impl Fn(&Tree) -> Option<Rect>) -> Rect {
let says = format!("{name} is on the screen");
loop {
let first = self.seen(&says, &find);
if find(&self.tree()) == Some(first) {
return first;
}
}
}

pub(super) fn click(&mut self, id: &str, name: &str) {
self.click_where(id, name, |_| true);
}

/// The first `id` that `which` picks, in reading order.
pub(super) fn click_where(&mut self, id: &str, name: &str, which: impl Fn(&Node) -> bool) {
self.click_nth_where(id, 0, name, which);
}

/// The `n`th `id` in reading order, counting from 0.
pub(super) fn click_nth(&mut self, id: &str, n: usize, name: &str) {
self.click_nth_where(id, n, name, |_| true);
}

/// The `n`th `id` that `which` picks, in reading order, counting from 0.
pub(super) fn click_nth_where(&mut self, id: &str, n: usize, name: &str, which: impl Fn(&Node) -> bool) {
let bounds = self.place(name, |tree| {
let picked = tree.all(id).into_iter().filter(|node| which(node)).nth(n);
picked.and_then(Node::bounds)
});
self.click_at(middle(bounds), PointerButton::Primary);
}

/// A card by its title's band: a todo list's is mostly the boxes of its items.
pub(super) fn click_card(&mut self, card: Rect) {
#[expect(clippy::cast_possible_truncation, reason = "points on a screen")]
let band = Pos2::new(middle(card).x, card.y0 as f32 + CARD_BAND);
self.click_at(band, PointerButton::Primary);
}

fn click_at(&mut self, pos: Pos2, button: PointerButton) {
self.driver.apply(vec![Event::PointerMoved(pos)]);
self.driver.apply(vec![press(pos, button, true)]);
self.driver.apply(vec![press(pos, button, false)]);
self.clicked = Some(Instant::now());
}

/// Two clicks, sent together so that they are one double click however slowly the window draws.
/// ⚠️ A click just before makes egui count three, wherever it was: they wait their turn.
pub(super) fn double_click(&mut self, pos: Pos2) {
while self.clicked.is_some_and(|at| at.elapsed() < DOUBLE_CLICK) {
self.tree();
}
let click = || [true, false].map(|down| press(pos, PointerButton::Primary, down));
self.driver.apply(vec![Event::PointerMoved(pos)]);
self.driver.apply([click(), click()].concat());
self.clicked = Some(Instant::now());
}

/// The pointer over a place: what a card shows on hover.
pub(super) fn move_over(&mut self, bounds: Rect) {
self.driver.apply(vec![Event::PointerMoved(middle(bounds))]);
}

/// Clicks a field, then types at the end of what it holds.
pub(super) fn fill(&mut self, id: &str, name: &str, text: &str) {
self.take_keyboard(id, name);
self.type_text(text);
}

/// Types over what a field holds. ⚠️ Not by a second click, which selects a word only within
/// the double click's delay: the machine's speed.
pub(super) fn replace(&mut self, id: &str, name: &str, text: &str) {
self.take_keyboard(id, name);
self.press(Shortcut::SelectAll);
self.type_text(text);
}

/// Clicks a field until it holds the keyboard: what is typed a frame early goes nowhere. ⚠️ A
/// click can land in a frame that drops it; the next comes a few frames later — two at once
/// would be a double click.
pub(super) fn take_keyboard(&mut self, id: &str, name: &str) {
let until = Instant::now() + PATIENCE;
loop {
self.click(id, name);
if (0..5).any(|_| self.tree().has_focus(id)) {
return;
}
assert!(Instant::now() < until, "« {} »: {name} never took the keyboard", current_step());
}
}

/// A key pressed and released at its place on the keyboard.
pub(super) fn key(&mut self, key: Key, modifiers: Modifiers) {
self.key_printed(key, key, modifiers);
}

/// As `key`, `printed` being what the layout prints on the key that stands at `place`.
pub(super) fn key_printed(&mut self, printed: Key, place: Key, modifiers: Modifiers) {
let physical_key = Some(place);
let event = |pressed| Event::Key { key: printed, physical_key, pressed, repeat: false, modifiers };
self.driver.apply(vec![event(true)]);
self.driver.apply(vec![event(false)]);
}

/// Scrolls `within` down until `find` finds its place, back from the top past its end: a list
/// draws only what is in view.
pub(super) fn scroll_to(
&mut self,
within: &str,
name: &str,
find: impl Fn(&Tree) -> Option<Rect>,
) -> Rect {
for notch in 0..60 {
let tree = self.tree();
let room = tree.find(within).and_then(Node::bounds);
let in_view =
|place: Rect| room.is_none_or(|room| place.y0 >= room.y0 && place.y1 <= room.y1 + 1.0);
if find(&tree).is_some_and(in_view) {
break;
}
// The first reads are the core's to answer.
match notch {
0..5 => {}
_ if notch % 20 == 19 => self.wheel(within, 100_000.0),
_ => self.wheel(within, -120.0),
}
}
self.place(name, find)
}

/// Scrolls `within` until a control stands above `foot`: a panel draws what lies past its edge
/// too, where no click reaches it.
pub(super) fn reach(&mut self, within: &str, (id, name): (&str, &str), foot: &str) {
self.expect(&format!("{name} is on the screen"), |tree| tree.has(id));
for _ in 0..60 {
let tree = self.tree();
let place = |id| tree.find(id).and_then(Node::bounds);
let above = place(id).zip(place(foot)).is_some_and(|(target, foot)| target.y1 < foot.y0);
if above {
return;
}
self.wheel(within, -120.0);
}
}

/// The wheel over `within`, in points: down is negative.
fn wheel(&mut self, within: &str, points: f32) {
let Some(bounds) = self.tree().find(within).and_then(Node::bounds) else {
return;
};
self.driver.apply(vec![
Event::PointerMoved(middle(bounds)),
Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: egui::vec2(0.0, points),
phase: egui::TouchPhase::Move,
source: egui::MouseWheelSource::Wheel,
modifiers: Modifiers::NONE,
},
]);
self.driver.settle();
}
}

fn press(pos: Pos2, button: PointerButton, pressed: bool) -> Event {
Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE }
}
Loading
Loading