On Tue, 21 Apr 2026 16:18:39 GMT, Ziad El Midaoui <[email protected]> 
wrote:

> Added Test to check caret visibility in `TextField` and dead space at 
> beginning/end of text.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Changes requested by angorya (Reviewer).

tests/system/src/test/java/test/robot/javafx/scene/TextFieldCaretVisibilityTest.java
 line 46:

> 44: 
> 45: public class TextFieldCaretVisibilityTest extends RobotTestBase {
> 46:     private static final double EPSILON = 2.0;

minor: rename to MARGIN maybe?

Greek epsilon (ε) in many tests refers to a small error appearing in floating 
point calculations, see
https://en.wikipedia.org/wiki/Machine_epsilon

tests/system/src/test/java/test/robot/javafx/scene/TextFieldCaretVisibilityTest.java
 line 78:

> 76: 
> 77:                 for (double width : TEST_WIDTHS) {
> 78:                     runAndWait(() -> field.setPrefWidth(width));

does not work: the actual width of the text field does not change.  you may 
need to change the layout: `setContent()` sets the center of a `BorderPane`, 
which forces the said Node to occupy full width.  You probably want to wrap it 
into an `HBox` maybe:

L74:

                setContent(new HBox(field));


Another thing is that you have too many TEST_WIDTHS, perhaps one large and one 
small would suffice.  The small one should be chosen to be rather narrow so as 
to cause horizontal scrolling:

    private static final double[] TEST_WIDTHS = { 600, 50 };


With these changes, the test fails as the caret is not visible in all cases.
(And it does not fail immediately, runs to the end and then fails)


org.opentest4j.AssertionFailedError: caret right edge outside clip (start, 
width=50.0): caret.maxX=283.734375 clip.maxX=39.5 ==> expected: <true> but was: 
<false>
        at 
org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
        at 
org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
        at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
        at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
        at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214)
        at 
test.robot.javafx.scene.TextFieldCaretVisibilityTest.assertCaretVisible(TextFieldCaretVisibilityTest.java:118)
        at 
test.robot.javafx.scene.TextFieldCaretVisibilityTest.lambda$5(TextFieldCaretVisibilityTest.java:86)
        at test.util.Util.lambda$0(Util.java:106)
        at 
javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$4(PlatformImpl.java:424)
        at 
javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)


(on macOS)

-------------

PR Review: https://git.openjdk.org/jfx/pull/2157#pullrequestreview-4155781014
PR Review Comment: https://git.openjdk.org/jfx/pull/2157#discussion_r3124959560
PR Review Comment: https://git.openjdk.org/jfx/pull/2157#discussion_r3125097186

Reply via email to