changeset 7613:1f4093002756

[TEST-ONLY] unit test for RT-37787: Sizing fonts with CSS em can result in wrong size font being displayed
author David Grieve<david.grieve@oracle.com>
date Fri, 01 Aug 2014 10:43:52 -0400
parents 4b2c53c5ac68
children d1aac088a16b
files modules/controls/src/test/java/com/sun/javafx/scene/control/skin/LabeledTextTest.java modules/controls/src/test/resources/com/sun/javafx/scene/control/skin/LabeledTextTest.css
diffstat 2 files changed, 49 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/test/java/com/sun/javafx/scene/control/skin/LabeledTextTest.java	Fri Aug 01 10:43:46 2014 -0400
+++ b/modules/controls/src/test/java/com/sun/javafx/scene/control/skin/LabeledTextTest.java	Fri Aug 01 10:43:52 2014 -0400
@@ -27,16 +27,13 @@
 
 import javafx.css.CssMetaData;
 import com.sun.javafx.css.Stylesheet;
-import java.util.List;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
-import javafx.beans.value.WritableValue;
 import javafx.scene.Cursor;
+import javafx.scene.Group;
 import javafx.scene.Scene;
 import javafx.scene.control.Label;
 import javafx.scene.effect.BlendMode;
+import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
-import javafx.scene.paint.Paint;
 import javafx.scene.text.Font;
 import javafx.scene.text.TextAlignment;
 import javafx.stage.Stage;
@@ -371,5 +368,49 @@
         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
         assertTrue(labeledText.isUnderline());
     }
-    
+
+
+    @Test public void test_RT_37787() {
+
+        label = new Label("test_RT_37787");
+        label.getStyleClass().clear();
+        label.setId("test-rt-37787");
+
+        scene = new Scene(new Group(label));
+        String url = getClass().getResource("LabeledTextTest.css").toExternalForm();
+        scene.getStylesheets().add(url);
+
+        label.setFont(Font.font(10));
+        assertEquals(10, label.getFont().getSize(), .1);
+
+        stage.setScene(scene);
+        stage.show();
+
+        // If the actual size is 10 * 1.5 * 1.5 = 22.5, then we've encountered RT-37787!
+        double expected = Font.getDefault().getSize() * 1.5;
+        double actual = label.getFont().getSize();
+        assertEquals(expected, actual, .1);
+
+    }
+
+    @Test public void test_RT_37787_with_inline_style() {
+
+        label = new Label("test_RT_37787_with_inline_style");
+        label.setStyle("-fx-font-size: 1.231em;");
+        label.getStyleClass().clear();
+
+        VBox root = new VBox();
+        root.setStyle("-fx-font-size: 1.5em");
+        root.getChildren().add(label);
+
+        scene = new Scene(root);
+        stage.setScene(scene);
+        stage.show();
+
+        double expected = Font.getDefault().getSize() * 1.5 * 1.231;
+        double actual = label.getFont().getSize();
+        assertEquals(expected, actual, .1);
+
+    }
+
 }
--- a/modules/controls/src/test/resources/com/sun/javafx/scene/control/skin/LabeledTextTest.css	Fri Aug 01 10:43:46 2014 -0400
+++ b/modules/controls/src/test/resources/com/sun/javafx/scene/control/skin/LabeledTextTest.css	Fri Aug 01 10:43:52 2014 -0400
@@ -12,3 +12,5 @@
     -fx-underline: true;
 }
 
+#test-rt-37787 { -fx-font-size: 1.5em; }
+