Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8327478: Add System test to verify TextSelection issue for webkit-617.1 #1719

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package test.robot.javafx.web;

import java.util.concurrent.CountDownLatch;

import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.scene.paint.Color;
import javafx.scene.robot.Robot;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import test.util.Util;

public class TextSelectionTest {

private static final String html = "<html>" +
"<head></head> " +
"<body>&nbsp&nbsp&nbsp&nbsp some text</body>" +
"</html>";

private static CountDownLatch startupLatch = new CountDownLatch(1);
private static CountDownLatch webviewLoadLatch = new CountDownLatch(1);
private static Scene scene;
private static Robot robot;
private Color colorBefore;
private Color colorAfter;

public static class TestApp extends Application {
@Override
public void start(Stage primaryStage) {

robot = new Robot();
WebView webview = new WebView();
scene = new Scene(webview, 400, 300);
primaryStage.setScene(scene);
primaryStage.setAlwaysOnTop(true);

webview.getEngine().getLoadWorker().stateProperty().addListener((ov, o, n) -> {
if (n == Worker.State.SUCCEEDED) {
webviewLoadLatch.countDown();
}
});
webview.getEngine().loadContent(html);
primaryStage.setOnShown(e -> startupLatch.countDown());
primaryStage.show();
}
}

@BeforeAll
public static void initFX() {
Util.launch(startupLatch, TestApp.class);
Util.waitForLatch(webviewLoadLatch, 10, "Timeout waiting for web content to load");
}

@AfterAll
public static void teardown() {
Util.shutdown();
}

// ========================== TEST CASE ==========================
@Test
@Timeout(value=20)
public void testTextSelection() throws Exception {

int x = (int)(scene.getWindow().getX() + scene.getX() + 22);
int y = (int)(scene.getWindow().getY() + scene.getY() + 15);

Util.parkCursor(robot);
Util.runAndWait(() -> colorBefore = robot.getPixelColor(x, y));

Util.doubleClick(robot, x, y);
Util.sleep(500); // Wait for the selection highlight to be drawn

Util.parkCursor(robot);
Util.runAndWait(() -> colorAfter = robot.getPixelColor(x, y));

Assertions.assertNotEquals(colorBefore, colorAfter,
"Selection color did not change after double click");
}
}
15 changes: 15 additions & 0 deletions tests/system/src/test/java/test/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Rectangle2D;
import javafx.scene.input.MouseButton;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
Expand Down Expand Up @@ -333,6 +334,20 @@ public static void waitForLatch(CountDownLatch latch, int seconds, String msg) {
}
}

/**
* Makes double click of the mouse left button.
*/
public static void doubleClick(Robot robot, int x, int y) {
runAndWait(() -> {
robot.mouseMove(x, y);
robot.mouseClick(MouseButton.PRIMARY);
});
sleep(50);
runAndWait(() -> {
robot.mouseClick(MouseButton.PRIMARY);
});
}

/**
* Moves the cursor outside of the Stage to avoid it interfering with Robot tests.
* The cursor is moved to a point close to the lower right corner of the primary screen,
Expand Down