|
31 | 31 |
|
32 | 32 | import org.htmlunit.cssparser.ErrorHandler; |
33 | 33 | import org.htmlunit.cssparser.dom.AbstractCSSRuleImpl; |
| 34 | +import org.htmlunit.cssparser.dom.CSSFontFaceRuleImpl; |
34 | 35 | import org.htmlunit.cssparser.dom.CSSMediaRuleImpl; |
| 36 | +import org.htmlunit.cssparser.dom.CSSPageRuleImpl; |
35 | 37 | import org.htmlunit.cssparser.dom.CSSRuleListImpl; |
36 | 38 | import org.htmlunit.cssparser.dom.CSSStyleDeclarationImpl; |
37 | 39 | import org.htmlunit.cssparser.dom.CSSStyleRuleImpl; |
@@ -739,6 +741,29 @@ public void atRuleFontFaceComplex2() throws Exception { |
739 | 741 | rule.getCssText()); |
740 | 742 | } |
741 | 743 |
|
| 744 | + /** |
| 745 | + * @throws Exception if the test fails |
| 746 | + */ |
| 747 | + @Test |
| 748 | + public void invalidFontFaceRule_isSkipped_andFollowingRulesStillParsed() throws Exception { |
| 749 | + final String css = |
| 750 | + "@font-face { font-family: Gentium; ) }\n" |
| 751 | + + "p { color: blue; }\n"; |
| 752 | + |
| 753 | + // If fontFaceRule() currently aborts parsing, this test will FAIL today. |
| 754 | + // That’s OK: it captures the desired behavior. |
| 755 | + final CSSStyleSheetImpl sheet = parse(css, 1, 0, 1); |
| 756 | + |
| 757 | + final CSSRuleListImpl rules = sheet.getCssRules(); |
| 758 | + assertEquals(2, rules.getLength()); |
| 759 | + |
| 760 | + assertTrue(rules.getRules().get(0) instanceof CSSFontFaceRuleImpl); |
| 761 | + assertEquals("@font-face { font-family: Gentium; }", rules.getRules().get(0).getCssText()); |
| 762 | + |
| 763 | + assertTrue(rules.getRules().get(1) instanceof CSSStyleRuleImpl); |
| 764 | + assertEquals("p { color: blue; }", rules.getRules().get(1).getCssText()); |
| 765 | + } |
| 766 | + |
742 | 767 | /** |
743 | 768 | * @see <a href="http://www.w3.org/TR/CSS21/syndata.html#at-rules"> |
744 | 769 | * http://www.w3.org/TR/CSS21/syndata.html#at-rules</a> |
@@ -4004,6 +4029,27 @@ private void pageSelectors(final String css, final String expected, |
4004 | 4029 | } |
4005 | 4030 | } |
4006 | 4031 |
|
| 4032 | + /** |
| 4033 | + * @throws Exception if the test fails |
| 4034 | + */ |
| 4035 | + @Test |
| 4036 | + public void invalidPageRule_isSkipped_andFollowingRulesStillParsed() throws Exception { |
| 4037 | + final String css = |
| 4038 | + "@page :left { margin: 3cm; ) }\n" // missing closing '}' |
| 4039 | + + "p { color: blue; }"; |
| 4040 | + |
| 4041 | + final CSSStyleSheetImpl sheet = parse(css, 1, 0, 1); |
| 4042 | + |
| 4043 | + final CSSRuleListImpl rules = sheet.getCssRules(); |
| 4044 | + assertEquals(2, rules.getLength()); |
| 4045 | + |
| 4046 | + assertTrue(rules.getRules().get(0) instanceof CSSPageRuleImpl); |
| 4047 | + assertEquals("@page :left { margin: 3cm; }", rules.getRules().get(0).getCssText()); |
| 4048 | + |
| 4049 | + assertTrue(rules.getRules().get(1) instanceof CSSStyleRuleImpl); |
| 4050 | + assertEquals("p { color: blue; }", rules.getRules().get(1).getCssText()); |
| 4051 | + } |
| 4052 | + |
4007 | 4053 | /** |
4008 | 4054 | * Test keyframes at rule. |
4009 | 4055 | * |
|
0 commit comments