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