1 package test.com.sun.javafx.css;
   2 
   3 
   4 import javafx.css.Declaration;
   5 import javafx.css.Rule;
   6 import javafx.css.Selector;
   7 import com.sun.javafx.css.StyleManager;
   8 import com.sun.javafx.css.StyleManager;
   9 import javafx.css.Stylesheet;
  10 import javafx.collections.FXCollections;
  11 import javafx.collections.ObservableList;
  12 import javafx.collections.ObservableSet;
  13 import javafx.css.CssMetaData;
  14 import javafx.css.PseudoClass;
  15 import javafx.css.Styleable;
  16 import javafx.scene.paint.Color;
  17 import org.junit.Ignore;
  18 import org.junit.Test;
  19 
  20 import java.io.FilePermission;
  21 import java.lang.reflect.ReflectPermission;
  22 import java.net.URL;
  23 import java.security.Permission;
  24 import java.util.List;
  25 import java.util.PropertyPermission;
  26 
  27 import static org.junit.Assert.*;
  28 import static org.junit.Assume.*;
  29 
  30 /**
  31  * Created by dgrieve on 9/17/14.
  32  */
  33 public class StylesheetWithSecurityManagerTest {
  34 
  35     static final Styleable styleable = new Styleable() {
  36         @Override
  37         public String getTypeSelector() {
  38             return "*";
  39         }
  40 
  41         @Override
  42         public String getId() {
  43             return null;
  44         }
  45 
  46         ObservableList<String> styleClasses = FXCollections.observableArrayList("root");
  47         @Override
  48         public ObservableList<String> getStyleClass() {
  49             return styleClasses;
  50         }
  51 
  52         @Override
  53         public String getStyle() {
  54             return null;
  55         }
  56 
  57         @Override
  58         public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
  59             return null;
  60         }
  61 
  62         @Override
  63         public Styleable getStyleableParent() {
  64             return null;
  65         }
  66 
  67         @Override
  68         public ObservableSet<PseudoClass> getPseudoClassStates() {
  69             return FXCollections.<PseudoClass>emptyObservableSet();
  70         }
  71     };
  72 
  73     @Test
  74     public void testRT_38395() throws Exception {
  75 
  76         System.setSecurityManager(new TestSecurityManager());
  77         Stylesheet stylesheet = StyleManager.loadStylesheet("com/sun/javafx/scene/control/skin/modena/modena.css");
  78         assertNotNull(stylesheet);
  79 
  80         Color base = null;
  81         for(Rule rule : stylesheet.getRules()) {
  82             for (Selector s : rule.getSelectors()) {
  83                 if (s.applies(styleable)) {
  84                     for(Declaration decl : rule.getDeclarations()) {
  85                         if ("-fx-base".equals(decl.getProperty())) {
  86                             base = (Color)decl.getParsedValue().convert(null);
  87                         }
  88                     }
  89                 }
  90             }
  91         }
  92         assertNotNull(base);
  93         Color expected = Color.web("#ececec");
  94         assertEquals(expected.getRed(), base.getGreen(), 1E-6);
  95         assertEquals(expected.getGreen(), base.getGreen(), 1E-6);
  96         assertEquals(expected.getBlue(), base.getBlue(), 1E-6);
  97     }
  98 
  99     @Test
 100     @Ignore("8149999")
 101     public void testRT_38395_the_sequel() throws Exception {
 102 
 103         System.setSecurityManager(new TestSecurityManager());
 104         Stylesheet stylesheet = StyleManager.loadStylesheet("test/com/sun/javafx/css/StylesheetTest.css");
 105         assertNotNull(stylesheet);
 106 
 107         Color hoverBase = null;
 108         for(Rule rule : stylesheet.getRules()) {
 109             for (Selector s : rule.getSelectors()) {
 110                 if (s.applies(styleable)) {
 111                     for(Declaration decl : rule.getDeclarations()) {
 112                         if ("-fx-hover-base".equals(decl.getProperty())) {
 113                             hoverBase = (Color)decl.getParsedValue().convert(null);
 114                         }
 115                     }
 116                 }
 117             }
 118         }
 119         assertNotNull(hoverBase);
 120         assertEquals(Color.YELLOW.getRed(), hoverBase.getRed(), 1E-6);
 121         assertEquals(Color.YELLOW.getGreen(), hoverBase.getGreen(), 1E-6);
 122         assertEquals(Color.YELLOW.getBlue(), hoverBase.getBlue(), 1E-6);
 123     }
 124 
 125     //
 126     // The code in URLConverter that this attempts to test only checks to see whether or not there is a SecurityManager.
 127     //
 128     static class TestSecurityManager extends SecurityManager {
 129         @Override
 130         public void checkPermission(Permission perm) {
 131             return;
 132         }
 133     }
 134 }
--- EOF ---