Skip to content

Commit 0a20fef

Browse files
Gopaloraaghaisas
authored andcommitted
8327478: Add System test to verify TextSelection issue for webkit-617.1
Reviewed-by: kcr, angorya
1 parent fc770fb commit 0a20fef

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package test.robot.javafx.web;
27+
28+
import java.util.concurrent.CountDownLatch;
29+
30+
import javafx.concurrent.Worker;
31+
import javafx.scene.paint.Color;
32+
import javafx.scene.web.WebView;
33+
34+
import org.junit.jupiter.api.Assertions;
35+
import org.junit.jupiter.api.BeforeEach;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.Timeout;
38+
39+
import test.robot.testharness.RobotTestBase;
40+
import test.util.Util;
41+
42+
public class TextSelectionTest extends RobotTestBase {
43+
44+
private static final String html = """
45+
<html>
46+
<body><font size="2">&nbsp&nbsp&nbsp&nbsp some text</font></body>
47+
</html>
48+
""";
49+
50+
private static CountDownLatch webviewLoadLatch = new CountDownLatch(1);
51+
private volatile Color colorBefore;
52+
private volatile Color colorAfter;
53+
54+
@BeforeEach
55+
public void beforeEach() {
56+
Util.runAndWait(() -> {
57+
WebView webview = new WebView();
58+
webview.getEngine().getLoadWorker().stateProperty().addListener((ov, o, n) -> {
59+
if (n == Worker.State.SUCCEEDED) {
60+
webviewLoadLatch.countDown();
61+
}
62+
});
63+
webview.getEngine().loadContent(html);
64+
contentPane.setCenter(webview);
65+
});
66+
Util.waitForLatch(webviewLoadLatch, 10, "Timeout waiting for web content to load");
67+
}
68+
69+
// ========================== TEST CASE ==========================
70+
@Test
71+
@Timeout(value=20)
72+
public void testTextSelection() {
73+
74+
int x = (int)(scene.getWindow().getX() + scene.getX() + 22);
75+
int y = (int)(scene.getWindow().getY() + scene.getY() + 15);
76+
77+
Util.parkCursor(robot);
78+
Util.runAndWait(() -> colorBefore = robot.getPixelColor(x, y));
79+
80+
Util.runAndWait(() -> robot.mouseMove(x, y));
81+
Util.doubleClick(robot);
82+
Util.sleep(500); // Wait for the selection highlight to be drawn
83+
84+
Util.parkCursor(robot);
85+
Util.runAndWait(() -> colorAfter = robot.getPixelColor(x, y));
86+
87+
Assertions.assertNotEquals(colorBefore, colorAfter,
88+
"Selection color did not change after double click");
89+
}
90+
}

tests/system/src/test/java/test/util/Util.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javafx.application.Application;
4242
import javafx.application.Platform;
4343
import javafx.geometry.Rectangle2D;
44+
import javafx.scene.input.MouseButton;
4445
import javafx.scene.Node;
4546
import javafx.scene.Scene;
4647
import javafx.scene.layout.Region;
@@ -333,6 +334,19 @@ public static void waitForLatch(CountDownLatch latch, int seconds, String msg) {
333334
}
334335
}
335336

337+
/**
338+
* Makes double click of the mouse left button.
339+
*/
340+
public static void doubleClick(Robot robot) {
341+
runAndWait(() -> {
342+
robot.mouseClick(MouseButton.PRIMARY);
343+
});
344+
sleep(50);
345+
runAndWait(() -> {
346+
robot.mouseClick(MouseButton.PRIMARY);
347+
});
348+
}
349+
336350
/**
337351
* Moves the cursor outside of the Stage to avoid it interfering with Robot tests.
338352
* The cursor is moved to a point close to the lower right corner of the primary screen,

0 commit comments

Comments
 (0)