changeset 1445:d12adf6ea5d5

RT-21894: unit test
author David Grieve<david.grieve@oracle.com>
date Fri, 13 Jul 2012 13:15:20 -0400
parents aa283b2f20ad
children 8b3da2148b1b
files javafx-ui-controls/test/javafx/scene/control/MenuButtonTest.java
diffstat 1 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/test/javafx/scene/control/MenuButtonTest.java	Thu Jul 12 16:27:13 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/MenuButtonTest.java	Fri Jul 13 13:15:20 2012 -0400
@@ -4,9 +4,16 @@
 
 package javafx.scene.control;
 
+import com.sun.javafx.scene.control.skin.MenuButtonSkin;
+import com.sun.javafx.tk.Toolkit;
 import javafx.beans.property.SimpleObjectProperty;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
 import javafx.geometry.Side;
+import javafx.scene.Scene;
+import javafx.scene.layout.VBox;
 import javafx.scene.shape.Rectangle;
+import javafx.stage.Stage;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -180,4 +187,57 @@
 
     //TODO: test show()/isShowing() for disabled=true
     //TODO: test MenuButton.impl_getPsuedoClassState
+    
+    @Test
+    public void test_RT_21894() {
+        
+        // Bug reproduces by setting opacity on the MenuButton
+        // then moving focus on and off the MenuButton
+        final MenuButton mb = new MenuButton();
+        mb.setText("SomeText"); 
+        
+        MenuButtonSkin mbs = new MenuButtonSkin(mb);
+        mb.setSkin(mbs);
+        
+        Button other = new Button("other");
+        // Doesn't have to be done this way, but this more closely duplicates
+        // the example code in the bug report.
+        other.setOnAction(new EventHandler<ActionEvent>(){
+            @Override
+            public void handle(ActionEvent t) {
+                mb.setOpacity(.5);
+            }
+        });
+        
+        VBox vbox = new VBox();
+        vbox.getChildren().addAll(mb, other);
+        Scene scene = new Scene(vbox, 300, 300); 
+        Stage stage = new Stage();
+        stage.setScene(scene); 
+        stage.show();         
+        
+        other.requestFocus();
+        assertFalse(mb.isFocused());
+        
+        // set opacity on MenuButton
+        other.fire();
+        
+        // focus on MenuButton
+        mb.requestFocus();
+        assertTrue(mb.isFocused());
+        
+        // give css a chance to run
+        Toolkit.getToolkit().firePulse();
+        
+        // focus off the MenuButton
+        other.requestFocus();
+        assertFalse(mb.isFocused());
+        
+        // give css a chance to run
+        Toolkit.getToolkit().firePulse();
+
+        // MenuButton should still be 50%
+        assertEquals(.5, mb.getOpacity(), 0.00001);
+        
+    }    
 }