changeset 1434:1953b610d096

[TEST-ONLY] RT-23320 - Traversal : write unit test to check for nested focus-traversal cycles inside a TabPane.
author mickf
date Wed, 11 Jul 2012 16:46:20 +0100
parents 30b375f0ad85
children 2e6dd4d24206
files javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Wed Jul 11 08:03:29 2012 -0400
+++ b/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Wed Jul 11 16:46:20 2012 +0100
@@ -9,6 +9,7 @@
 import com.sun.javafx.pgstub.StubToolkit;
 import com.sun.javafx.scene.control.skin.TabPaneSkin;
 import com.sun.javafx.tk.Toolkit;
+import javafx.application.Platform;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.ObjectProperty;
@@ -20,9 +21,12 @@
 import javafx.event.Event;
 import javafx.event.EventHandler;
 import javafx.geometry.Side;
+import javafx.scene.Group;
 import javafx.scene.Scene;
+import javafx.scene.input.KeyEvent;
 import javafx.scene.input.MouseEvent;
 import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
 import javafx.stage.Stage;
 import static org.junit.Assert.*;
 
@@ -767,4 +771,50 @@
         assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());        
     }    
+
+
+    boolean button1Focused = false;
+    @Test public void focusTraversalShouldLookInsideEmbeddedEngines() {
+
+        Button b1 = new Button("Button1");
+        final ChangeListener<Boolean> focusListener = new ChangeListener<Boolean>() {
+            @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldVal, Boolean newVal) {
+                button1Focused = true;
+            }
+        };
+        b1.focusedProperty().addListener(focusListener);
+
+        final ScrollPane sp = new ScrollPane();
+        final VBox vbox1 = new VBox();
+        vbox1.setSpacing(10);
+        vbox1.setTranslateX(10);
+        vbox1.setTranslateY(10);
+        vbox1.getChildren().addAll(b1);
+        tab1.setContent(vbox1);
+        sp.setContent(vbox1);
+        tab1.setContent(sp);
+        tabPane.getTabs().add(tab1);
+
+        tabPane.getTabs().add(tab2);
+
+        final Scene scene1 = new Scene(new Group(), 400, 400);
+        ((Group)scene1.getRoot()).getChildren().add(tabPane);
+        
+        stage.setScene(scene1);
+        stage.show();
+
+        final KeyEvent tabEvent = KeyEvent.impl_keyEvent(null, "", "", 0x09,
+                                                         false, false, false, false,
+                                                         KeyEvent.KEY_PRESSED);
+        Platform.runLater(new Runnable() {
+            @Override public void run() {
+                tabPane.requestFocus();
+                Event.fireEvent(tabPane, tabEvent);
+
+            }
+        });
+
+        assertTrue(button1Focused);
+
+    }    
 }