Fix overlay drop ordering and qualify native docking test setup

Hit-test expanded overlays before the docked content they cover. Share tab detachment and group-settings capture across lifecycle paths.

Native fixtures establish their initial OS focus with one client click. Geometry setup waits for the requested client width before creating the split, avoiding a ratio constrained by the previous native size. Transfer assertions remain unchanged.

Verified 329 fx tests and 34 example tests with all five native test options enabled.
This commit is contained in:
2026-11-16 01:28:48 +01:00
parent 01af6c6a0c
commit a35664dabe
10 changed files with 205 additions and 44 deletions
@@ -51,6 +51,7 @@ class FloatingNativeFocusTest {
Fixture fixture = fixture();
AtomicReference<Stage> firstFloating = new AtomicReference<>();
try {
NativeFixtureFocus.establish(robot, fixture.notes);
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_1, "1");
FxThread.onFx(() -> {
command(fixture.notes, "Float", null);
@@ -147,14 +147,17 @@ class FloatingWindowGeometryTest {
AtomicReference<Double> ratio = new AtomicReference<>();
AtomicReference<Point> start = new AtomicReference<>();
try {
FxThread.onFx(() -> fixture.floating.setWidth(760));
awaitClientWidth(fixture.floating, 740);
FxThread.onFx(() -> {
fixture.floating.setWidth(760);
var window = fixture.manager.layout().windows().stream().filter(candidate -> !candidate.main()).findFirst().orElseThrow();
var group = window.areas().getFirst().groups().getFirst().id();
Dockable anchor = new Dockable(new DockableId("anchor"), new TextArea("Anchor"));
fixture.manager.open(anchor, DockTarget.group(group));
fixture.manager.move(anchor.getId(), DockTarget.split(group, Side.RIGHT));
fixture.manager.updateGroup(group, DockGroupChanges.builder().minimumWidth(320).build());
// Make this minimum active at the starting width as well: even a short native
// shrink must change the live ratio before testing committed publication.
fixture.manager.updateGroup(group, DockGroupChanges.builder().minimumWidth(500).build());
});
Thread.sleep(400);
FxThread.onFx(() -> {
@@ -200,6 +203,17 @@ class FloatingWindowGeometryTest {
}
}
private static void awaitClientWidth(Stage stage, double minimum) throws Exception {
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
AtomicReference<Boolean> ready = new AtomicReference<>(false);
do {
Thread.sleep(25);
FxThread.onFx(() -> ready.set(stage.getScene().getWidth() >= minimum
&& stage.getScene().getRoot().getLayoutBounds().getWidth() >= minimum));
} while (!ready.get() && System.nanoTime() < deadline);
assertTrue(ready.get(), "The native window's client layout must reach the starting width before splitting");
}
private static DockLayoutView.Split publishedSplit(DockingManager manager) {
var area = manager.layout().windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().areas().getFirst();
return assertInstanceOf(DockLayoutView.Split.class, area.root());
@@ -50,6 +50,7 @@ class NativeDockDragTest {
var watchdog = Executors.newSingleThreadScheduledExecutor();
watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 20, TimeUnit.SECONDS);
try {
NativeFixtureFocus.establish(robot, f.notes);
await(() -> f.main.isFocused(), "Initial main window must be focused");
Point outside = onFx(() -> {
var screen = Screen.getPrimary().getVisualBounds();
@@ -131,6 +132,7 @@ class NativeDockDragTest {
var watchdog = Executors.newSingleThreadScheduledExecutor();
watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 25, TimeUnit.SECONDS);
try {
NativeFixtureFocus.establish(robot, f.notes);
await(() -> source.get().isFocused(), "The initial source window must have focus");
var before = onFx(f.manager::layout);
drag(robot, onFx(() -> headerPoint(f.notes)), onFx(() -> center(readme.get())), () -> FxThread.onFx(() -> {
@@ -190,6 +192,7 @@ class NativeDockDragTest {
var watchdog = Executors.newSingleThreadScheduledExecutor();
watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 20, TimeUnit.SECONDS);
try {
NativeFixtureFocus.establish(robot, f.notes);
await(() -> source.get().isFocused(), "The initial floating source must be focused");
var initial = onFx(f.manager::layout);
drag(robot, onFx(() -> headerPoint(f.notes)), onFx(() -> headerPoint(project.get())), () -> FxThread.onFx(() -> {
@@ -0,0 +1,52 @@
package de.neitzel.fx.view;
import javafx.geometry.Bounds;
import javafx.scene.control.IndexRange;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** Establishes the starting desktop state once; never used to repair focus after a tested operation. */
final class NativeFixtureFocus {
private NativeFixtureFocus() { }
static void establish(Robot robot, TextArea editor) throws Exception {
Point original = MouseInfo.getPointerInfo().getLocation();
AtomicReference<Point> client = new AtomicReference<>();
AtomicReference<IndexRange> selection = new AtomicReference<>();
FxThread.onFx(() -> {
Stage stage = (Stage) editor.getScene().getWindow();
stage.toFront();
editor.getScene().getRoot().applyCss();
editor.getScene().getRoot().layout();
selection.set(editor.getSelection());
Bounds bounds = editor.localToScreen(editor.getBoundsInLocal());
client.set(new Point((int) bounds.getCenterX(), (int) bounds.getCenterY()));
});
try {
robot.mouseMove(client.get().x, client.get().y);
try { robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); }
finally { robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); }
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
AtomicReference<Boolean> focused = new AtomicReference<>(false);
do {
Thread.sleep(25);
FxThread.onFx(() -> focused.set(editor.getScene().getWindow().isFocused()
&& editor.getScene().getFocusOwner() == editor));
} while (!focused.get() && System.nanoTime() < deadline);
assertTrue(focused.get(), "The initial editor click must establish native window and content focus");
FxThread.onFx(() -> editor.selectRange(selection.get().getStart(), selection.get().getEnd()));
} finally {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(original.x, original.y);
}
}
}
@@ -133,6 +133,61 @@ class OverlayDockDropTest {
});
}
@ParameterizedTest
@EnumSource(Side.class)
void expandedOverlayContentReceivesDropsAboveTheUnderlyingEditor(Side side) throws Exception {
FxThread.onFx(() -> {
DockLayout initial = new DockLayout();
initial.setCenter(new DockGroupDefinition("editors"));
DockGroupDefinition tools = new DockGroupDefinition("tools");
tools.setCollapsible(true);
tools.setMode(DockGroupMode.OVERLAY);
tools.setTabSide(side);
tools.setPreferredWidth(240);
tools.setPreferredHeight(190);
tools.setSplitDirections(de.neitzel.fx.docking.SplitDirections.NONE);
edge(initial, side, tools);
DockPane pane = new DockPane();
pane.setInitialLayout(initial);
Stage stage = new Stage();
stage.setScene(new Scene(pane, 900, 600));
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
Dockable editor = new Dockable(new DockableId("editor"), new TextArea("Editor"));
Dockable first = new Dockable(new DockableId("first"), new TextArea("Unsaved first"));
first.setTitle("First");
Dockable second = new Dockable(new DockableId("second"), new TextArea("Second"));
second.setTitle("Second");
manager.open(editor, DockTarget.area("editors"));
manager.open(first, DockTarget.area("tools"));
manager.open(second, DockTarget.area("tools"));
stage.show();
try {
pane.applyCss();
pane.layout();
TabPane overlay = tabs(pane, first.getId());
Bounds into = second.getContent().localToScreen(second.getContent().getBoundsInLocal());
double x = into.getCenterX();
double y = into.getCenterY();
Bounds underneath = tabs(pane, editor.getId()).localToScreen(
tabs(pane, editor.getId()).getBoundsInLocal());
assertTrue(underneath.contains(x, y), "The visible overlay content covers the editor drop surface");
assertFalse(group(manager).collapsed());
Node sourceHeader = header(overlay, first.getId());
Bounds from = sourceHeader.localToScreen(sourceHeader.getBoundsInLocal());
mouse(sourceHeader, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
mouse(sourceHeader, MouseEvent.MOUSE_DRAGGED, x, y, true);
assertTrue(pane.lookup(".dock-drop-indicator").isVisible());
mouse(sourceHeader, MouseEvent.MOUSE_RELEASED, x, y, false);
assertEquals(java.util.List.of(second.getId(), first.getId()), group(manager).dockableIds(),
"A drop on overlay content appends within that visible group");
assertEquals(java.util.List.of(editor.getId()), group(manager, "editors").dockableIds());
assertSame(first, manager.activeDockable());
assertSame(first.getContent(), overlay.getSelectionModel().getSelectedItem().getContent());
assertFalse(group(manager).collapsed());
} finally { stage.hide(); }
});
}
private static void edge(DockLayout layout, Side side, DockGroupDefinition group) {
switch (side) {
case LEFT -> layout.setLeft(group);