@Test public void idTagClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".idtag"); assertThat(rule).hasPropertyWithValue("background-image", "url(images/Token-IDTag_Light.png)") .hasPropertyWithValue("background-size", "30px 30px") .hasPropertyWithValue("background-repeat", "no-repeat") .hasPropertyWithValue("height", "30px") .hasPropertyWithValue("width", "30px") .hasPropertyWithValue("display", "inline-block") .hasPropertyWithValue("text-align", "center") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("color", "black") .hasPropertyWithValue("padding-top", "5px") .hasPropertyWithValue("vertical-align", "middle") .hasPropertyWithValue("font-size", "0.95em"); }
/** * Adds the class rule. * * @param elemtl * the elemtl * @param classtl * the classtl * @param styleRule * the style rule * @param ancestorSelectors * the ancestor selectors */ private final void addClassRule(String elemtl, String classtl, CSSStyleRule styleRule, ArrayList<SelectorMatcher> ancestorSelectors) { if (elemtl == null || "".equals(elemtl)) { elemtl = "*"; } Map<String, Collection<StyleRuleInfo>> classMap = this.classMapsByElement.get(elemtl); if (classMap == null) { classMap = new HashMap<String, Collection<StyleRuleInfo>>(); this.classMapsByElement.put(elemtl, classMap); } Collection<StyleRuleInfo> rules = classMap.get(classtl); if (rules == null) { rules = new LinkedList<StyleRuleInfo>(); classMap.put(classtl, rules); } rules.add(new StyleRuleInfo(ancestorSelectors, styleRule)); }
/** * Adds the attribute rule. * * @param elemtl * the elemtl * @param classtl * the classtl * @param styleRule * the style rule * @param ancestorSelectors * the ancestor selectors */ private final void addAttributeRule(String elemtl, String attrtl, CSSStyleRule styleRule, ArrayList<SelectorMatcher> ancestorSelectors) { if (elemtl == null || "".equals(elemtl)) { elemtl = "*"; } Map<String, Collection<StyleRuleInfo>> attrMap = this.attrMapsByElement.get(elemtl); if (attrMap == null) { attrMap = new HashMap<String, Collection<StyleRuleInfo>>(); this.attrMapsByElement.put(elemtl, attrMap); } Collection<StyleRuleInfo> rules = attrMap.get(attrtl); if (rules == null) { rules = new LinkedList<StyleRuleInfo>(); attrMap.put(attrtl, rules); } rules.add(new StyleRuleInfo(ancestorSelectors, styleRule)); }
/** * Adds the id rule. * * @param elemtl * the elemtl * @param idtl * the idtl * @param styleRule * the style rule * @param ancestorSelectors * the ancestor selectors */ private final void addIdRule(String elemtl, String idtl, CSSStyleRule styleRule, ArrayList<SelectorMatcher> ancestorSelectors) { if (elemtl == null || "".equals(elemtl)) { elemtl = "*"; } Map<String, Collection<StyleRuleInfo>> idsMap = this.idMapsByElement.get(elemtl); if (idsMap == null) { idsMap = new HashMap<String, Collection<StyleRuleInfo>>(); this.idMapsByElement.put(elemtl, idsMap); } Collection<StyleRuleInfo> rules = idsMap.get(idtl); if (rules == null) { rules = new LinkedList<StyleRuleInfo>(); idsMap.put(idtl, rules); } rules.add(new StyleRuleInfo(ancestorSelectors, styleRule)); }
/** * put style declarations * * @param elementRules * @param styleDeclarations * @param element * @param pseudoNames * @return */ private Collection<CSSStyleDeclaration> putStyleDeclarations(Collection<StyleRuleInfo> elementRules, Collection<CSSStyleDeclaration> styleDeclarations, HTMLElementImpl element, Set pseudoNames) { Iterator<StyleRuleInfo> i = elementRules.iterator(); while (i.hasNext()) { StyleRuleInfo styleRuleInfo = i.next(); if (styleRuleInfo.isSelectorMatch(element, pseudoNames)) { CSSStyleRule styleRule = styleRuleInfo.getStyleRule(); CSSStyleSheet styleSheet = styleRule.getParentStyleSheet(); if (styleSheet != null && styleSheet.getDisabled()) { continue; } if (styleDeclarations == null) { styleDeclarations = new LinkedList<CSSStyleDeclaration>(); } styleDeclarations.add(styleRule.getStyle()); } } return styleDeclarations; }
private ElementRuleList extractDOMModifications(List<CSSStyleRule> ruleList) { ElementRuleList modifierRules = new ElementRuleList(); Iterator<CSSStyleRule> it = ruleList.iterator(); while(it.hasNext()) { CSSStyleRule rule = it.next(); PseudoClass pseudoModifier = getDOMModifier(rule.getSelectorText()); if(pseudoModifier!=null) { ElementRule modifierRule = ElementRuleFactory.createElementRule(pseudoModifier, CSSUtil.asMap(rule.getStyle())); modifierRules.add(modifierRule); it.remove(); } } return modifierRules; }
@Test public void pilotClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".pilot"); assertThat(rule).hasPropertyWithValue("font-size", "1.1em") .hasPropertyWithValue("margin-top", "5px") .hasPropertyWithValue("font-weight", "bold"); }
@Test public void shieldsSymbolClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".shields-symbol"); assertThat(rule).hasPropertyWithValue("font-family", "\"x-wing-symbols\"") .hasPropertyWithValue("font-size", "1.75em") .hasPropertyWithValue("color", "cyan") .hasPropertyWithValue("font-weight", "normal") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("-webkit-font-smoothing", "always"); }
@Test public void hullSymbolClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".hull-symbol"); assertThat(rule).hasPropertyWithValue("font-family", "\"x-wing-symbols\"") .hasPropertyWithValue("font-size", "1.7em") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("color", "yellow") .hasPropertyWithValue("font-weight", "normal") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("-webkit-font-smoothing", "always"); }
@Test public void agilitySymbolClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".agility-symbol"); assertThat(rule).hasPropertyWithValue("font-family", "\"x-wing-symbols\"") .hasPropertyWithValue("font-size", "1.75em") .hasPropertyWithValue("color", "rgb(86, 244, 66)") .hasPropertyWithValue("font-weight", "normal") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("-webkit-font-smoothing", "always"); }
@Test public void attackSymbolClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".attack-symbol"); assertThat(rule).hasPropertyWithValue("font-family", "\"x-wing-symbols\"") .hasPropertyWithValue("font-size", "1.75em") .hasPropertyWithValue("color", "rgb(242, 14, 56)") .hasPropertyWithValue("font-weight", "normal") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("-webkit-font-smoothing", "always"); }
@Test public void upgradeTypeSymbolClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".upgrade-type-symbol"); assertThat(rule).hasPropertyWithValue("font-family", "\"x-wing-symbols\"") .hasPropertyWithValue("font-size", "16pt") .hasPropertyWithValue("color", "rgb(255, 255, 255)") .hasPropertyWithValue("font-weight", "normal") .hasPropertyWithValue("font-style", "normal") .hasPropertyWithValue("text-shadow", "0px 0px rgb(0, 0, 0)") .hasPropertyWithValue("-webkit-font-smoothing", "always"); }
@Test public void squadClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".squad"); assertThat(rule).hasPropertyWithValue("padding", "10px") .hasPropertyWithValue("height", "100%") .hasPropertyWithValue("background-image", "linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5))"); }
@Test public void pilotClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".pilot"); assertThat(rule).hasPropertyWithValue("font-size", "1.1em") .hasPropertyWithValue("margin-top", "5px") .hasPropertyWithValue("font-weight", "bold"); }
@Test public void upgradesClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".upgrades"); assertThat(rule).hasPropertyWithValue("font-size", "0.9em") .hasPropertyWithValue("margin-bottom", "5px") .hasPropertyWithValue("font-weight", "bold"); }
protected CSSStyleRule findRule(CSSRuleList rules, String ruleName) throws Exception { for (int i = 0; i < rules.getLength(); i++) { CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.item(i); SelectorList selectorList = rule.getSelectors(); for (int s = 0; s < selectorList.getLength(); s++ ) { Selector selector = selectorList.item(s); if (selector.toString().equals(ruleName)) { return rule; } } } return null; }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof CSSStyleRule)) { return false; } final CSSStyleRule csr = (CSSStyleRule) obj; return super.equals(obj) && LangUtils.equals(getSelectorText(), csr.getSelectorText()) && LangUtils.equals(getStyle(), csr.getStyle()); }
/** * Adds the element rule. * * @param elemtl * the elemtl * @param styleRule * the style rule * @param ancestorSelectors * the ancestor selectors */ private final void addElementRule(String elemtl, CSSStyleRule styleRule, ArrayList<SelectorMatcher> ancestorSelectors) { if (elemtl == null || "".equals(elemtl)) { elemtl = "*"; } Collection<StyleRuleInfo> rules = this.rulesByElement.get(elemtl); if (rules == null) { rules = new LinkedList<StyleRuleInfo>(); this.rulesByElement.put(elemtl, rules); } rules.add(new StyleRuleInfo(ancestorSelectors, styleRule)); }
public HashMap<String, CSSStyleRule> extractCssStyleRules(String cssFile) throws IOException { TEST_FILE_SYSTEM.filesExists(cssFile); CSSOMParser cssParser = new CSSOMParser(); CSSStyleSheet css = cssParser.parseStyleSheet(new InputSource(new FileReader(TEST_FILE_SYSTEM.file(cssFile))), null, null); CSSRuleList cssRules = css.getCssRules(); HashMap<String, CSSStyleRule> rules = new HashMap<String, CSSStyleRule>(); for (int i = 0; i < cssRules.getLength(); i++) { CSSRule rule = cssRules.item(i); if (rule instanceof CSSStyleRule) { rules.put(((CSSStyleRule) rule).getSelectorText(), (CSSStyleRule) rule); } } return rules; }
@Override public String toString(){ String css= ""; for (Map.Entry<String, CSSStyleRule> ruleEntry : rules.entrySet()) { css += ruleEntry.toString() +"\n"; } return css; }
public AttributeRuleList(CSSRuleList ruleList) { super(ruleList.getLength()); for (int i = 0; i < ruleList.getLength(); i++) { CSSRule rule = ruleList.item(i); if(rule instanceof CSSStyleRule) { this.add((CSSStyleRule)rule); } } }
private List<SingleRule> getSingleRules(AttributeRuleList ruleList) { ArrayList<SingleRule> result = new ArrayList<SingleRule>(); for (CSSStyleRule styleRule : ruleList) { String selectorText = styleRule.getSelectorText(); CSSStyleDeclaration styles = styleRule.getStyle(); for (int j = 0; j < styles.getLength(); j++) { String property = styles.item(j); result.add(new SingleRule(selectorText, property, styles.getPropertyCSSValue(property).getCssText())); } } return result; }
protected CSSStyleRuleAssert(CSSStyleRule actual) { super(actual, CSSStyleRuleAssert.class); }
public static CSSStyleRuleAssert assertThat(CSSStyleRule actual) { return new CSSStyleRuleAssert(actual); }
@Test public void hullClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".hull"); assertThat(rule).hasPropertyWithValue("font-size", "0.95em") .hasPropertyWithValue("color", "yellow"); }
@Test public void redClassHasExpectedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".red"); assertThat(rule).hasPropertyWithValue("color", "red"); }
@Test public void shieldsClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".shields"); assertThat(rule).hasPropertyWithValue("font-size", "0.95em") .hasPropertyWithValue("color", "cyan"); }
@Test public void hullClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".hull"); assertThat(rule).hasPropertyWithValue("font-size", "0.95em") .hasPropertyWithValue("color", "yellow"); }
@Test public void agilityClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".agility"); assertThat(rule).hasPropertyWithValue("font-size", "0.95em") .hasPropertyWithValue("color", "rgb(86, 244, 66)"); }
@Test public void attackClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".attack"); assertThat(rule).hasPropertyWithValue("font-size", "0.95em") .hasPropertyWithValue("color", "rgb(242, 14, 56)"); }
@Test public void upgradeDiscardedClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".upgradeDiscarded"); assertThat(rule).hasPropertyWithValue("color", "red"); }
@Test public void upgradeDiscardedBeforeClassHasExpecedValues() throws Exception { CSSStyleRule rule = findRule(styleSheet.getCssRules(), ".upgradeDiscarded:before"); assertThat(rule).hasPropertyWithValue("content", "\"\u2718\""); }
public CSSStyleRule get(String ruleName) { return rules.get(ruleName); }
public AttributeRuleList(Collection<? extends CSSStyleRule> c) { super(c); }
public void applyTo(Document document) throws NodeSelectorException { for (CSSStyleRule styleRule : this) { handleRule(document, styleRule.getSelectorText(), CSSUtil.asMap(styleRule.getStyle())); } }
/** * Instantiates a new style rule info. * * @param SelectorMatchers * A collection of SelectorMatcher's. * @param rule * A CSS rule. */ public StyleRuleInfo(ArrayList<SelectorMatcher> SelectorMatchers, CSSStyleRule rule) { super(); ancestorSelectors = SelectorMatchers; setStyleRule(rule); }
/** * Gets the style rule. * * @return the style rule */ public CSSStyleRule getStyleRule() { return styleRule; }
/** * Sets the style rule. * * @param styleRule * the new style rule */ public void setStyleRule(CSSStyleRule styleRule) { this.styleRule = styleRule; }