use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSCharsetRuleTest method testInsertRule.
public void testInsertRule() {
CSSStyleSheet sheet = getStyleSheet();
assertEquals(0, sheet.insertRule(RULE, 0));
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule = ruleList.item(0);
assertTrue(rule instanceof CSSCharsetRule);
CSSCharsetRule charsetRule = (CSSCharsetRule) rule;
assertEquals("iso-8859-1", charsetRule.getEncoding());
assertEquals(RULE, charsetRule.getCssText());
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSFontFamilyTest method testFontFamilies.
public void testFontFamilies() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList rules = sheet.getCssRules();
assertEquals(4, rules.getLength());
// Rule 1: No whitespace
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
// Rule 1: No whitespace
rule = rules.item(0);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
// Rule 2: Single whitespace
rule = rules.item(1);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier New"));
// Rule 3: In quotes
rule = rules.item(2);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Courier New"));
// Rule 4: Tabs and spaces all over
rule = rules.item(3);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Comic Sans"));
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSMediaRuleTest method testCreateRule.
public void testCreateRule() {
ICSSStyleSheet sheet = getStyleSheet();
ICSSDocument doc = sheet;
ICSSMediaRule newRule = doc.createCSSMediaRule();
MediaList newList = newRule.getMedia();
newList.appendMedium("media1");
newList.appendMedium("media2");
sheet.insertRuleBefore(newRule, null);
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule = ruleList.item(0);
assertTrue(rule instanceof CSSMediaRule);
CSSMediaRule mediaRule = (CSSMediaRule) rule;
MediaList mediaList = mediaRule.getMedia();
assertEquals(2, mediaList.getLength());
assertEquals("media1", mediaList.item(0));
assertEquals("media2", mediaList.item(1));
assertEquals("@media media1, media2 {" + FileUtil.commonEOL + "}", mediaRule.getCssText());
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSPageRuleTest method testInsertText4.
public void testInsertText4() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(6, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
// rule 4
rule = ruleList.item(3);
assertEquals(CSSRule.PAGE_RULE, rule.getType());
assertTrue(rule instanceof CSSPageRule);
assertEquals(":right", ((CSSPageRule) rule).getSelectorText());
declaration = ((CSSPageRule) rule).getStyle();
assertEquals(2, declaration.getLength());
value = declaration.getPropertyCSSValue("margin-left");
checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 3));
value = declaration.getPropertyCSSValue("margin-right");
checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 4));
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSPageRuleTest method testInsertText5.
public void testInsertText5() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(6, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
CSSValueList valueList;
// rule 5
rule = ruleList.item(4);
assertEquals(CSSRule.PAGE_RULE, rule.getType());
assertTrue(rule instanceof CSSPageRule);
assertEquals("narrow", ((CSSPageRule) rule).getSelectorText());
declaration = ((CSSPageRule) rule).getStyle();
assertEquals(1, declaration.getLength());
value = declaration.getPropertyCSSValue("size");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(2, valueList.getLength());
checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 9));
checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 18));
}
Aggregations