diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-05-07 22:52:07 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-05-07 22:59:57 +0300 |
| commit | e9c6f08906143c3fec1ad1301d538bef4cbc1978 (patch) | |
| tree | c4a7642b9b58ebbd790da06ccedb59be8993ccd1 | |
| parent | 17343a6740bcc4ef4a87542b508620778032e3b5 (diff) | |
| download | niri-e9c6f08906143c3fec1ad1301d538bef4cbc1978.tar.gz niri-e9c6f08906143c3fec1ad1301d538bef4cbc1978.tar.bz2 niri-e9c6f08906143c3fec1ad1301d538bef4cbc1978.zip | |
Add a resize transaction client-server test
| -rw-r--r-- | src/tests/mod.rs | 1 | ||||
| -rw-r--r-- | src/tests/transactions.rs | 105 | ||||
| -rw-r--r-- | src/utils/transaction.rs | 2 |
3 files changed, 108 insertions, 0 deletions
diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 87841cbc..fdbb41ac 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -6,4 +6,5 @@ mod server; mod floating; mod fullscreen; +mod transactions; mod window_opening; diff --git a/src/tests/transactions.rs b/src/tests/transactions.rs new file mode 100644 index 00000000..0f81d8a8 --- /dev/null +++ b/src/tests/transactions.rs @@ -0,0 +1,105 @@ +use std::fmt::Write as _; + +use insta::assert_snapshot; +use niri_ipc::SizeChange; +use wayland_client::protocol::wl_surface::WlSurface; + +use super::client::ClientId; +use super::*; +use crate::layout::LayoutElement; +use crate::niri::Niri; + +fn format_window_sizes(niri: &Niri) -> String { + let mut buf = String::new(); + for (_out, mapped) in niri.layout.windows() { + let size = mapped.size(); + writeln!(&mut buf, "{} × {}", size.w, size.h).unwrap(); + } + buf +} + +fn create_window(f: &mut Fixture, id: ClientId, w: u16, h: u16) -> WlSurface { + let window = f.client(id).create_window(); + let surface = window.surface.clone(); + window.commit(); + f.roundtrip(id); + + let window = f.client(id).window(&surface); + window.attach_new_buffer(); + window.set_size(w, h); + window.ack_last_and_commit(); + f.roundtrip(id); + + surface +} + +#[test] +fn column_resize_waits_for_both_windows() { + let mut f = Fixture::new(); + f.add_output(1, (1920, 1080)); + let id = f.add_client(); + + let surface1 = create_window(&mut f, id, 100, 100); + let surface2 = create_window(&mut f, id, 200, 200); + f.double_roundtrip(id); + + let _ = f.client(id).window(&surface1).recent_configures(); + let _ = f.client(id).window(&surface2).recent_configures(); + + // Consume into one column. + f.niri().layout.consume_or_expel_window_left(None); + f.double_roundtrip(id); + + // Commit for the column consume. + let window = f.client(id).window(&surface1); + assert_snapshot!( + window.format_recent_configures(), + @"size: 936 × 516, bounds: 1888 × 1048, states: []" + ); + window.ack_last_and_commit(); + + let window = f.client(id).window(&surface2); + assert_snapshot!( + window.format_recent_configures(), + @"size: 936 × 516, bounds: 1888 × 1048, states: [Activated]" + ); + window.ack_last_and_commit(); + + f.double_roundtrip(id); + + // This should say 100 × 100 and 200 × 200. + assert_snapshot!(format_window_sizes(f.niri()), @r" + 100 × 100 + 200 × 200 + "); + + // Issue a resize. + f.niri() + .layout + .set_column_width(SizeChange::AdjustFixed(10)); + f.double_roundtrip(id); + + // Commit window 1 in response to resize. + let window = f.client(id).window(&surface1); + window.set_size(300, 300); + window.ack_last_and_commit(); + f.double_roundtrip(id); + + // This should still say 100 × 100 as we're waiting in a transaction for the second window. + assert_snapshot!(format_window_sizes(f.niri()), @r" + 100 × 100 + 200 × 200 + "); + + // Commit window 2 in response to resize. + let window = f.client(id).window(&surface2); + window.set_size(400, 400); + window.ack_last_and_commit(); + f.double_roundtrip(id); + + // This should say 300 × 300 and 400 × 400 as the transaction completed. + assert_snapshot!(format_window_sizes(f.niri()), @r" + 300 × 300 + 400 × 400 + "); +} diff --git a/src/utils/transaction.rs b/src/utils/transaction.rs index f4921947..74a5691e 100644 --- a/src/utils/transaction.rs +++ b/src/utils/transaction.rs @@ -93,6 +93,8 @@ impl Transaction { let _span = trace_span!("deadline timer", transaction = ?Weak::as_ptr(&inner)) .entered(); + // FIXME: come up with some way to control the deadline timer from tests. + #[cfg(not(test))] if let Some(inner) = inner.upgrade() { trace!("deadline reached, completing transaction"); inner.complete(); |
