Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 263081 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/tests/css/core/parser/StyleRuleTest.java (+58 lines)
Lines 77-80 Link Here
77
		String colorString = ((CSSPrimitiveValue) value).getStringValue();
77
		String colorString = ((CSSPrimitiveValue) value).getStringValue();
78
		assertEquals("Verdana", colorString);
78
		assertEquals("Verdana", colorString);
79
	}
79
	}
80
	
81
	public void testTestFontItalic() throws Exception {
82
		String css = "Label { font: Arial 12px; font-style: italic }";
83
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
84
		CSSRuleList rules = styleSheet.getCssRules();
85
		CSSRule rule = rules.item(0);
86
		assertEquals(CSSRule.STYLE_RULE, rule.getType());
87
		CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle();
88
		CSSValue value = style.getPropertyCSSValue("font-style");
89
		assertTrue(value instanceof CSSPrimitiveValue);
90
		String colorString = ((CSSPrimitiveValue) value).getStringValue();
91
		assertEquals("italic", colorString);
92
	}
93
	
94
	public void testTestFontBold() throws Exception{
95
		String css = "Label { font: Arial 12px; font-style: bold }";
96
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
97
		CSSRuleList rules = styleSheet.getCssRules();
98
		CSSRule rule = rules.item(0);
99
		assertEquals(CSSRule.STYLE_RULE, rule.getType());
100
		CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle();
101
		CSSValue value = style.getPropertyCSSValue("font-style");
102
		assertTrue(value instanceof CSSPrimitiveValue);
103
		String colorString = ((CSSPrimitiveValue) value).getStringValue();
104
		assertEquals("bold", colorString);
105
	}
106
	
107
	
108
	public void testBackgroundNameColor() throws Exception{
109
		String css = "Label { background-color: green }";
110
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
111
		CSSRuleList rules = styleSheet.getCssRules();
112
		CSSRule rule = rules.item(0);
113
		assertEquals(CSSRule.STYLE_RULE, rule.getType());
114
		CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle();
115
		CSSValue value = style.getPropertyCSSValue("background-color");
116
		assertTrue(value instanceof CSSPrimitiveValue);
117
		String colorString = ((CSSPrimitiveValue) value).getStringValue();
118
		assertEquals("green", colorString);
119
	}
120
	
121
	public void testBackgroundHexColor() throws Exception {
122
		String css = "Label { background-color: #FF0220 }";
123
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
124
		CSSRuleList rules = styleSheet.getCssRules();
125
		CSSRule rule = rules.item(0);
126
		assertEquals(CSSRule.STYLE_RULE, rule.getType());
127
		CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle();
128
		CSSValue value = style.getPropertyCSSValue("background-color");
129
		assertTrue(value instanceof CSSPrimitiveValue);
130
		RGBColor colorValue = ((CSSPrimitiveValue) value).getRGBColorValue();
131
		assertEquals(255.0f, colorValue.getRed().getFloatValue(
132
				CSSPrimitiveValue.CSS_NUMBER), 0f);
133
		assertEquals(2.0f, colorValue.getGreen().getFloatValue(
134
				CSSPrimitiveValue.CSS_NUMBER), 0f);
135
		assertEquals(32.0f, colorValue.getBlue().getFloatValue(
136
				CSSPrimitiveValue.CSS_NUMBER), 0f);
137
	}
80
}
138
}
(-)src/org/eclipse/e4/ui/tests/css/core/parser/CascadeTest.java (-2 / +29 lines)
Lines 44-51 Link Here
44
		TestElement button = new TestElement("Button", engine);
44
		TestElement button = new TestElement("Button", engine);
45
		CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null);
45
		CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null);
46
		assertEquals("black", style.getPropertyCSSValue("color").getCssText());
46
		assertEquals("black", style.getPropertyCSSValue("color").getCssText());
47
		assertEquals("bold", style.getPropertyCSSValue("font-weight")
47
		assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText());
48
				.getCssText());
49
	}
48
	}
50
49
51
	public void testSpecificity() throws Exception {
50
	public void testSpecificity() throws Exception {
Lines 95-100 Link Here
95
		style = viewCSS.getComputedStyle(button, null);
94
		style = viewCSS.getComputedStyle(button, null);
96
		assertEquals("red", style.getPropertyCSSValue("color").getCssText());
95
		assertEquals("red", style.getPropertyCSSValue("color").getCssText());
97
	}
96
	}
97
	
98
	public void testImportantRule() throws Exception {
99
		//Several rules for the same class, if one rule has ! important 
100
		//it takes precedence over all other, if more than one 
101
		//last one gets precedence
102
	
103
		String css = "Button{color:red ! important;}\n" 
104
			+"Button{ color: blue ! important;}\n"
105
			+ "Button { color: black }\n";
106
		ViewCSS viewCSS = createViewCss(css);
107
108
		TestElement button = new TestElement("Button", engine);
109
		CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null);
110
		assertEquals("blue", style.getPropertyCSSValue("color").getCssText());
111
	}
112
	
113
	public void testBug261081() throws Exception{
114
		// Two rules with the same specificity, the second rule should take
115
		// precedence because of its position in the stylesheet
116
		String css = "Button, Label { color: blue; font-weight: bold; }\n"
117
			+ "Button { color: black }\n";
118
		ViewCSS viewCSS = createViewCss(css);
119
120
		TestElement button = new TestElement("Button", engine);
121
		CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null);
122
		assertEquals("black", style.getPropertyCSSValue("color").getCssText());
123
		assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText());
124
	}
98
125
99
	private static ViewCSS createViewCss(String css) throws IOException {
126
	private static ViewCSS createViewCss(String css) throws IOException {
100
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);
127
		CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css);

Return to bug 263081