1 /* 2 * Copyright (c) 2013, 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 com.sun.javafx.pgstub.StubToolkit; 29 import com.sun.javafx.tk.Toolkit; 30 import javafx.geometry.Bounds; 31 import javafx.scene.Group; 32 import javafx.scene.Scene; 33 import javafx.scene.layout.HBox; 34 import javafx.scene.shape.Rectangle; 35 import javafx.scene.text.Font; 36 import javafx.stage.Stage; 37 import junit.framework.Assert; 38 import org.junit.Test; 39 40 import static junit.framework.Assert.assertNotNull; 41 import static org.junit.Assert.assertNull; 42 import static org.junit.Assert.assertSame; 43 44 public class MiscellaneousTests { 45 46 @Test 47 public void test_RT_31168() { 48 // 49 // Make sure that a control added and removed from the scene-graph before css is processed 50 // gets css processed when it is added back in. 51 52 Button button = new Button("RT-31168"); 53 Rectangle rectangle = new Rectangle(50,50); 54 55 Group container = new Group(); 56 container.getChildren().add(rectangle); 57 58 Scene scene = new Scene(new Group(container, new Button("button"))); 59 60 // 61 // Gotta put this in a window for the pulse listener to get hooked up (see Scene#impl_initPeer(). 62 // Need the pulse listener since we want to enter root via Scene#doCSSPass() 63 // 64 Stage stage = new Stage(); 65 stage.setScene(scene); 66 stage.show(); 67 68 // 69 // Has to be a pulse since we want to enter from Scene.doCSSPass() 70 // 71 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 72 73 container.getChildren().set(0, button); 74 container.getChildren().set(0, rectangle); 75 76 // 77 // Has to be a pulse since we want to enter from Scene.doCSSPass() 78 // 79 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 80 81 // Should be null since the button was added and removed before the pulse processed css 82 assertNull(button.getBackground()); 83 84 container.getChildren().set(0, button); 85 86 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 87 88 // Should no longer be null 89 assertNotNull(button.getBackground()); 90 91 } 92 93 @Test public void test_RT_33103() { 94 95 HBox box = new HBox(); 96 97 TextField field = new TextField(); 98 Label badLabel = new Label("Field:", field); 99 100 box.getChildren().addAll(badLabel, field); 101 102 Scene scene = new Scene(box); 103 Stage stage = new Stage(); 104 stage.setScene(scene); 105 stage.show(); 106 107 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 108 109 assertSame(badLabel, field.getParent()); 110 111 } 112 113 @Test public void test_RT_33080() { 114 115 // Rough approximation of sample code from the bug and steps to reproduce 116 117 final HBox root = new HBox(10); 118 119 final RadioButton rb1 = new RadioButton("RB1"); 120 final RadioButton rb2 = new RadioButton("RB2"); 121 122 root.getChildren().addAll(rb1, rb2); 123 124 Scene scene = new Scene(root); 125 Stage stage = new Stage(); 126 stage.setScene(scene); 127 stage.show(); 128 129 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 130 131 // click on rb1 132 rb1.setSelected(true); 133 134 // pulse 135 ((StubToolkit)Toolkit.getToolkit()).fireTestPulse(); 136 137 // change font 138 rb1.setFont(new Font("system", 22)); 139 rb2.setFont(new Font("system", 22)); 140 141 // pulse 142 ((StubToolkit) Toolkit.getToolkit()).fireTestPulse(); 143 144 // click on rb1 again 145 rb1.setSelected(false); 146 147 // pulse 148 ((StubToolkit) Toolkit.getToolkit()).fireTestPulse(); 149 150 // At this point, if the bug is present, the width and height of the buttons will be different. 151 Bounds b1 = rb1.getLayoutBounds(); 152 Bounds b2 = rb2.getLayoutBounds(); 153 154 Assert.assertEquals(rb1.getWidth(), rb2.getWidth(), 0.00001); 155 } 156 157 }