11/*
2- * Copyright (c) 2010, 2020 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2010, 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525
2626package test .javafx .scene .control ;
2727
28+ import javafx .collections .FXCollections ;
29+ import javafx .scene .control .ComboBox ;
30+ import javafx .scene .control .Tab ;
31+ import javafx .scene .control .TabPane ;
32+ import org .junit .After ;
2833import test .com .sun .javafx .scene .control .infrastructure .StageLoader ;
2934import javafx .css .CssMetaData ;
3035import static test .com .sun .javafx .scene .control .infrastructure .ControlTestUtils .*;
5358import org .junit .Before ;
5459import org .junit .Test ;
5560
61+ import java .util .concurrent .atomic .AtomicInteger ;
62+
5663/**
5764 *
5865 * @author srikalyc
@@ -65,6 +72,7 @@ public class SplitPaneTest {
6572 private Scene scene ;
6673 private Stage stage ;
6774 private StackPane root ;
75+ private StageLoader stageLoader ;
6876
6977 @ Before public void setup () {
7078 tk = (StubToolkit )Toolkit .getToolkit ();//This step is not needed (Just to make sure StubToolkit is loaded into VM)
@@ -79,6 +87,11 @@ public class SplitPaneTest {
7987 stage .setScene (scene );
8088 }
8189
90+ @ After
91+ public void cleanup () {
92+ if (stageLoader != null ) stageLoader .dispose ();
93+ }
94+
8295 /*********************************************************************
8396 * Helper methods (NOTE TESTS) *
8497 ********************************************************************/
@@ -1329,4 +1342,56 @@ private double convertDividerPostionToAbsolutePostion(double pos, double edge) {
13291342
13301343 sl .dispose ();
13311344 }
1345+
1346+ /**
1347+ * Verifies that a divider position change of the {@link SplitPane} does not hang the layout.
1348+ * Previously, this may happen when the divider position changed to a large number (>1),
1349+ * which can hang the layout as it resulted in multiple layout requests (through SplitPaneSkin.layoutChildren).
1350+ * See also: JDK-8277122
1351+ */
1352+ @ Test
1353+ public void testDividerOverOneDoesNotHangLayout () {
1354+ testSetDividerPositionDoesNotHangLayout (10 );
1355+ }
1356+
1357+ /**
1358+ * Verifies that a divider position change of the {@link SplitPane} does not hang the layout.
1359+ * Previously, this may happen when the divider position changed to a negative number (<1),
1360+ * which can hang the layout as it resulted in multiple layout requests (through SplitPaneSkin.layoutChildren).
1361+ * See also: JDK-8277122
1362+ */
1363+ @ Test
1364+ public void testDividerUnderZeroDoesNotHangLayout () {
1365+ testSetDividerPositionDoesNotHangLayout (-1 );
1366+ }
1367+
1368+ private void testSetDividerPositionDoesNotHangLayout (double dividerPosition ) {
1369+ AtomicInteger layoutCounter = new AtomicInteger ();
1370+ ComboBox <String > cbx = new ComboBox <>(FXCollections .observableArrayList ("1" , "2" , "3" )) {
1371+ @ Override
1372+ protected void layoutChildren () {
1373+ layoutCounter .incrementAndGet ();
1374+ super .layoutChildren ();
1375+ }
1376+ };
1377+ SplitPane pane = new SplitPane (new Label ("AAAAA" ), new TabPane (new Tab ("Test" , cbx )));
1378+ StackPane root = new StackPane (pane );
1379+
1380+ stageLoader = new StageLoader (root );
1381+
1382+ Toolkit .getToolkit ().firePulse ();
1383+
1384+ pane .setDividerPosition (0 , dividerPosition );
1385+
1386+ Toolkit .getToolkit ().firePulse ();
1387+
1388+ // Reset layout counter
1389+ layoutCounter .set (0 );
1390+
1391+ cbx .getSelectionModel ().select (0 );
1392+ Toolkit .getToolkit ().firePulse ();
1393+
1394+ assertTrue (layoutCounter .get () > 0 );
1395+ }
1396+
13321397}
0 commit comments