|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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.javafx.scene.control.skin; |
| 27 | + |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +import javafx.scene.Node; |
| 32 | +import javafx.scene.Scene; |
| 33 | +import javafx.scene.control.Tab; |
| 34 | +import javafx.scene.control.TabPane; |
| 35 | +import javafx.scene.control.skin.TabPaneSkin; |
| 36 | +import javafx.scene.control.skin.TabPaneSkinShim; |
| 37 | +import javafx.scene.layout.VBox; |
| 38 | +import javafx.stage.Stage; |
| 39 | + |
| 40 | +import org.junit.After; |
| 41 | +import org.junit.Before; |
| 42 | +import org.junit.Ignore; |
| 43 | +import org.junit.Test; |
| 44 | +import static org.junit.Assert.*; |
| 45 | + |
| 46 | +/** |
| 47 | + * Testing sync'ing of tab headers with tabs. |
| 48 | + * https://bugs.openjdk.java.net/browse/JDK-8222457 |
| 49 | + * https://bugs.openjdk.java.net/browse/JDK-8237602 |
| 50 | + * |
| 51 | + * All basically the same issue: the listChangeListener is not correctly |
| 52 | + * updating the tab headers. |
| 53 | + */ |
| 54 | +public class TabPaneSkinHeaderOrderTest { |
| 55 | + |
| 56 | + private Scene scene; |
| 57 | + private Stage stage; |
| 58 | + private VBox root; |
| 59 | + private TabPane tabPane; |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testSetAllCollectionWithAdditionalTabs() { |
| 63 | + List<Tab> combined = new ArrayList<>(tabPane.getTabs()); |
| 64 | + combined.add(combined.size(), new Tab("t6")); |
| 65 | + tabPane.getTabs().setAll(combined); |
| 66 | + assertSyncTabHeaders(); |
| 67 | + } |
| 68 | + |
| 69 | + @Ignore("JDK-8245528") |
| 70 | + @Test |
| 71 | + public void testSetExistingTabAtDifferentIndex() { |
| 72 | + Tab t5 = tabPane.getTabs().get(4); |
| 73 | + tabPane.getTabs().set(0, t5); |
| 74 | + assertSyncTabHeaders(); |
| 75 | + } |
| 76 | + |
| 77 | + @Ignore("JDK-8245528") |
| 78 | + // Does not fail in system test with tab header animations not disabled. |
| 79 | + // Does not fail with even number of tabs. |
| 80 | + // Looks like that it fails in scenarios when an existing tab's position is |
| 81 | + // same before and after the change in tabs list. |
| 82 | + @Test |
| 83 | + public void testSetAllReverse() { |
| 84 | + Tab t1 = tabPane.getTabs().get(0); |
| 85 | + Tab t2 = tabPane.getTabs().get(1); |
| 86 | + Tab t3 = tabPane.getTabs().get(2); |
| 87 | + Tab t4 = tabPane.getTabs().get(3); |
| 88 | + Tab t5 = tabPane.getTabs().get(4); |
| 89 | + tabPane.getTabs().setAll(t5, t4, t3, t2, t1); |
| 90 | + assertSyncTabHeaders(); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void testSetAllRandomwShuffles() { |
| 95 | + Tab t1 = tabPane.getTabs().get(0); |
| 96 | + Tab t2 = tabPane.getTabs().get(1); |
| 97 | + Tab t3 = tabPane.getTabs().get(2); |
| 98 | + Tab t4 = tabPane.getTabs().get(3); |
| 99 | + Tab t5 = tabPane.getTabs().get(4); |
| 100 | + |
| 101 | + tabPane.getTabs().setAll(t1, t3, t5, t2, t4); |
| 102 | + assertSyncTabHeaders(); |
| 103 | + |
| 104 | + tabPane.getTabs().setAll(t1, t4, t5); |
| 105 | + assertSyncTabHeaders(); |
| 106 | + |
| 107 | + // @Ignore("JDK-8245528") |
| 108 | + // tabPane.getTabs().setAll(t5, t3, t4, t1, t2); |
| 109 | + // assertSyncTabHeaders(); |
| 110 | + |
| 111 | + tabPane.getTabs().setAll(t4, new Tab("T1"), t5, t3); |
| 112 | + assertSyncTabHeaders(); |
| 113 | + |
| 114 | + tabPane.getTabs().setAll(new Tab("T2"), t2, t5, t4); |
| 115 | + assertSyncTabHeaders(); |
| 116 | + |
| 117 | + // @Ignore("JDK-8245528") |
| 118 | + // tabPane.getTabs().setAll(t3, t5, t4, t2, new Tab("T3")); |
| 119 | + // assertSyncTabHeaders(); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void testRetainSingle() { |
| 124 | + tabPane.getTabs().retainAll(tabPane.getTabs().get(2)); |
| 125 | + assertSyncTabHeaders(); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void testRetainMultiple() { |
| 130 | + tabPane.getTabs().retainAll(tabPane.getTabs().get(0), |
| 131 | + tabPane.getTabs().get(3)); |
| 132 | + assertSyncTabHeaders(); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void testRetainMultipleCollection() { |
| 137 | + List<Tab> retain = List.of(tabPane.getTabs().get(1), |
| 138 | + tabPane.getTabs().get(3)); |
| 139 | + tabPane.getTabs().retainAll(retain); |
| 140 | + assertSyncTabHeaders(); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + public void testRemoveSingleIndex() { |
| 145 | + tabPane.getTabs().remove(0); |
| 146 | + assertSyncTabHeaders(); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void testRemoveSingleTab() { |
| 151 | + tabPane.getTabs().remove(tabPane.getTabs().get(3)); |
| 152 | + assertSyncTabHeaders(); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testRemoveMultiple() { |
| 157 | + tabPane.getTabs().removeAll(tabPane.getTabs().get(0), |
| 158 | + tabPane.getTabs().get(2)); |
| 159 | + assertSyncTabHeaders(); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void testRemoveMultipleCollection() { |
| 164 | + List<Tab> remove = List.of(tabPane.getTabs().get(1), |
| 165 | + tabPane.getTabs().get(3)); |
| 166 | + tabPane.getTabs().removeAll(remove); |
| 167 | + assertSyncTabHeaders(); |
| 168 | + } |
| 169 | + |
| 170 | + @Test |
| 171 | + public void testRemoveFromTo() { |
| 172 | + tabPane.getTabs().remove(1, 3); |
| 173 | + assertSyncTabHeaders(); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void testAddSingleAtBeginning() { |
| 178 | + tabPane.getTabs().add(0, new Tab("t0")); |
| 179 | + assertSyncTabHeaders(); |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + public void testAddSingleAtEnd() { |
| 184 | + tabPane.getTabs().add(new Tab("t6")); |
| 185 | + assertSyncTabHeaders(); |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + public void testAddSingleAtEndIndex() { |
| 190 | + tabPane.getTabs().add(tabPane.getTabs().size(), new Tab("t6")); |
| 191 | + assertSyncTabHeaders(); |
| 192 | + } |
| 193 | + |
| 194 | + @Test |
| 195 | + public void testAddSingleInMiddle() { |
| 196 | + tabPane.getTabs().add(2, new Tab("tm")); |
| 197 | + assertSyncTabHeaders(); |
| 198 | + } |
| 199 | + |
| 200 | + @Ignore("JDK-8245528") |
| 201 | + @Test |
| 202 | + public void testAddSingleExistingTab() { |
| 203 | + tabPane.getTabs().add(1, tabPane.getTabs().get(3)); |
| 204 | + assertSyncTabHeaders(); |
| 205 | + } |
| 206 | + |
| 207 | + @Ignore("JDK-8245528") |
| 208 | + @Test |
| 209 | + public void testAddMultipleExistingTabsAtBeginning() { |
| 210 | + List<Tab> added = List.of(tabPane.getTabs().get(3), |
| 211 | + tabPane.getTabs().get(4)); |
| 212 | + tabPane.getTabs().addAll(0, added); |
| 213 | + assertSyncTabHeaders(); |
| 214 | + } |
| 215 | + |
| 216 | + @Test |
| 217 | + public void testAddCollectionAtBeginning() { |
| 218 | + List<Tab> added = List.of(new Tab("t-1"), new Tab("t0")); |
| 219 | + tabPane.getTabs().addAll(0, added); |
| 220 | + assertSyncTabHeaders(); |
| 221 | + } |
| 222 | + |
| 223 | + @Test |
| 224 | + public void testAddMultipleAtEnd() { |
| 225 | + tabPane.getTabs().addAll(new Tab("t6"), new Tab("t7")); |
| 226 | + assertSyncTabHeaders(); |
| 227 | + } |
| 228 | + |
| 229 | + @Test |
| 230 | + public void testAddCollectionAtEnd() { |
| 231 | + List<Tab> added = List.of(new Tab("t6"), new Tab("t7")); |
| 232 | + tabPane.getTabs().addAll(tabPane.getTabs().size(), added); |
| 233 | + assertSyncTabHeaders(); |
| 234 | + } |
| 235 | + |
| 236 | + @Test |
| 237 | + public void testAddCollectionInMiddle() { |
| 238 | + List<Tab> added = List.of(new Tab("tm1"), new Tab("tm2")); |
| 239 | + tabPane.getTabs().addAll(2, added); |
| 240 | + assertSyncTabHeaders(); |
| 241 | + } |
| 242 | + |
| 243 | + @Test |
| 244 | + public void testInitialTabOrder() { |
| 245 | + assertSyncTabHeaders(); |
| 246 | + } |
| 247 | + |
| 248 | + protected void assertSyncTabHeaders() { |
| 249 | + assertSyncHeaders(tabPane.getTabs(), |
| 250 | + TabPaneSkinShim.getTabHeaders(tabPane)); |
| 251 | + } |
| 252 | + |
| 253 | + protected void assertSyncHeaders(List<Tab> tabs, List<Node> headers) { |
| 254 | + assertEquals("sanity: same size", tabs.size(), headers.size()); |
| 255 | + for (int i = 0; i < tabs.size(); i++) { |
| 256 | + Tab headerTab = (Tab) headers.get(i).getProperties().get(Tab.class); |
| 257 | + assertSame("tab at " + i + ", is: " + tabs.get(i).getText() |
| 258 | + + " but in header it is: " + headerTab.getText(), |
| 259 | + tabs.get(i), headerTab); |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + |
| 264 | +//----------------- setup and initial |
| 265 | + @Test |
| 266 | + public void testSetupState() { |
| 267 | + assertNotNull(tabPane); |
| 268 | + List<Node> expected = List.of(tabPane); |
| 269 | + assertEquals(expected, root.getChildren()); |
| 270 | + } |
| 271 | + |
| 272 | + @After |
| 273 | + public void cleanup() { |
| 274 | + stage.hide(); |
| 275 | + } |
| 276 | + |
| 277 | + @Before |
| 278 | + public void setup() { |
| 279 | + root = new VBox(); |
| 280 | + scene = new Scene(root); |
| 281 | + stage = new Stage(); |
| 282 | + stage.setScene(scene); |
| 283 | + tabPane = new TabPane(new Tab("t1"), new Tab("t2"), new Tab("t3"), |
| 284 | + new Tab("t4"), new Tab("t5")); |
| 285 | + root.getChildren().add(tabPane); |
| 286 | + stage.show(); |
| 287 | + TabPaneSkinShim.disableAnimations((TabPaneSkin)tabPane.getSkin()); |
| 288 | + } |
| 289 | +} |
0 commit comments