use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSStyleSheetTest method testInsertRule.
public void testInsertRule() {
CSSStyleSheet sheet = getStyleSheet();
assertEquals(0, sheet.insertRule(RULE_H3, 0));
assertEquals(0, sheet.insertRule(RULE_H1, 0));
assertEquals(1, sheet.insertRule(RULE_H2, 1));
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule;
rule = ruleList.item(0);
assertEquals(RULE_H1, rule.getCssText());
rule = ruleList.item(1);
assertEquals(RULE_H2, rule.getCssText());
rule = ruleList.item(2);
assertEquals(RULE_H3, rule.getCssText());
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSStyleSheetTest method testDeleteRule.
public void testDeleteRule() {
CSSStyleSheet sheet = getStyleSheet();
assertEquals(0, sheet.insertRule(RULE_H3, 0));
assertEquals(0, sheet.insertRule(RULE_H1, 0));
assertEquals(1, sheet.insertRule(RULE_H2, 1));
CSSRuleList ruleList;
CSSRule rule;
sheet.deleteRule(1);
ruleList = sheet.getCssRules();
rule = ruleList.item(0);
assertEquals(RULE_H1, rule.getCssText());
rule = ruleList.item(1);
assertEquals(RULE_H3, rule.getCssText());
sheet.deleteRule(1);
ruleList = sheet.getCssRules();
rule = ruleList.item(0);
assertEquals(RULE_H1, rule.getCssText());
sheet.deleteRule(0);
try {
sheet.deleteRule(0);
} catch (DOMException e) {
assertEquals(DOMException.INDEX_SIZE_ERR, e.code);
}
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class StyleSheetTest method testImportFromParentDirectory.
/**
* Tests for the import of a stylesheet in a parent directory
* @throws Exception
*/
public void testImportFromParentDirectory() throws Exception {
String filePath = "/" + PROJECT_NAME + "/WebContent/style/sub.css";
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
assertTrue("File doesn't exist: " + filePath, file.exists());
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(file);
if (model instanceof ICSSModel) {
ICSSDocument document = ((ICSSModel) model).getDocument();
if (document instanceof ICSSStyleSheet) {
CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
assertTrue("There should be a total of 1 rule.", list.getLength() == 1);
CSSRule rule = list.item(0);
assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
assertEquals("Stylesheet reference is different than expected.", ((CSSStyleRule) rule).getSelectorText(), "#content");
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class StyleSheetTest method testImportCycle.
/**
* Tests for cycles in imports. If a cycle is encountered, we should not get stuck
* in a loop or re-import the stylesheet.
* @throws Exception
*/
public void testImportCycle() throws Exception {
String filePath = "/" + PROJECT_NAME + "/WebContent/cycle0.css";
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
assertTrue("File doesn't exist: " + filePath, file.exists());
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(file);
if (model instanceof ICSSModel) {
ICSSDocument document = ((ICSSModel) model).getDocument();
if (document instanceof ICSSStyleSheet) {
CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == 3);
for (int i = 0; i < list.getLength(); i++) {
CSSRule rule = list.item(i);
assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
// Check that the rules are imported, it would start with the last imported stylesheet's rules and move up
assertEquals("Style rules are not equal.", ((CSSStyleRule) rule).getSelectorText(), "#cycle" + (2 - i));
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.w3c.dom.css.CSSRuleList in project webtools.sourceediting by eclipse.
the class CSSFontFaceRuleTest method _testInsertText1.
public void _testInsertText1() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(3, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
CSSValueList valueList;
// rule 1
rule = ruleList.item(0);
assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
assertTrue(rule instanceof CSSFontFaceRule);
declaration = ((CSSFontFaceRule) rule).getStyle();
assertEquals(4, declaration.getLength());
value = declaration.getPropertyCSSValue("font-family");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Swiss 721"));
value = declaration.getPropertyCSSValue("src");
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "swiss721blk.pfr"));
value = declaration.getPropertyCSSValue("font-style");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(3, valueList.getLength());
checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
value = declaration.getPropertyCSSValue("font-weight");
assertTrue(value instanceof CSSValueList);
valueList = (CSSValueList) value;
assertEquals(3, valueList.getLength());
checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 800));
checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 900));
}
Aggregations