modules/graphics/src/test/java/javafx/css/CssParserTest.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,31 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package com.sun.javafx.css.parser;
import com.sun.javafx.css.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
--- 21,31 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package javafx.css;
import com.sun.javafx.css.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
*** 45,60 ****
import javafx.util.Duration;
import org.junit.Test;
import static org.junit.Assert.*;
! public class CSSParserTest {
@Test
public void testRT_16959() {
! CSSParser instance = CSSParser.getInstance();
// RT-16959 is an infinite loop on incomplete linear gradient
ParsedValue result = instance.parseExpr("-fx-background-color", "linear-gradient(from 0% 0% to 0% 100%, )");
assertNull("parseExpr", result);
--- 45,60 ----
import javafx.util.Duration;
import org.junit.Test;
import static org.junit.Assert.*;
! public class CssParserTest {
@Test
public void testRT_16959() {
! CssParser instance = new CssParser();
// RT-16959 is an infinite loop on incomplete linear gradient
ParsedValue result = instance.parseExpr("-fx-background-color", "linear-gradient(from 0% 0% to 0% 100%, )");
assertNull("parseExpr", result);
*** 104,114 ****
+ "rgba(248, 248, 246, 0.3) 55%, "
+ "rgba(141, 138, 125, 0.0), "
+ "); "
+ "}";
! CSSParser instance = CSSParser.getInstance();
Stylesheet ss = instance.parse(stylesheetText);
assertNotNull(ss);
List<Rule> rules = ss.getRules();
--- 104,114 ----
+ "rgba(248, 248, 246, 0.3) 55%, "
+ "rgba(141, 138, 125, 0.0), "
+ "); "
+ "}";
! CssParser instance = new CssParser();
Stylesheet ss = instance.parse(stylesheetText);
assertNotNull(ss);
List<Rule> rules = ss.getRules();
*** 134,144 ****
}
@Test
public void testParseSizeWithInvalidDigits() {
! CSSParser instance = CSSParser.getInstance();
// RT-16959 is an infinite loop on incomplete linear gradient
ParsedValue result = instance.parseExpr("-fx-font-size", "10ptx");
assertNull("parseExpr", result);
--- 134,144 ----
}
@Test
public void testParseSizeWithInvalidDigits() {
! CssParser instance = new CssParser();
// RT-16959 is an infinite loop on incomplete linear gradient
ParsedValue result = instance.parseExpr("-fx-font-size", "10ptx");
assertNull("parseExpr", result);
*** 165,175 ****
@Test
public void testRT_17830() {
! CSSParser instance = CSSParser.getInstance();
// The empty declaration should be skipped. The stylesheet should have
// two declarations.
Stylesheet ss = instance.parse(".rt17830 {-fx-fill: red;; -fx-stroke: yellow; }");
--- 165,175 ----
@Test
public void testRT_17830() {
! CssParser instance = new CssParser();
// The empty declaration should be skipped. The stylesheet should have
// two declarations.
Stylesheet ss = instance.parse(".rt17830 {-fx-fill: red;; -fx-stroke: yellow; }");
*** 193,203 ****
}
@Test
public void testRT_20311() {
! CSSParser instance = CSSParser.getInstance();
try {
instance.parse(".rt-20311 { -fx-background-color:red\n-fx-border-color:black; }");
} catch (Exception e) {
fail(e.toString());
--- 193,203 ----
}
@Test
public void testRT_20311() {
! CssParser instance = new CssParser();
try {
instance.parse(".rt-20311 { -fx-background-color:red\n-fx-border-color:black; }");
} catch (Exception e) {
fail(e.toString());
*** 213,223 ****
"font-style: normal;\n" +
"font-weight: 400;\n" +
"src: local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');\n"+
"}";
! Stylesheet stylesheet = CSSParser.getInstance().parse(css);
int nFontFaceSrcs = checkFontFace(stylesheet);
assertEquals(3, nFontFaceSrcs);
}
--- 213,223 ----
"font-style: normal;\n" +
"font-weight: 400;\n" +
"src: local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');\n"+
"}";
! Stylesheet stylesheet = new CssParser().parse(css);
int nFontFaceSrcs = checkFontFace(stylesheet);
assertEquals(3, nFontFaceSrcs);
}
*** 231,241 ****
"font-weight: 400;\n" +
"src: local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff'),\n"+
" local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');\n"+
"}";
! Stylesheet stylesheet = CSSParser.getInstance().parse(css);
int nFontFaceSrcs = checkFontFace(stylesheet);
assertEquals(6, nFontFaceSrcs);
}
--- 231,241 ----
"font-weight: 400;\n" +
"src: local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff'),\n"+
" local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCps73hpw3pgy2gAi-Ip7WPMi0.woff) format('woff');\n"+
"}";
! Stylesheet stylesheet = new CssParser().parse(css);
int nFontFaceSrcs = checkFontFace(stylesheet);
assertEquals(6, nFontFaceSrcs);
}
*** 243,266 ****
List<FontFace> fontFaces = stylesheet.getFontFaces();
assertNotNull(fontFaces);
assertEquals(1, fontFaces.size());
! FontFace fontFace = fontFaces.get(0);
Map<String,String> descriptors = fontFace.getDescriptors();
assertEquals("'Bree Serif'", descriptors.get("font-family"));
assertEquals("normal", descriptors.get("font-style"));
assertEquals("400", descriptors.get("font-weight"));
! List<FontFace.FontFaceSrc> fontFaceSrcs = fontFace.getSources();
int nFontFaceSrcs = fontFaceSrcs != null ? fontFaceSrcs.size() : 0;
for(int n=0; n<nFontFaceSrcs; n++) {
! FontFace.FontFaceSrc fontFaceSrc = fontFaceSrcs.get(n);
! FontFace.FontFaceSrcType type = fontFaceSrc.getType();
switch(type) {
case LOCAL: {
String src = fontFaceSrc.getSrc();
assertTrue("Bree Serif".equals(src) || "BreeSerif-Regular".equals(src));
assertNull(fontFaceSrc.getFormat());
--- 243,266 ----
List<FontFace> fontFaces = stylesheet.getFontFaces();
assertNotNull(fontFaces);
assertEquals(1, fontFaces.size());
! FontFaceImpl fontFace = (FontFaceImpl)fontFaces.get(0);
Map<String,String> descriptors = fontFace.getDescriptors();
assertEquals("'Bree Serif'", descriptors.get("font-family"));
assertEquals("normal", descriptors.get("font-style"));
assertEquals("400", descriptors.get("font-weight"));
! List<FontFaceImpl.FontFaceSrc> fontFaceSrcs = fontFace.getSources();
int nFontFaceSrcs = fontFaceSrcs != null ? fontFaceSrcs.size() : 0;
for(int n=0; n<nFontFaceSrcs; n++) {
! FontFaceImpl.FontFaceSrc fontFaceSrc = fontFaceSrcs.get(n);
! FontFaceImpl.FontFaceSrcType type = fontFaceSrc.getType();
switch(type) {
case LOCAL: {
String src = fontFaceSrc.getSrc();
assertTrue("Bree Serif".equals(src) || "BreeSerif-Regular".equals(src));
assertNull(fontFaceSrc.getFormat());
*** 281,309 ****
return nFontFaceSrcs;
}
@Test public void testRT_32522() {
! ParsedValue value = CSSParser.getInstance().parseExpr("foo", "1 2em 3 4;");
Object obj = value.convert(Font.font(13));
assert obj instanceof Number[];
assertArrayEquals(new Number[] {1d, 26d, 3d, 4d}, (Number[])obj);
! value = CSSParser.getInstance().parseExpr("foo", "1;");
obj = value.convert(null);
assert obj instanceof Number;
assertEquals(1d, (Number)obj);
}
@Test public void testRT_38483() {
Duration expected = Duration.millis(42);
! ParsedValue value = CSSParser.getInstance().parseExpr("foo", "42ms;");
Object observed = value.convert(null);
assertEquals(expected, observed);
! value = CSSParser.getInstance().parseExpr("foo", "indefinite;");
observed = value.convert(null);
assertEquals(Duration.INDEFINITE, observed);
}
}
--- 281,309 ----
return nFontFaceSrcs;
}
@Test public void testRT_32522() {
! ParsedValue value = new CssParser().parseExpr("foo", "1 2em 3 4;");
Object obj = value.convert(Font.font(13));
assert obj instanceof Number[];
assertArrayEquals(new Number[] {1d, 26d, 3d, 4d}, (Number[])obj);
! value = new CssParser().parseExpr("foo", "1;");
obj = value.convert(null);
assert obj instanceof Number;
assertEquals(1d, (Number)obj);
}
@Test public void testRT_38483() {
Duration expected = Duration.millis(42);
! ParsedValue value = new CssParser().parseExpr("foo", "42ms;");
Object observed = value.convert(null);
assertEquals(expected, observed);
! value = new CssParser().parseExpr("foo", "indefinite;");
observed = value.convert(null);
assertEquals(Duration.INDEFINITE, observed);
}
}