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

8289587: IllegalArgumentException: Color.rgb's red parameter (-16776961) expects color values 0-255 #809

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
202 changes: 99 additions & 103 deletions tests/system/src/test/java/test/javafx/scene/web/ColorChooserTest.java
Original file line number Diff line number Diff line change
@@ -38,136 +38,132 @@
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import test.util.Util;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class ColorChooserTest {
private static final CountDownLatch launchLatch = new CountDownLatch(1);

static ColorChooserTestApp colorChooserTestApp;
static volatile Stage stage;
static volatile ColorChooserTestApp colorChooserTestApp;

@Test
public void testColorChooser() {
colorChooserTestApp.startTest();
}

private WebView webView;
private Scene scene;
private int counter;
private final List<String> colors = List.of("#ff3300", "#3367ff", "#cc072d");
@BeforeAll
public static void setupOnce() {
new Thread(() -> Application.launch(ColorChooserTestApp.class, (String[]) null)).start();
Assertions.assertTrue(Util.await(launchLatch), "Timeout waiting for FX runtime to start");
}

@AfterAll
public static void tearDownOnce() {
Platform.runLater(stage::hide);
Platform.exit();
}

public static class ColorChooserTestApp extends Application {
Stage primaryStage = null;

private WebView webView;
private Scene scene;
private int counter;
private final List<String> colors = List.of("#ff3300", "#3367ff", "#cc072d");

@Override
public void init() {
ColorChooserTest.colorChooserTestApp = this;
colorChooserTestApp = this;
}

@Override
public void start(Stage primaryStage) throws Exception {
Platform.setImplicitExit(false);
this.primaryStage = primaryStage;
launchLatch.countDown();
}
}
stage = primaryStage;

@BeforeClass
public static void setupOnce() {
// Start the Test Application
new Thread(() -> Application.launch(ColorChooserTestApp.class, (String[])null)).start();

assertTrue("Timeout waiting for FX runtime to start", Util.await(launchLatch));
}

@AfterClass
public static void tearDownOnce() {
Platform.exit();
}

@Before
public void setupTestObjects() {
Platform.runLater(() -> {
webView = new WebView();
scene = new Scene(webView);
colorChooserTestApp.primaryStage.setScene(scene);
colorChooserTestApp.primaryStage.setAlwaysOnTop(true);
colorChooserTestApp.primaryStage.setWidth(300);
colorChooserTestApp.primaryStage.setHeight(300);
colorChooserTestApp.primaryStage.show();
});
}
stage.setScene(scene);
stage.setAlwaysOnTop(true);
stage.setWidth(300);
stage.setHeight(300);
stage.setOnShown(e -> launchLatch.countDown());
stage.show();
}

