1 /* 2 * Copyright (c) 2010, 2017, 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 test.javafx.css; 27 28 import java.io.File; 29 import java.lang.reflect.InvocationTargetException; 30 import java.lang.reflect.Method; 31 import java.lang.reflect.Modifier; 32 import java.net.URL; 33 import java.util.ArrayList; 34 import java.util.Arrays; 35 import java.util.Collections; 36 import java.util.List; 37 import java.util.Set; 38 39 import com.sun.javafx.css.CascadingStyle; 40 import com.sun.javafx.css.ParsedValueImpl; 41 import com.sun.javafx.css.PseudoClassState; 42 import com.sun.javafx.css.StyleManager; 43 import test.com.sun.javafx.css.TestNode; 44 import test.com.sun.javafx.css.TestNodeBase; 45 import com.sun.javafx.sg.prism.NGNode; 46 import javafx.beans.value.WritableValue; 47 import javafx.scene.Group; 48 import javafx.scene.Node; 49 import javafx.scene.Scene; 50 import javafx.scene.paint.Color; 51 import javafx.scene.shape.Rectangle; 52 import javafx.scene.text.Font; 53 import javafx.scene.text.Text; 54 import javafx.stage.Stage; 55 import javafx.css.converter.BooleanConverter; 56 import com.sun.javafx.geom.BaseBounds; 57 import com.sun.javafx.geom.transform.BaseTransform; 58 import com.sun.javafx.jmx.MXNodeAlgorithm; 59 import com.sun.javafx.jmx.MXNodeAlgorithmContext; 60 import com.sun.javafx.scene.NodeHelper; 61 import javafx.css.CompoundSelector; 62 import javafx.css.CssMetaData; 63 import javafx.css.CssParser; 64 import javafx.css.CssParserShim; 65 import javafx.css.Declaration; 66 import javafx.css.DeclarationShim; 67 import javafx.css.FontCssMetaData; 68 import javafx.css.ParsedValue; 69 import javafx.css.PseudoClass; 70 import javafx.css.Rule; 71 import javafx.css.RuleShim; 72 import javafx.css.Selector; 73 import javafx.css.SelectorShim; 74 import javafx.css.SimpleSelector; 75 import javafx.css.SimpleSelectorShim; 76 import javafx.css.Style; 77 import javafx.css.StyleConverter; 78 import javafx.css.StyleOrigin; 79 import javafx.css.Styleable; 80 import javafx.css.StyleableProperty; 81 import javafx.css.Stylesheet; 82 import javafx.css.StylesheetShim; 83 import org.junit.Test; 84 85 import static org.junit.Assert.*; 86 87 88 public class CssMetaDataTest { 89 90 public CssMetaDataTest() { 91 } 92 93 private static CssMetaData get(List<CssMetaData<? extends Styleable, ?>> list, String prop) { 94 for (CssMetaData styleable : list) { 95 if (prop.equals(styleable.getProperty())) return styleable; 96 } 97 return null; 98 } 99 100 /** 101 * Test of getCssMetaData method of class Styleable. 102 */ 103 @Test 104 public void testGetCssMetaData_Styleable() { 105 Styleable styleable = new TestNode(); 106 List<CssMetaData<? extends Styleable, ?>> expResult = TestNode.getClassCssMetaData(); 107 List result = styleable.getCssMetaData(); 108 assertEquals(expResult, result); 109 } 110 111 @Test 112 public void testGetJavafxBeansProperty() { 113 TestNode testNode = new TestNode(); 114 WritableValue prop = TestNodeBase.StyleableProperties.TEST.getStyleableProperty(testNode); 115 assert(prop != null); 116 CssMetaData result = ((StyleableProperty)prop).getCssMetaData(); 117 assert(result == TestNodeBase.StyleableProperties.TEST); 118 } 119 120 /** 121 * Test of getProperty method, of class CssMetaData. 122 */ 123 @Test 124 public void testGetProperty() { 125 126 String expResult = "-fx-test"; 127 String result = TestNodeBase.StyleableProperties.TEST.getProperty(); 128 assertEquals(expResult, result); 129 } 130 131 /** 132 * Test of getConverter method, of class CssMetaData. 133 */ 134 @Test 135 public void testGetConverter() { 136 137 StyleConverter expResult = BooleanConverter.getInstance(); 138 StyleConverter result = TestNodeBase.StyleableProperties.TEST.getConverter(); 139 assertEquals(expResult, result); 140 } 141 142 /** 143 * Test of getInitialValue method, of class CssMetaData. 144 */ 145 @Test 146 public void testGetInitialValue() { 147 148 TestNode testNode = new TestNode(); 149 Double expResult = testNode.getXyzzy(); 150 Double result = (Double)TestNode.StyleableProperties.XYZZY.getInitialValue(testNode); 151 assertEquals(expResult, result); 152 153 } 154 155 /** 156 * Test of getSubProperties method, of class CssMetaData. 157 */ 158 @Test 159 public void testGetSubProperties() { 160 161 CssMetaData<TestNode,Font> fontProp = 162 new FontCssMetaData<TestNode>("-fx-font", Font.getDefault()) { 163 164 @Override 165 public boolean isSettable(TestNode n) { 166 return true; 167 } 168 169 @Override 170 public StyleableProperty<Font> getStyleableProperty(TestNode n) { 171 return null; 172 } 173 }; 174 175 List<CssMetaData<? extends Styleable, ?>> list = fontProp.getSubProperties(); 176 assertNotNull(list); 177 178 } 179 180 /** 181 * Test of isInherits method, of class CssMetaData. 182 */ 183 @Test 184 public void testIsInherits() { 185 186 boolean expResult = false; 187 boolean result = TestNode.StyleableProperties.XYZZY.isInherits(); 188 assertEquals(expResult, result); 189 190 } 191 192 /** 193 * Test of toString method, of class CssMetaData. 194 */ 195 @Test 196 public void testToString() { 197 198 CssMetaData<TestNode,Font> fontProp = 199 new FontCssMetaData<TestNode>("-fx-font", Font.getDefault()) { 200 201 @Override 202 public boolean isSettable(TestNode n) { 203 return true; 204 } 205 206 @Override 207 public StyleableProperty<Font> getStyleableProperty(TestNode n) { 208 return null; 209 } 210 }; 211 212 String string = fontProp.toString(); 213 assertNotNull(string); 214 215 } 216 217 /** 218 * Test of equals method, of class CssMetaData. 219 */ 220 @Test 221 public void testEquals() { 222 TestNode testNode = new TestNode(); 223 Node node = new Node() { 224 }; 225 226 CssMetaData testNodeOpacity = get(TestNode.getClassCssMetaData(), "-fx-opacity"); 227 CssMetaData nodeOpacity = get(Node.getClassCssMetaData(), "-fx-opacity"); 228 229 assertTrue(testNodeOpacity.equals(nodeOpacity)); 230 } 231 232 static int ord = 0; 233 static CascadingStyle createCascadingStyle(Selector selector, Declaration declaration) { 234 235 Set<PseudoClass> pseudoClasses = null; 236 if (selector instanceof SimpleSelector) { 237 238 pseudoClasses = 239 SimpleSelectorShim.getPseudoClassStates((SimpleSelector)selector); 240 } else { 241 242 pseudoClasses = new PseudoClassState(); 243 for (SimpleSelector sel : ((CompoundSelector)selector).getSelectors()) { 244 245 Set<PseudoClass> selectorPseudoClasses = SimpleSelectorShim.getPseudoClassStates(sel); 246 pseudoClasses.addAll(selectorPseudoClasses); 247 } 248 } 249 250 return new CascadingStyle( 251 new Style(selector, declaration), 252 pseudoClasses, 253 0, 254 ord++ 255 ); 256 } 257 258 @Test @org.junit.Ignore 259 public void testGetMatchingStyles() { 260 261 262 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 263 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 264 StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); 265 266 final List<Rule> rules = stylesheet.getRules(); 267 268 // 269 // .root { -fx-base: red; -fx-color: -fx-base; } 270 // 271 List<String> rootStyleClass = new ArrayList<String>(); 272 rootStyleClass.add("root"); 273 274 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 275 276 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 277 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 278 279 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 280 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 281 282 List<Selector> selectors = new ArrayList<Selector>(); 283 Collections.addAll(selectors, root); 284 285 List<Declaration> declarations = new ArrayList<Declaration>(); 286 Collections.addAll(declarations, fxBase, fxColor); 287 288 Rule baseRule = RuleShim.getRule(selectors, declarations); 289 rules.add(baseRule); 290 291 // 292 // .rect { -fx-fill: -fx-color; } 293 // 294 List<String> rectStyleClass = new ArrayList<String>(); 295 rectStyleClass.add("rect"); 296 297 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 298 299 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 300 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 301 302 selectors = new ArrayList<Selector>(); 303 Collections.addAll(selectors, rect); 304 305 declarations = new ArrayList<Declaration>(); 306 Collections.addAll(declarations, fxFill); 307 308 Rule rectRule = RuleShim.getRule(selectors, declarations); 309 rules.add(rectRule); 310 311 // .rect:hover { -fx-fill: yellow; } 312 List<String> pseudoclasses = new ArrayList<String>(); 313 pseudoclasses.add("hover"); 314 315 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 316 317 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 318 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 319 320 selectors = new ArrayList<Selector>(); 321 Collections.addAll(selectors, rectHover); 322 323 declarations = new ArrayList<Declaration>(); 324 Collections.addAll(declarations, fxFillHover); 325 326 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 327 rules.add(rectHoverRule); 328 329 List<Style> expecteds = new ArrayList<Style>(); 330 Collections.addAll(expecteds, 331 new Style(root, fxBase), 332 new Style(root, fxColor), 333 new Style(rect, fxFill), 334 new Style(rectHover, fxFillHover) 335 ); 336 337 final Rectangle rectangle = new Rectangle(); 338 rectangle.getStyleClass().add("rect"); 339 340 final Group group = new Group(); 341 group.getChildren().add(rectangle); 342 343 Scene scene = new Scene(group); 344 Stage stage = new Stage(); 345 stage.setScene(scene); 346 stage.show(); 347 348 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 349 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 350 351 // System.err.println("matchingStyles: " + matchingStyles); 352 // System.err.println("expecteds: " + expecteds); 353 // System.err.println("actuals: " + actuals); 354 355 assertEquals(expecteds.size(), actuals.size(), 0); 356 357 for (Style style : expecteds) { 358 if (!actuals.remove(style)) fail(); 359 } 360 assertTrue(actuals.isEmpty()); 361 } 362 363 @Test @org.junit.Ignore 364 public void testGetMatchingStylesWithInlineStyleOnParent() { 365 366 367 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 368 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 369 StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); 370 371 final List<Rule> rules = stylesheet.getRules(); 372 373 // 374 // .root { -fx-base: red; -fx-color: -fx-base; } 375 // 376 List<String> rootStyleClass = new ArrayList<String>(); 377 rootStyleClass.add("root"); 378 379 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 380 381 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 382 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 383 384 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 385 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 386 387 List<Selector> selectors = new ArrayList<Selector>(); 388 Collections.addAll(selectors, root); 389 390 List<Declaration> declarations = new ArrayList<Declaration>(); 391 Collections.addAll(declarations, fxBase, fxColor); 392 393 Rule baseRule = RuleShim.getRule(selectors, declarations); 394 rules.add(baseRule); 395 396 // 397 // .rect { -fx-fill: -fx-color; } 398 // 399 List<String> rectStyleClass = new ArrayList<String>(); 400 rectStyleClass.add("rect"); 401 402 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 403 404 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 405 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 406 407 selectors = new ArrayList<Selector>(); 408 Collections.addAll(selectors, rect); 409 410 declarations = new ArrayList<Declaration>(); 411 Collections.addAll(declarations, fxFill); 412 413 Rule rectRule = RuleShim.getRule(selectors, declarations); 414 rules.add(rectRule); 415 416 // .rect:hover { -fx-fill: yellow; } 417 List<String> pseudoclasses = new ArrayList<String>(); 418 pseudoclasses.add("hover"); 419 420 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 421 422 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 423 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 424 425 selectors = new ArrayList<Selector>(); 426 Collections.addAll(selectors, rectHover); 427 428 declarations = new ArrayList<Declaration>(); 429 Collections.addAll(declarations, fxFillHover); 430 431 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 432 rules.add(rectHoverRule); 433 434 // Declaration now checks origin, so we need to make this expected 435 // value look like it came from an inline 436 final Declaration decl = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false); 437 438 Stylesheet ss = new StylesheetShim(null) { 439 { 440 setOrigin(StyleOrigin.INLINE); 441 getRules().add( 442 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(decl)) 443 ); 444 } 445 }; 446 447 List<Style> expecteds = new ArrayList<Style>(); 448 Collections.addAll(expecteds, 449 new Style(SelectorShim.getUniversalSelector(), decl), 450 new Style(root, fxBase), 451 new Style(root, fxColor), 452 new Style(rect, fxFill), 453 new Style(rectHover, fxFillHover) 454 ); 455 456 final Rectangle rectangle = new Rectangle(); 457 rectangle.getStyleClass().add("rect"); 458 459 final Group group = new Group(); 460 group.setStyle("-fx-base: green;"); 461 group.getChildren().add(rectangle); 462 463 Scene scene = new Scene(group); 464 Stage stage = new Stage(); 465 stage.setScene(scene); 466 stage.show(); 467 468 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 469 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 470 471 // System.err.println("matchingStyles: " + matchingStyles); 472 // System.err.println("expecteds: " + expecteds); 473 // System.err.println("actuals: " + actuals); 474 475 assertEquals(expecteds.size(), actuals.size(), 0); 476 477 // inline style should be first 478 assertEquals(expecteds.get(0), actuals.get(0)); 479 480 for (Style style : expecteds) { 481 if (!actuals.remove(style)) fail(); 482 } 483 assertTrue(actuals.isEmpty()); 484 } 485 486 @Test @org.junit.Ignore 487 public void testGetMatchingStylesWithInlineStyleOnLeaf() { 488 489 490 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 491 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 492 StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); 493 494 final List<Rule> rules = stylesheet.getRules(); 495 496 // 497 // .root { -fx-base: red; -fx-color: -fx-base; } 498 // 499 List<String> rootStyleClass = new ArrayList<String>(); 500 rootStyleClass.add("root"); 501 502 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 503 504 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 505 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 506 507 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 508 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 509 510 List<Selector> selectors = new ArrayList<Selector>(); 511 Collections.addAll(selectors, root); 512 513 List<Declaration> declarations = new ArrayList<Declaration>(); 514 Collections.addAll(declarations, fxBase, fxColor); 515 516 Rule baseRule = RuleShim.getRule(selectors, declarations); 517 rules.add(baseRule); 518 519 // 520 // .rect { -fx-fill: -fx-color; } 521 // 522 List<String> rectStyleClass = new ArrayList<String>(); 523 rectStyleClass.add("rect"); 524 525 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 526 527 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 528 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 529 530 selectors = new ArrayList<Selector>(); 531 Collections.addAll(selectors, rect); 532 533 declarations = new ArrayList<Declaration>(); 534 Collections.addAll(declarations, fxFill); 535 536 Rule rectRule = RuleShim.getRule(selectors, declarations); 537 rules.add(rectRule); 538 539 // .rect:hover { -fx-fill: yellow; } 540 List<String> pseudoclasses = new ArrayList<String>(); 541 pseudoclasses.add("hover"); 542 543 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 544 545 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 546 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 547 548 selectors = new ArrayList<Selector>(); 549 Collections.addAll(selectors, rectHover); 550 551 declarations = new ArrayList<Declaration>(); 552 Collections.addAll(declarations, fxFillHover); 553 554 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 555 rules.add(rectHoverRule); 556 557 // Declaration now checks origin, so we need to make this expected 558 // value look like it came from an inline 559 final Declaration decl = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false); 560 561 Stylesheet ss = new StylesheetShim(null) { 562 { 563 setOrigin(StyleOrigin.INLINE); 564 getRules().add( 565 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(decl)) 566 ); 567 } 568 }; 569 570 List<Style> expecteds = new ArrayList<Style>(); 571 Collections.addAll(expecteds, 572 new Style(SelectorShim.getUniversalSelector(), decl), 573 new Style(root, fxBase), 574 new Style(root, fxColor), 575 new Style(rect, fxFill), 576 new Style(rectHover, fxFillHover) 577 ); 578 579 final Rectangle rectangle = new Rectangle(); 580 rectangle.getStyleClass().add("rect"); 581 rectangle.setStyle("-fx-base: green;"); 582 583 final Group group = new Group(); 584 group.getChildren().add(rectangle); 585 586 Scene scene = new Scene(group); 587 Stage stage = new Stage(); 588 stage.setScene(scene); 589 stage.show(); 590 591 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 592 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 593 594 // System.err.println("matchingStyles: " + matchingStyles); 595 // System.err.println("expecteds: " + expecteds); 596 // System.err.println("actuals: " + actuals); 597 598 assertEquals(expecteds.size(), actuals.size(), 0); 599 600 // inline style should be first 601 assertEquals(expecteds.get(0), actuals.get(0)); 602 603 for (Style style : expecteds) { 604 if (!actuals.remove(style)) fail(); 605 } 606 assertTrue(actuals.isEmpty()); 607 } 608 609 @Test @org.junit.Ignore 610 public void testGetMatchingStylesWithInlineStyleOnRootAndLeaf() { 611 612 613 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 614 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 615 StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); 616 617 final List<Rule> rules = stylesheet.getRules(); 618 619 // 620 // .root { -fx-base: red; -fx-color: -fx-base; } 621 // 622 List<String> rootStyleClass = new ArrayList<String>(); 623 rootStyleClass.add("root"); 624 625 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 626 627 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 628 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 629 630 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 631 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 632 633 List<Selector> selectors = new ArrayList<Selector>(); 634 Collections.addAll(selectors, root); 635 636 List<Declaration> declarations = new ArrayList<Declaration>(); 637 Collections.addAll(declarations, fxBase, fxColor); 638 639 Rule baseRule = RuleShim.getRule(selectors, declarations); 640 rules.add(baseRule); 641 642 // 643 // .rect { -fx-fill: -fx-color; } 644 // 645 List<String> rectStyleClass = new ArrayList<String>(); 646 rectStyleClass.add("rect"); 647 648 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 649 650 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 651 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 652 653 selectors = new ArrayList<Selector>(); 654 Collections.addAll(selectors, rect); 655 656 declarations = new ArrayList<Declaration>(); 657 Collections.addAll(declarations, fxFill); 658 659 Rule rectRule = RuleShim.getRule(selectors, declarations); 660 rules.add(rectRule); 661 662 // .rect:hover { -fx-fill: yellow; } 663 List<String> pseudoclasses = new ArrayList<String>(); 664 pseudoclasses.add("hover"); 665 666 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 667 668 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 669 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 670 671 selectors = new ArrayList<Selector>(); 672 Collections.addAll(selectors, rectHover); 673 674 declarations = new ArrayList<Declaration>(); 675 Collections.addAll(declarations, fxFillHover); 676 677 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 678 rules.add(rectHoverRule); 679 680 // Declaration now checks origin, so we need to make this expected 681 // value look like it came from an inline 682 final Declaration gdecl = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false); 683 final Declaration ydecl = DeclarationShim.getDeclaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false); 684 685 Stylesheet ss = new StylesheetShim(null) { 686 { 687 setOrigin(StyleOrigin.INLINE); 688 Collections.addAll(getRules(), 689 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(gdecl)), 690 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(ydecl)) 691 ); 692 } 693 }; 694 695 List<Style> expecteds = new ArrayList<Style>(); 696 Collections.addAll(expecteds, 697 new Style(SelectorShim.getUniversalSelector(), ydecl), 698 new Style(SelectorShim.getUniversalSelector(), gdecl), 699 new Style(root, fxBase), 700 new Style(root, fxColor), 701 new Style(rect, fxFill), 702 new Style(rectHover, fxFillHover) 703 ); 704 705 final Rectangle rectangle = new Rectangle(); 706 rectangle.getStyleClass().add("rect"); 707 rectangle.setStyle("-fx-base: green;"); 708 709 final Group group = new Group(); 710 group.setStyle("-fx-color: yellow;"); 711 group.getChildren().add(rectangle); 712 713 Scene scene = new Scene(group); 714 Stage stage = new Stage(); 715 stage.setScene(scene); 716 stage.show(); 717 718 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 719 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 720 721 // System.err.println("matchingStyles: " + matchingStyles); 722 // System.err.println("expecteds: " + expecteds); 723 // System.err.println("actuals: " + actuals); 724 725 assertEquals(expecteds.size(), actuals.size(), 0); 726 727 // inline style should be first 728 assertEquals(expecteds.get(0), actuals.get(0)); 729 730 for (Style style : expecteds) { 731 if (!actuals.remove(style)) fail(style.toString()); 732 } 733 assertTrue(actuals.isEmpty()); 734 } 735 736 @Test @org.junit.Ignore 737 public void testGetMatchingStylesShouldNotReturnAncestorPropertyIfNotInherited() { 738 739 740 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 741 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 742 StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); 743 744 final List<Rule> rules = stylesheet.getRules(); 745 746 // 747 // .root { -fx-base: red; -fx-color: -fx-base; } 748 // 749 List<String> rootStyleClass = new ArrayList<String>(); 750 rootStyleClass.add("root"); 751 752 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 753 754 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 755 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 756 757 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 758 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 759 760 ParsedValueImpl<Color,Color> fxFillShouldNotMatchValue = new ParsedValueImpl<Color,Color>(Color.RED, null); 761 Declaration fxFillShouldNotMatch = DeclarationShim.getDeclaration("-fx-fill", fxFillShouldNotMatchValue, false); 762 763 List<Selector> selectors = new ArrayList<Selector>(); 764 Collections.addAll(selectors, root); 765 766 List<Declaration> declarations = new ArrayList<Declaration>(); 767 Collections.addAll(declarations, fxBase, fxColor, fxFillShouldNotMatch); 768 769 Rule baseRule = RuleShim.getRule(selectors, declarations); 770 rules.add(baseRule); 771 772 // 773 // .rect { -fx-fill: -fx-color; } 774 // 775 List<String> rectStyleClass = new ArrayList<String>(); 776 rectStyleClass.add("rect"); 777 778 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 779 780 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 781 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 782 783 selectors = new ArrayList<Selector>(); 784 Collections.addAll(selectors, rect); 785 786 declarations = new ArrayList<Declaration>(); 787 Collections.addAll(declarations, fxFill); 788 789 Rule rectRule = RuleShim.getRule(selectors, declarations); 790 rules.add(rectRule); 791 792 // .rect:hover { -fx-fill: yellow; } 793 List<String> pseudoclasses = new ArrayList<String>(); 794 pseudoclasses.add("hover"); 795 796 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 797 798 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 799 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 800 801 selectors = new ArrayList<Selector>(); 802 Collections.addAll(selectors, rectHover); 803 804 declarations = new ArrayList<Declaration>(); 805 Collections.addAll(declarations, fxFillHover); 806 807 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 808 rules.add(rectHoverRule); 809 810 List<Style> expecteds = new ArrayList<Style>(); 811 Collections.addAll(expecteds, 812 new Style(root, fxBase), 813 new Style(root, fxColor), 814 new Style(rect, fxFill), 815 new Style(rectHover, fxFillHover) 816 ); 817 818 final Rectangle rectangle = new Rectangle(); 819 rectangle.getStyleClass().add("rect"); 820 821 final Group group = new Group(); 822 group.getChildren().add(rectangle); 823 824 Scene scene = new Scene(group); 825 Stage stage = new Stage(); 826 stage.setScene(scene); 827 stage.show(); 828 829 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 830 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 831 832 // System.err.println("matchingStyles: " + matchingStyles); 833 // System.err.println("expecteds: " + expecteds); 834 // System.err.println("actuals: " + actuals); 835 836 assertEquals(expecteds.size(), actuals.size(), 0); 837 838 for (Style style : expecteds) { 839 if (!actuals.remove(style)) fail(); 840 } 841 assertTrue(actuals.isEmpty()); 842 } 843 844 845 @Test @org.junit.Ignore 846 public void testGetMatchingStylesShouldNotReturnInlineAncestorPropertyIfNotInherited() { 847 848 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 849 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 850 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet); 851 852 final List<Rule> rules = stylesheet.getRules(); 853 854 List<String> rootStyleClass = new ArrayList<String>(); 855 rootStyleClass.add("root"); 856 857 List<String> rectStyleClass = new ArrayList<String>(); 858 rectStyleClass.add("rect"); 859 860 // 861 // .root { -fx-base: red; -fx-color: -fx-base; } 862 // 863 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 864 865 ParsedValue fxBaseValue = new CssParserShim().parseExpr("-fx-base", "red"); 866 Declaration fxBase = DeclarationShim.getDeclaration("-fx-base", fxBaseValue, false); 867 868 ParsedValueImpl<String,String> fxColorValue = new ParsedValueImpl<String,String>(fxBase.getProperty(), null, true); 869 Declaration fxColor = DeclarationShim.getDeclaration("-fx-color", fxColorValue, false); 870 871 ParsedValueImpl<Color,Color> fxFillShouldNotMatchValue = new ParsedValueImpl<Color,Color>(Color.RED, null); 872 Declaration fxFillShouldNotMatch = DeclarationShim.getDeclaration("-fx-fill", fxFillShouldNotMatchValue, false); 873 874 List<Selector> selectors = new ArrayList<Selector>(); 875 Collections.addAll(selectors, root); 876 877 List<Declaration> declarations = new ArrayList<Declaration>(); 878 Collections.addAll(declarations, fxBase, fxColor, fxFillShouldNotMatch); 879 880 Rule baseRule = RuleShim.getRule(selectors, declarations); 881 rules.add(baseRule); 882 883 // 884 // .rect { -fx-fill: -fx-color; } 885 // 886 Selector rect = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 887 888 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "-fx-color"); 889 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 890 891 selectors = new ArrayList<Selector>(); 892 Collections.addAll(selectors, rect); 893 894 declarations = new ArrayList<Declaration>(); 895 Collections.addAll(declarations, fxFill); 896 897 Rule rectRule = RuleShim.getRule(selectors, declarations); 898 rules.add(rectRule); 899 900 // .rect:hover { -fx-fill: yellow; } 901 List<String> pseudoclasses = new ArrayList<String>(); 902 pseudoclasses.add("hover"); 903 904 Selector rectHover = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, pseudoclasses, null); 905 906 ParsedValueImpl<Color,Color> fxFillHoverValue = new ParsedValueImpl<Color,Color>(Color.YELLOW, null); 907 Declaration fxFillHover = DeclarationShim.getDeclaration("-fx-fill", fxFillHoverValue, false); 908 909 selectors = new ArrayList<Selector>(); 910 Collections.addAll(selectors, rectHover); 911 912 declarations = new ArrayList<Declaration>(); 913 Collections.addAll(declarations, fxFillHover); 914 915 Rule rectHoverRule = RuleShim.getRule(selectors, declarations); 916 rules.add(rectHoverRule); 917 918 List<Style> expecteds = new ArrayList<Style>(); 919 Collections.addAll(expecteds, 920 new Style(root, fxBase), 921 new Style(root, fxColor), 922 new Style(rect, fxFill), 923 new Style(rectHover, fxFillHover) 924 ); 925 926 final Rectangle rectangle = new Rectangle(); 927 rectangle.getStyleClass().add("rect"); 928 929 final Group group = new Group(); 930 group.getChildren().add(rectangle); 931 932 Scene scene = new Scene(group); 933 Stage stage = new Stage(); 934 stage.setScene(scene); 935 stage.show(); 936 937 final CssMetaData FILL = get(rectangle.getCssMetaData(), "-fx-fill"); 938 final List<Style> actuals = NodeHelper.getMatchingStyles(FILL, rectangle); 939 940 // System.err.println("matchingStyles: " + matchingStyles); 941 // System.err.println("expecteds: " + expecteds); 942 // System.err.println("actuals: " + actuals); 943 944 for (Style style : expecteds) { 945 actuals.remove(style); 946 } 947 assertTrue(actuals.toString(), actuals.isEmpty()); 948 } 949 950 @Test @org.junit.Ignore 951 public void testGetMatchingStylesReturnsInheritedProperty() { 952 953 954 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 955 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 956 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet); 957 958 final List<Rule> rules = stylesheet.getRules(); 959 960 // 961 // .root { -fx-base: red; -fx-color: -fx-base; } 962 // 963 List<String> rootStyleClass = new ArrayList<String>(); 964 rootStyleClass.add("root"); 965 966 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 967 968 ParsedValue<Color,Color> fxFontShouldInheritValue = new CssParserShim().parseExpr("-fx-font", "12px system"); 969 Declaration fxFontShouldInherit = DeclarationShim.getDeclaration("-fx-font", fxFontShouldInheritValue, false); 970 971 List<Selector> selectors = new ArrayList<Selector>(); 972 Collections.addAll(selectors, root); 973 974 List<Declaration> declarations = new ArrayList<Declaration>(); 975 Collections.addAll(declarations, fxFontShouldInherit); 976 977 Rule baseRule = RuleShim.getRule(selectors, declarations); 978 rules.add(baseRule); 979 980 // 981 // .text { -fx-fill: -fx-color; } 982 // 983 List<String> textStyleClass = new ArrayList<String>(); 984 textStyleClass.add("text"); 985 986 Selector textSelector = SimpleSelectorShim.getSimpleSelector("*", textStyleClass, null, null); 987 988 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "red"); 989 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 990 991 selectors = new ArrayList<Selector>(); 992 Collections.addAll(selectors, textSelector); 993 994 declarations = new ArrayList<Declaration>(); 995 Collections.addAll(declarations, fxFill); 996 997 Rule rectRule = RuleShim.getRule(selectors, declarations); 998 rules.add(rectRule); 999 1000 List<Style> expecteds = new ArrayList<Style>(); 1001 Collections.addAll(expecteds, 1002 new Style(root, fxFontShouldInherit) 1003 ); 1004 1005 final Text text = new Text("text"); 1006 text.getStyleClass().add("text"); 1007 1008 final Group group = new Group(); 1009 group.getChildren().add(text); 1010 1011 Scene scene = new Scene(group); 1012 Stage stage = new Stage(); 1013 stage.setScene(scene); 1014 stage.show(); 1015 1016 final CssMetaData FONT = get(text.getCssMetaData(), "-fx-font"); 1017 final List<Style> actuals = NodeHelper.getMatchingStyles(FONT, text); 1018 1019 // System.err.println("matchingStyles: " + matchingStyles); 1020 // System.err.println("expecteds: " + expecteds); 1021 // System.err.println("actuals: " + actuals); 1022 1023 assertEquals(expecteds.size(), actuals.size(), 0); 1024 1025 for (Style style : expecteds) { 1026 if (!actuals.remove(style)) fail(); 1027 } 1028 assertTrue(actuals.isEmpty()); 1029 } 1030 1031 @Test @org.junit.Ignore 1032 public void testGetMatchingStylesReturnsSubProperty() { 1033 1034 final Stylesheet stylesheet = StylesheetShim.getStylesheet(); 1035 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 1036 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet); 1037 1038 final List<Rule> rules = stylesheet.getRules(); 1039 1040 // 1041 // .root { -fx-base: red; -fx-color: -fx-base; } 1042 // 1043 List<String> rootStyleClass = new ArrayList<String>(); 1044 rootStyleClass.add("root"); 1045 1046 Selector root = SimpleSelectorShim.getSimpleSelector("*", rootStyleClass, null, null); 1047 1048 ParsedValue<Color,Color> fxFontShouldInheritValue = new CssParserShim().parseExpr("-fx-font", "12px system"); 1049 Declaration fxFontShouldInherit = DeclarationShim.getDeclaration("-fx-font", fxFontShouldInheritValue, false); 1050 1051 List<Selector> selectors = new ArrayList<Selector>(); 1052 Collections.addAll(selectors, root); 1053 1054 List<Declaration> declarations = new ArrayList<Declaration>(); 1055 Collections.addAll(declarations, fxFontShouldInherit); 1056 1057 Rule baseRule = RuleShim.getRule(selectors, declarations); 1058 rules.add(baseRule); 1059 1060 // 1061 // .text { -fx-fill: -fx-color; } 1062 // 1063 List<String> rectStyleClass = new ArrayList<String>(); 1064 rectStyleClass.add("text"); 1065 1066 Selector textSelector = SimpleSelectorShim.getSimpleSelector("*", rectStyleClass, null, null); 1067 1068 ParsedValue fxFillValue = new CssParserShim().parseExpr("-fx-fill", "red"); 1069 Declaration fxFill = DeclarationShim.getDeclaration("-fx-fill", fxFillValue, false); 1070 1071 ParsedValue fxFontFamilyValue = new CssParserShim().parseExpr("-fx-font-family", "arial"); 1072 Declaration fxFontFamily = DeclarationShim.getDeclaration("-fx-font-family", fxFontFamilyValue, false); 1073 1074 selectors = new ArrayList<Selector>(); 1075 Collections.addAll(selectors, textSelector); 1076 1077 declarations = new ArrayList<Declaration>(); 1078 Collections.addAll(declarations, fxFill, fxFontFamily); 1079 1080 Rule rectRule = RuleShim.getRule(selectors, declarations); 1081 rules.add(rectRule); 1082 1083 List<Style> expecteds = new ArrayList<Style>(); 1084 Collections.addAll(expecteds, 1085 new Style(textSelector, fxFontFamily), 1086 new Style(root, fxFontShouldInherit) 1087 ); 1088 1089 final Text text = new Text(); 1090 text.getStyleClass().add("text"); 1091 1092 final Group group = new Group(); 1093 group.getChildren().add(text); 1094 1095 Scene scene = new Scene(group); 1096 Stage stage = new Stage(); 1097 stage.setScene(scene); 1098 stage.show(); 1099 1100 final CssMetaData FONT = get(text.getCssMetaData(), "-fx-font"); 1101 final List<Style> actuals = NodeHelper.getMatchingStyles(FONT, text); 1102 1103 // System.err.println("matchingStyles: " + matchingStyles); 1104 // System.err.println("expecteds: " + expecteds); 1105 // System.err.println("actuals: " + actuals); 1106 1107 assertEquals(expecteds.size(), actuals.size(), 0); 1108 1109 for (Style style : expecteds) { 1110 if (!actuals.remove(style)) fail(); 1111 } 1112 assertTrue(actuals.isEmpty()); 1113 } 1114 1115 @Test 1116 public void testRT18097() { 1117 try { 1118 File f = System.getProperties().containsKey("CSS_META_DATA_TEST_DIR") ? 1119 new File(System.getProperties().get("CSS_META_DATA_TEST_DIR").toString()) : 1120 null; 1121 if (f == null) { 1122 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 1123 URL base = cl.getResource("javafx/../javafx"); 1124 f = new File(base.toURI()); 1125 } 1126 //System.err.println(f.getPath()); 1127 assertTrue("" + f.getCanonicalPath() + " is not a directory", f.isDirectory()); 1128 recursiveCheck(f, f.getPath().length() - 7); 1129 } catch (Exception ex) { 1130 ex.printStackTrace(System.err); 1131 fail(ex.getMessage()); 1132 } 1133 } 1134 1135 private static void checkClass(Class someClass) { 1136 1137 if (javafx.scene.Node.class.isAssignableFrom(someClass) && 1138 Modifier.isAbstract(someClass.getModifiers()) == false) { 1139 1140 String what = someClass.getName(); 1141 try { 1142 // should get NoSuchMethodException if ctor is not public 1143 // Constructor ctor = someClass.getConstructor((Class[])null); 1144 Method m = someClass.getMethod("getClassCssMetaData", (Class[]) null); 1145 // Node node = (Node)ctor.newInstance((Object[])null); 1146 Node node = (Node)someClass.newInstance(); 1147 List<CssMetaData<? extends Styleable, ?>> list = (List<CssMetaData<? extends Styleable, ?>>)m.invoke(null); 1148 if(list == null || list.isEmpty()) return; 1149 1150 for (CssMetaData styleable : list) { 1151 1152 what = someClass.getName() + " " + styleable.getProperty(); 1153 WritableValue writable = styleable.getStyleableProperty(node); 1154 assertNotNull(what, writable); 1155 1156 Object defaultValue = writable.getValue(); 1157 Object initialValue = styleable.getInitialValue((Node) someClass.newInstance()); 1158 1159 if (defaultValue instanceof Number) { 1160 // 5 and 5.0 are not the same according to equals, 1161 // but they should be... 1162 assert(initialValue instanceof Number); 1163 double d1 = ((Number)defaultValue).doubleValue(); 1164 double d2 = ((Number)initialValue).doubleValue(); 1165 assertEquals(what, d1, d2, .001); 1166 1167 } else if (defaultValue != null && defaultValue.getClass().isArray()) { 1168 assertTrue(what, Arrays.equals((Object[])defaultValue, (Object[])initialValue)); 1169 } else { 1170 assertEquals(what, defaultValue, initialValue); 1171 } 1172 1173 } 1174 1175 } catch (NoSuchMethodException ex) { 1176 System.err.println("NoSuchMethodException: " + what); 1177 } catch (IllegalAccessException ex) { 1178 System.err.println("IllegalAccessException: " + what); 1179 } catch (IllegalArgumentException ex) { 1180 System.err.println("IllegalArgumentException: " + what); 1181 } catch (InvocationTargetException ex) { 1182 System.err.println("InvocationTargetException: " + what); 1183 } catch (InstantiationException ex) { 1184 System.err.println("InstantiationException: " + what); 1185 } 1186 } 1187 } 1188 1189 private static void checkDirectory(File directory, final int pathLength) { 1190 if (directory.isDirectory()) { 1191 1192 for (File file : directory.listFiles()) { 1193 if (file.isFile() && file.getName().endsWith(".class")) { 1194 final int len = file.getPath().length() - ".class".length(); 1195 final String clName = 1196 file.getPath().substring(pathLength+1, len).replace(File.separatorChar,'.'); 1197 try { 1198 final Class cl = Class.forName(clName); 1199 if (cl != null) checkClass(cl); 1200 } catch(ClassNotFoundException ex) { 1201 System.err.println(ex.toString() + " " + clName); 1202 } 1203 } 1204 } 1205 } 1206 } 1207 1208 private static void recursiveCheck(File directory, int pathLength) { 1209 if (directory.isDirectory()) { 1210 // System.err.println(directory.getPath()); 1211 checkDirectory(directory, pathLength); 1212 1213 for (File subFile : directory.listFiles()) { 1214 recursiveCheck(subFile, pathLength); 1215 } 1216 } 1217 } 1218 1219 @Test @org.junit.Ignore("tested CssMetaData#set method, which is deprecated") 1220 public void testRT_21185() { 1221 1222 Color c1 = new Color(.1,.2,.3,1.0); 1223 Color c2 = new Color(.1,.2,.3,1.0); 1224 1225 Rectangle rect = new Rectangle(); 1226 rect.setFill(c1); 1227 1228 StyleableProperty fill = (StyleableProperty)rect.fillProperty(); 1229 StyleOrigin origin = ((StyleableProperty)rect.fillProperty()).getStyleOrigin(); 1230 1231 // set should not change the value if the values are equal and origin is same 1232 assertEquals(c1, c2); 1233 fill.applyStyle(origin, c2); 1234 1235 assertSame(c1,rect.getFill()); // instance should not change. 1236 1237 // set should change the value if the values are not equal. 1238 c2 = new Color(.3,.2,.1,1.0); 1239 fill.applyStyle(origin, c2); 1240 assertSame(c2,rect.getFill()); 1241 1242 // set should change the value if the origin is not the same 1243 fill.applyStyle(StyleOrigin.INLINE, c2); 1244 origin = ((StyleableProperty)rect.fillProperty()).getStyleOrigin(); 1245 assertSame(StyleOrigin.INLINE, origin); 1246 1247 // set should change the value if one is null and the other is not. 1248 rect.setFill(null); 1249 fill.applyStyle(origin, c2); 1250 assertSame(c2, rect.getFill()); 1251 1252 // set should change the value if one is null and the other is not 1253 fill.applyStyle(origin, null); 1254 assertNull(rect.getFill()); 1255 1256 } 1257 1258 1259 @Test @org.junit.Ignore 1260 public void testRT_24606() { 1261 1262 final Stylesheet stylesheet = new CssParser().parse( 1263 ".root { -fx-base: red; }" + 1264 ".group { -fx-color: -fx-base; }" + 1265 ".text { -fx-fill: -fx-color; }" 1266 ); 1267 stylesheet.setOrigin(StyleOrigin.USER_AGENT); 1268 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet); 1269 1270 final Text text = new Text("HelloWorld"); 1271 text.getStyleClass().add("text"); 1272 text.setFill(Color.BLUE); 1273 1274 final Group group = new Group(); 1275 group.getStyleClass().add("group"); 1276 group.getChildren().add(text); 1277 1278 final Group root = new Group(); 1279 root.getChildren().add(group); 1280 1281 Scene scene = new Scene(root); 1282 Stage stage = new Stage(); 1283 stage.setScene(scene); 1284 stage.show(); 1285 1286 CssMetaData prop = ((StyleableProperty)text.fillProperty()).getCssMetaData(); 1287 List list = NodeHelper.getMatchingStyles(prop, text); 1288 1289 assertEquals(3, list.size(), 0); 1290 1291 } 1292 1293 }