1 /*
   2  * Copyright (c) 2010, 2014, 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 javafx.scene.control;
  27 
  28 import static com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertPseudoClassDoesNotExist;
  29 import static com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertPseudoClassExists;
  30 import static com.sun.javafx.scene.control.infrastructure.ControlTestUtils.assertStyleClassContains;
  31 import static org.junit.Assert.assertEquals;
  32 import static org.junit.Assert.assertFalse;
  33 import static org.junit.Assert.assertNotNull;
  34 import static org.junit.Assert.assertNull;
  35 import static org.junit.Assert.assertSame;
  36 import static org.junit.Assert.assertTrue;
  37 
  38 import com.sun.javafx.scene.control.infrastructure.StageLoader;
  39 import javafx.application.Platform;
  40 import javafx.beans.property.BooleanProperty;
  41 import javafx.beans.property.DoubleProperty;
  42 import javafx.beans.property.ObjectProperty;
  43 import javafx.beans.property.SimpleBooleanProperty;
  44 import javafx.beans.property.SimpleDoubleProperty;
  45 import javafx.beans.property.SimpleObjectProperty;
  46 import javafx.beans.value.ChangeListener;
  47 import javafx.css.CssMetaData;
  48 import javafx.css.StyleableProperty;
  49 import javafx.event.Event;
  50 import javafx.geometry.Bounds;
  51 import javafx.geometry.Side;
  52 import javafx.scene.Group;
  53 import javafx.scene.Scene;
  54 import javafx.scene.input.KeyEvent;
  55 import javafx.scene.input.MouseEvent;
  56 import javafx.scene.layout.StackPane;
  57 import javafx.scene.layout.VBox;
  58 import javafx.stage.Stage;
  59 
  60 import org.junit.Before;
  61 import org.junit.Ignore;
  62 import org.junit.Test;
  63 
  64 import com.sun.javafx.pgstub.StubToolkit;
  65 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
  66 import com.sun.javafx.scene.control.infrastructure.MouseEventGenerator;
  67 import javafx.scene.control.skin.TabPaneSkin;
  68 import com.sun.javafx.scene.input.KeyCodeMap;
  69 import com.sun.javafx.tk.Toolkit;
  70 
  71 import java.util.Arrays;
  72 import java.util.HashMap;
  73 import java.util.LinkedList;
  74 import java.util.List;
  75 import java.util.Map;
  76 
  77 public class TabPaneTest {
  78     private TabPane tabPane;//Empty string
  79     private Toolkit tk;
  80     private TabPane.TabPaneSelectionModel sm;
  81     private Tab tab1;
  82     private Tab tab2;
  83     private Tab tab3;
  84     private Scene scene;
  85     private Stage stage;
  86     private StackPane root;
  87 
  88     @Before public void setup() {
  89         tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM)
  90         tabPane = new TabPane();
  91         tab1 = new Tab("one");
  92         tab2 = new Tab("two");
  93         tab3 = new Tab("three");
  94         sm = new TabPane.TabPaneSelectionModel(tabPane);
  95         root = new StackPane();
  96         scene = new Scene(root);
  97         stage = new Stage();
  98         stage.setScene(scene);
  99     }
 100 
 101     /*********************************************************************
 102      * Helper methods                                                    *
 103      ********************************************************************/
 104 
 105     private void show() {
 106         stage.show();
 107         stage.requestFocus();
 108     }
 109 
 110     /*********************************************************************
 111      * Tests for default values                                         *
 112      ********************************************************************/
 113 
 114     @Test public void defaultConstructorShouldSetStyleClassTo_tabpane() {
 115         assertStyleClassContains(tabPane, "tab-pane");
 116     }
 117 
 118     @Test public void defaultConstructorSelectionModelNotNull() {
 119         assertNotNull(tabPane.getSelectionModel());
 120     }
 121 
 122     @Test public void defaultConstructorInitialTabsEmpty() {
 123         assertNotNull(tabPane.getTabs());
 124         assertEquals(tabPane.getTabs().size(), 0.0, 0.0);
 125     }
 126 
 127     @Test public void defaultSideIsTop() {
 128         assertSame(tabPane.getSide(), Side.TOP);
 129     }
 130 
 131     @Test public void defaultConstructorTabClosingPolicy() {
 132         assertNotNull(tabPane.getTabClosingPolicy());
 133         assertSame(tabPane.getTabClosingPolicy(), TabPane.TabClosingPolicy.SELECTED_TAB);
 134     }
 135 
 136     @Test public void defaultConstructorRotateGraphic() {
 137         assertFalse(tabPane.isRotateGraphic());
 138     }
 139 
 140     @Test public void defaultTabMinWidth() {
 141         assertEquals(tabPane.getTabMinWidth(), 0.0, 0.0);
 142     }
 143 
 144     @Test public void defaultTabMaxWidth() {
 145         assertEquals(tabPane.getTabMaxWidth(), Double.MAX_VALUE, 0.0);
 146     }
 147 
 148     @Test public void defaultTabMinHeight() {
 149         assertEquals(tabPane.getTabMinHeight(), 0.0, 0.0);
 150     }
 151 
 152     @Test public void defaultTabMaxHeight() {
 153         assertEquals(tabPane.getTabMaxHeight(), Double.MAX_VALUE, 0.0);
 154     }
 155 
 156     @Test public void defaultSelectionModelEmpty() {
 157         assertTrue(tabPane.getSelectionModel().isEmpty());
 158     }
 159 
 160     @Test public void initialBoundsInParentMatchesWidthAndHeight() {
 161         TabPane testPane = new TabPane();
 162         testPane.resize(400, 400);
 163         testPane.setSkin(new TabPaneSkin(testPane));
 164         Bounds boundsInParent = testPane.getBoundsInParent();
 165         assertEquals(testPane.getWidth(), boundsInParent.getWidth(), 0.0);
 166         assertEquals(testPane.getHeight(), boundsInParent.getHeight(), 0.0);
 167     }
 168 
 169     /*********************************************************************
 170      * Tests for property binding                                        *
 171      ********************************************************************/
 172 
 173     @Test public void checkSelectionModelPropertyBind() {
 174         ObjectProperty objPr = new SimpleObjectProperty<SingleSelectionModel<Tab>>(null);
 175         tabPane.selectionModelProperty().bind(objPr);
 176         assertNull("selectionModel cannot be bound", tabPane.selectionModelProperty().getValue());
 177         objPr.setValue(sm);
 178         assertSame("selectionModel cannot be bound", tabPane.selectionModelProperty().getValue(), sm);
 179     }
 180 
 181     @Test public void checkSidePropertyBind() {
 182         ObjectProperty objPr = new SimpleObjectProperty<Side>(Side.BOTTOM);
 183         tabPane.sideProperty().bind(objPr);
 184         assertSame("side cannot be bound", tabPane.sideProperty().getValue(), Side.BOTTOM);
 185         objPr.setValue(Side.RIGHT);
 186         assertSame("side cannot be bound", tabPane.sideProperty().getValue(), Side.RIGHT);
 187     }
 188 
 189     @Test public void checkTabClosingPropertyBind() {
 190         ObjectProperty objPr = new SimpleObjectProperty<TabPane.TabClosingPolicy>(TabPane.TabClosingPolicy.UNAVAILABLE);
 191         tabPane.tabClosingPolicyProperty().bind(objPr);
 192         assertSame("side cannot be bound", tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.UNAVAILABLE);
 193         objPr.setValue(TabPane.TabClosingPolicy.ALL_TABS);
 194         assertSame("side cannot be bound", tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.ALL_TABS);
 195     }
 196 
 197     @Test public void checkRotateGraphicsPropertyBind() {
 198         BooleanProperty objPr = new SimpleBooleanProperty(false);
 199         tabPane.rotateGraphicProperty().bind(objPr);
 200         assertFalse("rotateGraphic cannot be bound", tabPane.rotateGraphicProperty().getValue());
 201         objPr.setValue(true);
 202         assertTrue("rotateGraphic cannot be bound", tabPane.rotateGraphicProperty().getValue());
 203     }
 204 
 205     @Test public void checkTabMinWidthPropertyBind() {
 206         DoubleProperty objPr = new SimpleDoubleProperty(2.0);
 207         tabPane.tabMinWidthProperty().bind(objPr);
 208         assertEquals("tabMinWidthProperty cannot be bound", tabPane.tabMinWidthProperty().getValue(), 2.0, 0.0);
 209         objPr.setValue(5.0);
 210         assertEquals("tabMinWidthProperty cannot be bound", tabPane.tabMinWidthProperty().getValue(), 5.0, 0.0);
 211     }
 212 
 213     @Test public void checkTabMaxWidthPropertyBind() {
 214         DoubleProperty objPr = new SimpleDoubleProperty(2.0);
 215         tabPane.tabMaxWidthProperty().bind(objPr);
 216         assertEquals("tabMaxWidthProperty cannot be bound", tabPane.tabMaxWidthProperty().getValue(), 2.0, 0.0);
 217         objPr.setValue(5.0);
 218         assertEquals("tabMaxWidthProperty cannot be bound", tabPane.tabMaxWidthProperty().getValue(), 5.0, 0.0);
 219     }
 220 
 221 
 222     @Test public void checkTabMinHeightPropertyBind() {
 223         DoubleProperty objPr = new SimpleDoubleProperty(2.0);
 224         tabPane.tabMinHeightProperty().bind(objPr);
 225         assertEquals("tabMinHeightProperty cannot be bound", tabPane.tabMinHeightProperty().getValue(), 2.0, 0.0);
 226         objPr.setValue(5.0);
 227         assertEquals("tabMinHeightProperty cannot be bound", tabPane.tabMinHeightProperty().getValue(), 5.0, 0.0);
 228     }
 229 
 230     @Test public void checkTabMaxHeightPropertyBind() {
 231         DoubleProperty objPr = new SimpleDoubleProperty(2.0);
 232         tabPane.tabMaxHeightProperty().bind(objPr);
 233         assertEquals("tabMaxHeightProperty cannot be bound", tabPane.tabMaxHeightProperty().getValue(), 2.0, 0.0);
 234         objPr.setValue(5.0);
 235         assertEquals("tabMaxHeightProperty cannot be bound", tabPane.tabMaxHeightProperty().getValue(), 5.0, 0.0);
 236     }
 237 
 238     @Test public void selectionModelPropertyHasBeanReference() {
 239         assertSame(tabPane, tabPane.selectionModelProperty().getBean());
 240     }
 241 
 242     @Test public void selectionModelPropertyHasName() {
 243         assertEquals("selectionModel", tabPane.selectionModelProperty().getName());
 244     }
 245 
 246     @Test public void sidePropertyHasBeanReference() {
 247         assertSame(tabPane, tabPane.sideProperty().getBean());
 248     }
 249 
 250     @Test public void sidePropertyHasName() {
 251         assertEquals("side", tabPane.sideProperty().getName());
 252     }
 253 
 254     @Test public void tabClosingPolicyPropertyHasBeanReference() {
 255         assertSame(tabPane, tabPane.tabClosingPolicyProperty().getBean());
 256     }
 257 
 258     @Test public void tabClosingPolicyPropertyHasName() {
 259         assertEquals("tabClosingPolicy", tabPane.tabClosingPolicyProperty().getName());
 260     }
 261 
 262     @Test public void rotateGraphicPropertyHasBeanReference() {
 263         assertSame(tabPane, tabPane.rotateGraphicProperty().getBean());
 264     }
 265 
 266     @Test public void rotateGraphicPropertyHasName() {
 267         assertEquals("rotateGraphic", tabPane.rotateGraphicProperty().getName());
 268     }
 269 
 270     @Test public void tabMinWidthPropertyHasBeanReference() {
 271         assertSame(tabPane, tabPane.tabMinWidthProperty().getBean());
 272     }
 273 
 274     @Test public void tabMinWidthPropertyHasName() {
 275         assertEquals("tabMinWidth", tabPane.tabMinWidthProperty().getName());
 276     }
 277 
 278     @Test public void tabMaxWidthPropertyHasBeanReference() {
 279         assertSame(tabPane, tabPane.tabMaxWidthProperty().getBean());
 280     }
 281 
 282     @Test public void tabMaxWidthPropertyHasName() {
 283         assertEquals("tabMaxWidth", tabPane.tabMaxWidthProperty().getName());
 284     }
 285 
 286     @Test public void tabMinHeightPropertyHasBeanReference() {
 287         assertSame(tabPane, tabPane.tabMinHeightProperty().getBean());
 288     }
 289 
 290     @Test public void tabMinHeightPropertyHasName() {
 291         assertEquals("tabMinHeight", tabPane.tabMinHeightProperty().getName());
 292     }
 293 
 294     @Test public void tabMaxHeightPropertyHasBeanReference() {
 295         assertSame(tabPane, tabPane.tabMaxHeightProperty().getBean());
 296     }
 297 
 298     @Test public void tabMaxHeightPropertyHasName() {
 299         assertEquals("tabMaxHeight", tabPane.tabMaxHeightProperty().getName());
 300     }
 301 
 302 
 303     /*********************************************************************
 304      * Check for Pseudo classes                                          *
 305      ********************************************************************/
 306 
 307     @Test public void settingSideSetsPseudoClass() {
 308         tabPane.setSide(Side.BOTTOM);
 309         assertPseudoClassExists(tabPane, "bottom");
 310         assertPseudoClassDoesNotExist(tabPane, "top");
 311         assertPseudoClassDoesNotExist(tabPane, "left");
 312         assertPseudoClassDoesNotExist(tabPane, "right");
 313     }
 314 
 315     @Test public void clearingSideClearsPseudoClass() {
 316         tabPane.setSide(Side.BOTTOM);
 317         tabPane.setSide(Side.LEFT);
 318         assertPseudoClassExists(tabPane, "left");
 319         assertPseudoClassDoesNotExist(tabPane, "bottom");
 320         assertPseudoClassDoesNotExist(tabPane, "top");
 321         assertPseudoClassDoesNotExist(tabPane, "right");
 322     }
 323 
 324 
 325     /*********************************************************************
 326      * CSS related Tests                                                 *
 327      ********************************************************************/
 328 
 329     @Test public void whenTabMinWidthIsBound_impl_cssSettable_ReturnsFalse() {
 330         CssMetaData styleable = ((StyleableProperty)tabPane.tabMinWidthProperty()).getCssMetaData();
 331         assertTrue(styleable.isSettable(tabPane));
 332         DoubleProperty other = new SimpleDoubleProperty(30.0);
 333         tabPane.tabMinWidthProperty().bind(other);
 334         assertFalse(styleable.isSettable(tabPane));
 335     }
 336 
 337     @Test public void whenTabMinWidthIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() {
 338         CssMetaData styleable = ((StyleableProperty)tabPane.tabMinWidthProperty()).getCssMetaData();
 339         assertTrue(styleable.isSettable(tabPane));
 340     }
 341 
 342     @Test public void canSpecifyTabMinWidthViaCSS() {
 343         ((StyleableProperty)tabPane.tabMinWidthProperty()).applyStyle(null, 34.0);
 344         assertEquals(34.0, tabPane.getTabMinWidth(), 0.0);
 345     }
 346 
 347     @Test public void whenTabMaxWidthIsBound_impl_cssSettable_ReturnsFalse() {
 348         CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxWidthProperty()).getCssMetaData();
 349         assertTrue(styleable.isSettable(tabPane));
 350         DoubleProperty other = new SimpleDoubleProperty(30.0);
 351         tabPane.tabMaxWidthProperty().bind(other);
 352         assertFalse(styleable.isSettable(tabPane));
 353     }
 354 
 355     @Test public void whenTabMaxWidthIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() {
 356         CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxWidthProperty()).getCssMetaData();
 357         assertTrue(styleable.isSettable(tabPane));
 358     }
 359 
 360     @Test public void canSpecifyTabMaxWidthViaCSS() {
 361         ((StyleableProperty)tabPane.tabMaxWidthProperty()).applyStyle(null, 34.0);
 362         assertEquals(34.0, tabPane.getTabMaxWidth(), 0.0);
 363     }
 364 
 365     @Test public void whenTabMinHeightIsBound_impl_cssSettable_ReturnsFalse() {
 366         CssMetaData styleable = ((StyleableProperty)tabPane.tabMinHeightProperty()).getCssMetaData();
 367         assertTrue(styleable.isSettable(tabPane));
 368         DoubleProperty other = new SimpleDoubleProperty(30.0);
 369         tabPane.tabMinHeightProperty().bind(other);
 370         assertFalse(styleable.isSettable(tabPane));
 371     }
 372 
 373     @Test public void whenTabMinHeightIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() {
 374         CssMetaData styleable = ((StyleableProperty)tabPane.tabMinHeightProperty()).getCssMetaData();
 375         assertTrue(styleable.isSettable(tabPane));
 376     }
 377 
 378     @Test public void canSpecifyTabMinHeightViaCSS() {
 379         ((StyleableProperty)tabPane.tabMinHeightProperty()).applyStyle(null, 34.0);
 380         assertEquals(34.0, tabPane.getTabMinHeight(), 0.0);
 381     }
 382 
 383     @Test public void whenTabMaxHeightIsBound_impl_cssSettable_ReturnsFalse() {
 384         CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxHeightProperty()).getCssMetaData();
 385         assertTrue(styleable.isSettable(tabPane));
 386         DoubleProperty other = new SimpleDoubleProperty(30.0);
 387         tabPane.tabMaxHeightProperty().bind(other);
 388         assertFalse(styleable.isSettable(tabPane));
 389     }
 390 
 391     @Test public void whenTabMaxHeightIsSpecifiedViaCSSAndIsNotBound_impl_cssSettable_ReturnsTrue() {
 392         CssMetaData styleable = ((StyleableProperty)tabPane.tabMaxHeightProperty()).getCssMetaData();
 393         assertTrue(styleable.isSettable(tabPane));
 394     }
 395 
 396     @Test public void canSpecifyTabMaxHeightViaCSS() {
 397         ((StyleableProperty)tabPane.tabMaxHeightProperty()).applyStyle(null, 34.0);
 398         assertEquals(34.0, tabPane.getTabMaxHeight(), 0.0);
 399     }
 400 
 401 
 402     /*********************************************************************
 403      * Miscellaneous Tests                                               *
 404      ********************************************************************/
 405 
 406     @Test public void setSelectionModelAndSeeValueIsReflectedInModel() {
 407         tabPane.setSelectionModel(sm);
 408         assertSame(tabPane.selectionModelProperty().getValue(), sm);
 409     }
 410 
 411     @Test public void setselectionModelAndSeeValue() {
 412         tabPane.setSelectionModel(sm);
 413         assertSame(tabPane.getSelectionModel(), sm);
 414     }
 415 
 416     @Test public void setSideAndSeeValueIsReflectedInModel() {
 417         tabPane.setSide(Side.BOTTOM);
 418         assertSame(tabPane.sideProperty().getValue(), Side.BOTTOM);
 419     }
 420 
 421     @Test public void setSideAndSeeValue() {
 422         tabPane.setSide(Side.LEFT);
 423         assertSame(tabPane.getSide(), Side.LEFT);
 424     }
 425 
 426     @Test public void setTabClosingPolicyAndSeeValueIsReflectedInModel() {
 427         tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
 428         assertSame(tabPane.tabClosingPolicyProperty().getValue(), TabPane.TabClosingPolicy.ALL_TABS);
 429     }
 430 
 431     @Test public void setTabClosingPolicyAndSeeValue() {
 432         tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
 433         assertSame(tabPane.getTabClosingPolicy(), TabPane.TabClosingPolicy.UNAVAILABLE);
 434     }
 435 
 436     @Test public void setRotateGraphicAndSeeValueIsReflectedInModel() {
 437         tabPane.setRotateGraphic(true);
 438         assertTrue(tabPane.rotateGraphicProperty().getValue());
 439     }
 440 
 441     @Test public void setRotateGraphicAndSeeValue() {
 442         tabPane.setRotateGraphic(true);
 443         assertTrue(tabPane.isRotateGraphic());
 444     }
 445 
 446     @Test public void setTabMinWidthAndSeeValueIsReflectedInModel() {
 447         tabPane.setTabMinWidth(30.0);
 448         assertEquals(tabPane.tabMinWidthProperty().getValue(), 30.0, 0.0);
 449     }
 450 
 451     @Test public void setTabMinWidthAndSeeValue() {
 452         tabPane.setTabMinWidth(30.0);
 453         assertEquals(tabPane.getTabMinWidth(), 30.0, 0.0);
 454     }
 455 
 456     @Test public void setTabMaxWidthAndSeeValueIsReflectedInModel() {
 457         tabPane.setTabMaxWidth(30.0);
 458         assertEquals(tabPane.tabMaxWidthProperty().getValue(), 30.0, 0.0);
 459     }
 460 
 461     @Test public void setTabMaxWidthAndSeeValue() {
 462         tabPane.setTabMaxWidth(30.0);
 463         assertEquals(tabPane.getTabMaxWidth(), 30.0, 0.0);
 464     }
 465 
 466     @Test public void setTabMinHeightAndSeeValueIsReflectedInModel() {
 467         tabPane.setTabMinHeight(30.0);
 468         assertEquals(tabPane.tabMinHeightProperty().getValue(), 30.0, 0.0);
 469     }
 470 
 471     @Test public void setTabMinHeightAndSeeValue() {
 472         tabPane.setTabMinHeight(30.0);
 473         assertEquals(tabPane.getTabMinHeight(), 30.0, 0.0);
 474     }
 475 
 476     @Test public void setTabMaxHeightAndSeeValueIsReflectedInModel() {
 477         tabPane.setTabMaxHeight(30.0);
 478         assertEquals(tabPane.tabMaxHeightProperty().getValue(), 30.0, 0.0);
 479     }
 480 
 481     @Test public void setTabMaxHeightAndSeeValue() {
 482         tabPane.setTabMaxHeight(30.0);
 483         assertEquals(tabPane.getTabMaxHeight(), 30.0, 0.0);
 484     }
 485 
 486     @Test public void addTabsCheckItemCountInSelectionModel() {
 487         tabPane.getTabs().add(tab1);
 488         tabPane.getTabs().add(tab2);
 489         assertEquals(tabPane.getSelectionModel().getItemCount(), 2.0, 0.0);
 490     }
 491 
 492     @Test public void addTabsCheckItemInSelectionModel() {
 493         tabPane.getTabs().add(tab1);
 494         tabPane.getTabs().add(tab2);
 495         assertSame(tabPane.getSelectionModel().getModelItem(0), tab1);
 496         assertSame(tabPane.getSelectionModel().getModelItem(1), tab2);
 497     }
 498 
 499     @Test public void addTabsCheckSelectUsingObjInSelectionModel() {
 500         tabPane.getTabs().add(tab1);
 501         tabPane.getTabs().add(tab2);
 502         tabPane.getSelectionModel().select(tab1);
 503         assertTrue(tabPane.getSelectionModel().isSelected(0));
 504     }
 505 
 506     @Test public void addTabsCheckSelectUsingIndexInSelectionModel() {
 507         tabPane.getTabs().add(tab1);
 508         tabPane.getTabs().add(tab2);
 509         tabPane.getSelectionModel().select(1);
 510         assertTrue(tabPane.getSelectionModel().isSelected(1));
 511     }
 512 
 513     @Test public void addTabsCheckClearAndSelectUsingIndexInSelectionModel() {
 514         tabPane.getTabs().add(tab1);
 515         tabPane.getTabs().add(tab2);
 516         tabPane.getSelectionModel().clearAndSelect(1);
 517         assertTrue(tabPane.getSelectionModel().isSelected(1));
 518     }
 519 
 520     @Test public void addTabsCheckSelectMultipleItemsAndClearOneItemInSelectionModel() {
 521         tabPane.getTabs().add(tab1);
 522         tabPane.getTabs().add(tab2);
 523         tabPane.getSelectionModel().select(0);
 524         tabPane.getSelectionModel().select(1);
 525         tabPane.getSelectionModel().clearSelection(0);
 526         assertFalse(tabPane.getSelectionModel().isSelected(0));
 527         assertTrue(tabPane.getSelectionModel().isSelected(1));
 528     }
 529 
 530     @Test public void addTabsCheckSelectMultipleItemsAndClearAllSelectionInSelectionModel() {
 531         tabPane.getTabs().add(tab1);
 532         tabPane.getTabs().add(tab2);
 533         tabPane.getSelectionModel().select(0);
 534         tabPane.getSelectionModel().select(1);
 535         tabPane.getSelectionModel().clearSelection();
 536         assertFalse(tabPane.getSelectionModel().isSelected(0));
 537         assertFalse(tabPane.getSelectionModel().isSelected(1));
 538         assertTrue(tabPane.getSelectionModel().isEmpty());
 539     }
 540 
 541     @Test public void addTabsCheckSelectUsingIteratorKindOfMethodsInSelectionModel() {
 542         tabPane.getTabs().add(tab1);
 543         tabPane.getTabs().add(tab2);
 544         tabPane.getSelectionModel().selectFirst();
 545         assertTrue(tabPane.getSelectionModel().isSelected(0));
 546         assertFalse(tabPane.getSelectionModel().isSelected(1));
 547         tabPane.getSelectionModel().selectNext();
 548         assertFalse(tabPane.getSelectionModel().isSelected(0));
 549         assertTrue(tabPane.getSelectionModel().isSelected(1));
 550         tabPane.getSelectionModel().clearSelection();
 551         tabPane.getSelectionModel().selectLast();
 552         assertFalse(tabPane.getSelectionModel().isSelected(0));
 553         assertTrue(tabPane.getSelectionModel().isSelected(1));
 554         tabPane.getSelectionModel().selectPrevious();
 555         assertTrue(tabPane.getSelectionModel().isSelected(0));
 556         assertFalse(tabPane.getSelectionModel().isSelected(1));
 557     }
 558 
 559     @Test public void flipTabOrder_RT20156() {
 560         tabPane.setSkin(new TabPaneSkin(tabPane));
 561         tabPane.getTabs().add(tab1);
 562         tabPane.getTabs().add(tab2);
 563         tabPane.getTabs().add(tab3);
 564 
 565         assertEquals("one", tabPane.getTabs().get(0).getText());
 566         assertEquals("two", tabPane.getTabs().get(1).getText());
 567         assertEquals("three", tabPane.getTabs().get(2).getText());
 568 
 569         final int lastTabIndex = tabPane.getTabs().size()-1;
 570         final Tab lastTab = tabPane.getTabs().get(lastTabIndex);
 571         tabPane.getTabs().remove(lastTabIndex);
 572         tabPane.getTabs().add(0, lastTab);
 573 
 574         assertEquals("three", tabPane.getTabs().get(0).getText());
 575         assertEquals("one", tabPane.getTabs().get(1).getText());
 576         assertEquals("two", tabPane.getTabs().get(2).getText());
 577         assertTrue(tabPane.getSelectionModel().isSelected(1));
 578     }
 579 
 580     @Test public void disableAllTabs() {
 581         tabPane.setSkin(new TabPaneSkin(tabPane));
 582         tabPane.getTabs().add(tab1);
 583         tabPane.getTabs().add(tab2);
 584         tabPane.getTabs().add(tab3);
 585 
 586         tab1.setDisable(true);
 587         tab2.setDisable(true);
 588         tab3.setDisable(true);
 589 
 590         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 591         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 592     }
 593 
 594     @Test public void disableFirstTabs() {
 595         tabPane.setSkin(new TabPaneSkin(tabPane));
 596         tabPane.getTabs().add(tab1);
 597         tabPane.getTabs().add(tab2);
 598         tabPane.getTabs().add(tab3);
 599 
 600         tab1.setDisable(true);
 601         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 602         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 603     }
 604 
 605     @Test public void disableATabAndSelectItByIndex() {
 606         tabPane.setSkin(new TabPaneSkin(tabPane));
 607         tabPane.getTabs().add(tab1);
 608         tabPane.getTabs().add(tab2);
 609         tabPane.getTabs().add(tab3);
 610 
 611         tab2.setDisable(true);
 612         tabPane.getSelectionModel().select(1);
 613         assertEquals(1, tabPane.getSelectionModel().getSelectedIndex());
 614         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 615     }
 616 
 617     @Test public void selectByIndexADisableTab() {
 618         tabPane.setSkin(new TabPaneSkin(tabPane));
 619         tabPane.getTabs().add(tab1);
 620         tabPane.getTabs().add(tab2);
 621         tabPane.getTabs().add(tab3);
 622 
 623         tabPane.getSelectionModel().select(1);
 624         tab2.setDisable(true);
 625         assertEquals(1, tabPane.getSelectionModel().getSelectedIndex());
 626         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 627         assertTrue(tab2.isDisable());
 628     }
 629 
 630     @Test public void disableATabAndSelectItByTab() {
 631         tabPane.setSkin(new TabPaneSkin(tabPane));
 632         tabPane.getTabs().add(tab1);
 633         tabPane.getTabs().add(tab2);
 634         tabPane.getTabs().add(tab3);
 635 
 636         tab2.setDisable(true);
 637         tabPane.getSelectionModel().select(tab2);
 638         assertEquals(1, tabPane.getSelectionModel().getSelectedIndex());
 639         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 640     }
 641 
 642     @Test public void selectByTabADisableTab() {
 643         tabPane.setSkin(new TabPaneSkin(tabPane));
 644         tabPane.getTabs().add(tab1);
 645         tabPane.getTabs().add(tab2);
 646         tabPane.getTabs().add(tab3);
 647 
 648         tabPane.getSelectionModel().select(tab2);
 649         tab2.setDisable(true);
 650         assertEquals(1, tabPane.getSelectionModel().getSelectedIndex());
 651         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 652         assertTrue(tab2.isDisable());
 653     }
 654 
 655     @Test public void navigateOverDisableTab() {
 656         tabPane.getTabs().add(tab1);
 657         tabPane.getTabs().add(tab2);
 658         tabPane.getTabs().add(tab3);
 659 
 660         root.getChildren().add(tabPane);
 661         show();
 662         tabPane.requestFocus();
 663 
 664         assertTrue(tabPane.isFocused());
 665         
 666         tab2.setDisable(true);
 667         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 668         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 669         assertTrue(tab2.isDisable());
 670 
 671         KeyEventFirer keyboard = new KeyEventFirer(tabPane);
 672         keyboard.doRightArrowPress();
 673 
 674         assertEquals(2, tabPane.getSelectionModel().getSelectedIndex());
 675         assertEquals(tab3, tabPane.getSelectionModel().getSelectedItem());
 676 
 677         keyboard.doLeftArrowPress();
 678 
 679         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 680         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 681     }
 682     
 683     @Ignore
 684     @Test public void mousePressSelectsATab_RT20476() {        
 685         tabPane.getTabs().add(tab1);
 686         tabPane.getTabs().add(tab2);
 687         tabPane.getTabs().add(tab3);        
 688         
 689         tab1.setContent(new Button("TAB1"));
 690         tab2.setContent(new Button("TAB2"));
 691         tab3.setContent(new Button("TAB3"));
 692         
 693         root.getChildren().add(tabPane);
 694         show();
 695 
 696         root.applyCss();
 697         root.resize(300, 300);
 698         root.layout();
 699         
 700         tk.firePulse();        
 701         assertTrue(tabPane.isFocused());
 702         
 703         double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX();
 704         double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY();
 705    
 706         scene.impl_processMouseEvent(
 707             MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20));
 708         tk.firePulse();        
 709         
 710         assertEquals(1, tabPane.getSelectionModel().getSelectedIndex());
 711         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());        
 712     }
 713     
 714     private int counter = 0;
 715     @Ignore
 716     @Test public void setOnSelectionChangedFiresTwice_RT21089() {
 717         tabPane.getTabs().add(tab1);
 718         tabPane.getTabs().add(tab2);
 719         
 720         tab1.setContent(new Button("TAB1"));
 721         tab2.setContent(new Button("TAB2"));
 722         
 723         root.getChildren().add(tabPane);
 724         show();
 725 
 726         root.applyCss();
 727         root.resize(300, 300);
 728         root.layout();
 729         
 730         tk.firePulse();        
 731         assertTrue(tabPane.isFocused());
 732 
 733         tab2.setOnSelectionChanged(event -> {
 734             assertEquals(0, counter++);
 735         });
 736 
 737         double xval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinX();
 738         double yval = (tabPane.localToScene(tabPane.getLayoutBounds())).getMinY();
 739    
 740         scene.impl_processMouseEvent(
 741             MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20));
 742         tk.firePulse();
 743         
 744         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 745                 
 746         scene.impl_processMouseEvent(
 747             MouseEventGenerator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+75, yval+20));
 748         tk.firePulse();        
 749         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 750     }
 751     
 752     @Test public void unableToSelectNextTabWhenFirstTabIsClosed_RT22326() {
 753         tabPane.getTabs().add(tab1);
 754         tabPane.getTabs().add(tab2);
 755         tabPane.getTabs().add(tab3);
 756 
 757         assertEquals("one", tabPane.getTabs().get(0).getText());
 758         assertEquals("two", tabPane.getTabs().get(1).getText());
 759         assertEquals("three", tabPane.getTabs().get(2).getText());
 760         
 761         tabPane.getTabs().remove(tab1);
 762 
 763         assertEquals(2, tabPane.getTabs().size());
 764         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 765         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 766         tabPane.getSelectionModel().selectNext();
 767         assertEquals(tab3, tabPane.getSelectionModel().getSelectedItem());
 768     }
 769     
 770     @Test public void removeFirstTabNextTabShouldBeSelected() {
 771         tabPane.getTabs().add(tab1);
 772         tabPane.getTabs().add(tab2);
 773         tabPane.getTabs().add(tab3);        
 774 
 775         assertEquals("one", tabPane.getTabs().get(0).getText());
 776         assertEquals("two", tabPane.getTabs().get(1).getText());
 777         assertEquals("three", tabPane.getTabs().get(2).getText());
 778         
 779         tabPane.getTabs().remove(tab1);
 780 
 781         assertEquals(2, tabPane.getTabs().size());
 782         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 783         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());        
 784     }
 785     
 786     @Test public void selectionModelShouldNotBeNullWhenClosingFirstTab_RT22925() {
 787         tabPane.getTabs().add(tab1);
 788         tabPane.getTabs().add(tab2);
 789         tabPane.getTabs().add(tab3);        
 790 
 791         tabPane.getSelectionModel().selectedItemProperty().addListener((ov, t, t1) -> {
 792             assertEquals(t.getText(), "one");
 793             assertEquals(t1.getText(), "two");
 794         });
 795         
 796         assertEquals("one", tabPane.getTabs().get(0).getText());
 797         assertEquals("two", tabPane.getTabs().get(1).getText());
 798         assertEquals("three", tabPane.getTabs().get(2).getText());
 799         
 800         tabPane.getTabs().remove(tab1);
 801 
 802         assertEquals(2, tabPane.getTabs().size());
 803         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
 804         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());        
 805     }    
 806 
 807 
 808     boolean button1Focused = false;
 809     @Test public void focusTraversalShouldLookInsideEmbeddedEngines() {
 810 
 811         Button b1 = new Button("Button1");
 812         final ChangeListener<Boolean> focusListener = (observable, oldVal, newVal) -> {
 813             button1Focused = true;
 814         };
 815         b1.focusedProperty().addListener(focusListener);
 816 
 817         final ScrollPane sp = new ScrollPane();
 818         final VBox vbox1 = new VBox();
 819         vbox1.setSpacing(10);
 820         vbox1.setTranslateX(10);
 821         vbox1.setTranslateY(10);
 822         vbox1.getChildren().addAll(b1);
 823         tab1.setContent(vbox1);
 824         sp.setContent(vbox1);
 825         tab1.setContent(sp);
 826         tabPane.getTabs().add(tab1);
 827 
 828         tabPane.getTabs().add(tab2);
 829 
 830         final Scene scene1 = new Scene(new Group(), 400, 400);
 831         ((Group)scene1.getRoot()).getChildren().add(tabPane);
 832         
 833         stage.setScene(scene1);
 834         stage.show();
 835         stage.requestFocus();
 836 
 837         final KeyEvent tabEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "", "", KeyCodeMap.valueOf(0x09),
 838                                                          false, false, false, false);
 839         Platform.runLater(() -> {
 840             tabPane.requestFocus();
 841             Event.fireEvent(tabPane, tabEvent);
 842 
 843         });
 844 
 845         assertTrue(button1Focused);
 846 
 847     }
 848 
 849     @Test public void test_rt_35013() {
 850         SplitPane splitPane = new SplitPane();
 851         splitPane.getItems().addAll(new Button("Button1"), new Button("Button2"));
 852 
 853         TabPane tabPane = new TabPane();
 854         Tab emptyTab;
 855         Tab splitTab = new Tab("SplitPane Tab");
 856         splitTab.setContent(splitPane);
 857         tabPane.getTabs().addAll(emptyTab = new Tab("Empty Tab"), splitTab);
 858 
 859         StageLoader sl = new StageLoader(tabPane);
 860 
 861         tabPane.getSelectionModel().select(emptyTab);
 862         Toolkit.getToolkit().firePulse();
 863         assertFalse(splitPane.getParent().isVisible());
 864 
 865         tabPane.getSelectionModel().select(splitTab);
 866         Toolkit.getToolkit().firePulse();
 867         assertTrue(splitPane.getParent().isVisible());
 868 
 869         sl.dispose();
 870     }
 871 
 872     @Test public void test_rt_36456_default_selectionMovesBackwardOne() {
 873         Tab tab0 = new Tab("Tab 0");
 874         Tab tab1 = new Tab("Tab 1");
 875         Tab tab2 = new Tab("Tab 2");
 876 
 877         TabPane tabPane = new TabPane();
 878         tabPane.getTabs().addAll(tab0, tab1, tab2);
 879         tabPane.getSelectionModel().select(tab1);
 880 
 881         StageLoader sl = new StageLoader(tabPane);
 882 
 883         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 884         tabPane.getTabs().remove(tab1);
 885         assertEquals(tab0, tabPane.getSelectionModel().getSelectedItem());
 886 
 887         sl.dispose();
 888     }
 889 
 890     @Test public void test_rt_36456_selectionMovesBackwardTwoSkippingDisabledTab() {
 891         Tab tab0 = new Tab("Tab 0");
 892         Tab tab1 = new Tab("Tab 1");
 893         tab1.setDisable(true);
 894         Tab tab2 = new Tab("Tab 2");
 895 
 896         TabPane tabPane = new TabPane();
 897         tabPane.getTabs().addAll(tab0, tab1, tab2);
 898         tabPane.getSelectionModel().select(tab2);
 899 
 900         StageLoader sl = new StageLoader(tabPane);
 901 
 902         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 903         tabPane.getTabs().remove(tab2);
 904 
 905         // selection should jump from tab2 to tab0, as tab1 is disabled
 906         assertEquals(tab0, tabPane.getSelectionModel().getSelectedItem());
 907 
 908         sl.dispose();
 909     }
 910 
 911     @Test public void test_rt_36456_selectionMovesForwardOne() {
 912         Tab tab0 = new Tab("Tab 0");
 913         tab0.setDisable(true);
 914         Tab tab1 = new Tab("Tab 1");
 915         Tab tab2 = new Tab("Tab 2");
 916 
 917         TabPane tabPane = new TabPane();
 918         tabPane.getTabs().addAll(tab0, tab1, tab2);
 919         tabPane.getSelectionModel().select(tab1);
 920 
 921         StageLoader sl = new StageLoader(tabPane);
 922 
 923         assertEquals(tab1, tabPane.getSelectionModel().getSelectedItem());
 924         tabPane.getTabs().remove(tab1);
 925 
 926         // selection should move to the next non-disabled tab - in this case tab2
 927         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
 928 
 929         sl.dispose();
 930     }
 931 
 932     @Test public void test_rt_36456_selectionMovesForwardTwoSkippingDisabledTab() {
 933         Tab tab0 = new Tab("Tab 0");
 934         Tab tab1 = new Tab("Tab 1");
 935         tab1.setDisable(true);
 936         Tab tab2 = new Tab("Tab 2");
 937 
 938         TabPane tabPane = new TabPane();
 939         tabPane.getTabs().addAll(tab0, tab1, tab2);
 940         tabPane.getSelectionModel().select(tab0);
 941 
 942         StageLoader sl = new StageLoader(tabPane);
 943 
 944         Tab selectedTab = tabPane.getSelectionModel().getSelectedItem();
 945         assertEquals(tab0, selectedTab);
 946         tabPane.getTabs().remove(tab0);
 947 
 948         // selection should move to the next non-disabled tab - in this case tab2
 949         selectedTab = tabPane.getSelectionModel().getSelectedItem();
 950         assertEquals(tab2.getText() + " != " +  tab2.getText(), tab2, selectedTab);
 951 
 952         sl.dispose();
 953     }
 954 
 955     @Test public void test_rt_36908() {
 956         TabPane pane = new TabPane();
 957         final Tab disabled = new Tab("Disabled");
 958         disabled.setDisable(true);
 959 
 960         Tab tab1 = new Tab("Tab 1");
 961         Tab tab2 = new Tab("Tab 2");
 962         pane.getTabs().addAll(disabled, tab1, tab2);
 963 
 964         assertEquals(1, pane.getSelectionModel().getSelectedIndex());
 965         assertEquals(tab1, pane.getSelectionModel().getSelectedItem());
 966     }
 967 
 968     @Test public void test_rt_24658() {
 969         Button btn = new Button("Button");
 970         final Tab disabled = new Tab("Disabled");
 971         disabled.setContent(btn);
 972 
 973         TabPane pane = new TabPane();
 974         pane.getTabs().addAll(disabled);
 975 
 976         assertEquals(0, pane.getSelectionModel().getSelectedIndex());
 977         assertEquals(disabled, pane.getSelectionModel().getSelectedItem());
 978         assertFalse(btn.isDisabled());
 979 
 980         disabled.setDisable(true);
 981         assertTrue(btn.isDisabled());
 982 
 983         disabled.setDisable(false);
 984         assertFalse(btn.isDisabled());
 985     }
 986 
 987     @Test public void test_rt_38382_noAddToTabPane() {
 988         test_rt_38382(false);
 989     }
 990 
 991     @Test public void test_rt_38382_addToTabPane() {
 992         test_rt_38382(true);
 993     }
 994 
 995     public void test_rt_38382(boolean addToTabPane) {
 996         final List<String> names = Arrays.asList(
 997                 "Biomass",
 998                 "Exploitable Population Biomass",
 999                 "MSY",
1000                 "Yield",
1001                 "Recruitment",
1002                 "Catch",
1003                 "Effort");
1004         final Map<Tab, List<String>> fooMap = new HashMap<>();
1005         final List<Tab> tabList = new LinkedList<>();
1006         for (String name : names) {
1007             final Tab tab = new Tab();
1008             tab.setText(name);
1009             fooMap.put(tab, new LinkedList<>());
1010             tabList.add(tab);
1011         }
1012         TabPane tabPane = new TabPane();
1013 
1014         if (addToTabPane) {
1015             tabPane.getTabs().setAll(tabList);
1016         }
1017 
1018         fooMap.entrySet().forEach(entry -> {
1019             final Tab tab = entry.getKey();
1020             assertTrue(tabList.contains(tab));
1021             assertTrue(fooMap.containsKey(tab));
1022         });
1023     }
1024 }