@Test public void testColorChooser() {
final CountDownLatch webViewStateLatch = new CountDownLatch(2);

Util.runAndWait(() -> {
assertNotNull(webView);
Window.getWindows().addListener((ListChangeListener<Window>) change -> {
while (change.next()) {
if (change.wasAdded()) {
change.getAddedSubList().stream()
.filter(w -> w.getScene().getRoot() instanceof CustomColorDialog)
.findFirst()
.map(w -> (CustomColorDialog) w.getScene().getRoot())
.ifPresent(dialog -> {
assertEquals(dialog.getCurrentColor(), Color.web(colors.get(counter - 1)));
dialog.setCustomColor(Color.web(colors.get(counter)));
HBox box = (HBox) dialog.lookup("#buttons-hbox");
Button ok = (Button) box.getChildren().get(0);
Platform.runLater(() -> {
ok.fire();
webViewStateLatch.countDown();
public void startTest() {
final CountDownLatch webViewStateLatch = new CountDownLatch(2);

Util.runAndWait(() -> {
Assertions.assertNotNull(webView);
Window.getWindows().addListener((ListChangeListener<Window>) change -> {
while (change.next()) {
if (change.wasAdded()) {
change.getAddedSubList().stream()
.filter(w -> w.getScene().getRoot() instanceof CustomColorDialog)
.findFirst()
.map(w -> (CustomColorDialog) w.getScene().getRoot())
.ifPresent(dialog -> {
Assertions.assertEquals(dialog.getCurrentColor(), Color.web(colors.get(counter - 1)));
dialog.setCustomColor(Color.web(colors.get(counter)));
HBox box = (HBox) dialog.lookup("#buttons-hbox");
Button ok = (Button) box.getChildren().get(0);
Platform.runLater(() -> {
ok.fire();
webViewStateLatch.countDown();
});
});
});
}
}
}
});
webView.getEngine().setOnAlert(event -> {
Assertions.assertNotNull(event.getData());
Assertions.assertEquals(event.getData(), "color: " + colors.get(counter++));
});
webView.getEngine().loadContent("<head>" +
"<script>" +
" function logColor(event) {" +
" var color = document.querySelector(\"#color\");\n" +
" alert(\"color: \" + color.value);" +
" }\n" +
" setTimeout(\n" +
" () => {\n" +
" var color = document.querySelector(\"#color\");\n" +
" color.addEventListener(\"change\", logColor, false);" +
" alert(\"color: \" + color.value);" +
" }, 100);" +
"</script>" +
"</head>" +
"<body>" +
" <input id=\"color\" type=\"color\" value=\"" + colors.get(0) + "\">" +
"</body>");
});
webView.getEngine().setOnAlert(event -> {
assertNotNull(event.getData());
assertEquals(event.getData(), "color: " + colors.get(counter++));
});
webView.getEngine().loadContent("<head>" +
"<script>" +
" function logColor(event) {" +
" var color = document.querySelector(\"#color\");\n" +
" alert(\"color: \" + color.value);" +
" }\n" +
" setTimeout(\n" +
" () => {\n" +
" var color = document.querySelector(\"#color\");\n" +
" color.addEventListener(\"change\", logColor, false);" +
" alert(\"color: \" + color.value);" +
" }, 100);" +
"</script>" +
"</head>" +
"<body>" +
" <input id=\"color\" type=\"color\" value=\"" + colors.get(0) + "\">" +
"</body>");
});

Util.sleep(100);
Util.runAndWait(() -> webView.requestFocus());
for (int i = 0; i < 2; i++) {
// the first time, it creates the dialog (fwkCreateAndShowColorChooser),
// the second time, it reuses it (fwkShowColorChooser)

Util.sleep(100);
Util.runAndWait(() -> {
webView.fireEvent(new MouseEvent(MouseEvent.MOUSE_PRESSED, 30,
15, (int) (scene.getWindow().getX() + scene.getX() + 30),
(int) (scene.getWindow().getY() + scene.getY() + 15), MouseButton.PRIMARY, 1,
false, false, false, false, true, false, false, true, false, false, null));
webView.fireEvent(new MouseEvent(MouseEvent.MOUSE_RELEASED, 30,
15, (int) (scene.getWindow().getX() + scene.getX() + 30),
(int) (scene.getWindow().getY() + scene.getY() + 15), MouseButton.PRIMARY, 1,
false, false, false, false, false, false, false, true, false, false, null));
});
Util.runAndWait(() -> webView.requestFocus());
for (int i = 0; i < 2; i++) {
// the first time, it creates the dialog (fwkCreateAndShowColorChooser),
// the second time, it reuses it (fwkShowColorChooser)
Util.sleep(100);
Util.runAndWait(() -> {
webView.fireEvent(new MouseEvent(MouseEvent.MOUSE_PRESSED, 30,
15, (int) (stage.getX() + scene.getX() + 30),
(int) (stage.getY() + scene.getY() + 15), MouseButton.PRIMARY, 1,
false, false, false, false, true, false, false, true, false, false, null));
webView.fireEvent(new MouseEvent(MouseEvent.MOUSE_RELEASED, 30,
15, (int) (stage.getX() + scene.getX() + 30),
(int) (stage.getY() + scene.getY() + 15), MouseButton.PRIMARY, 1,
false, false, false, false, false, false, false, true, false, false, null));
});
}
Assertions.assertTrue(Util.await(webViewStateLatch), "Timeout when waiting for color chooser");
}
assertTrue("Timeout when waiting for color chooser ", Util.await(webViewStateLatch));
}

}