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/swt/CSSTestCase.java (-1 / +6 lines)
Lines 1-6 Link Here
1
package org.eclipse.e4.ui.tests.css.swt;
1
package org.eclipse.e4.ui.tests.css.swt;
2
2
3
import java.io.IOException;
3
import java.io.IOException;
4
import java.io.Reader;
4
import java.io.StringReader;
5
import java.io.StringReader;
5
6
6
import junit.framework.TestCase;
7
import junit.framework.TestCase;
Lines 13-18 Link Here
13
public class CSSTestCase extends TestCase {
14
public class CSSTestCase extends TestCase {
14
	
15
	
15
	public CSSEngine createEngine(String styleSheet, Display display) {
16
	public CSSEngine createEngine(String styleSheet, Display display) {
17
		return createEngine(new StringReader(styleSheet), display);
18
	}
19
20
	public CSSEngine createEngine(Reader reader, Display display) {
16
		CSSEngine engine = new CSSSWTEngineImpl(display);
21
		CSSEngine engine = new CSSSWTEngineImpl(display);
17
		
22
		
18
		engine.setErrorHandler(new CSSErrorHandler() {
23
		engine.setErrorHandler(new CSSErrorHandler() {
Lines 22-28 Link Here
22
		});
27
		});
23
		
28
		
24
		try {
29
		try {
25
			engine.parseStyleSheet(new StringReader(styleSheet));
30
			engine.parseStyleSheet(reader);
26
		} catch (IOException e) {
31
		} catch (IOException e) {
27
			fail(e.getMessage());
32
			fail(e.getMessage());
28
		}
33
		}
(-)src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java (+2 lines)
Lines 18-22 Link Here
18
		addTestSuite(LabelTest.class);
18
		addTestSuite(LabelTest.class);
19
		addTestSuite(CTabFolderTest.class);
19
		addTestSuite(CTabFolderTest.class);
20
		addTestSuite(IdClassLabelColorTest.class);
20
		addTestSuite(IdClassLabelColorTest.class);
21
		addTestSuite(Test.class);
22
		addTestSuite(CssSelectorPrecedence.class);
21
	}
23
	}
22
}
24
}
(-)src/org/eclipse/e4/ui/tests/css/swt/CssSelectorPrecedence.java (+79 lines)
Added Link Here
1
package org.eclipse.e4.ui.tests.css.swt;
2
3
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
4
import org.eclipse.e4.ui.css.swt.CSSSWTConstants;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.graphics.RGB;
7
import org.eclipse.swt.layout.FillLayout;
8
import org.eclipse.swt.widgets.Composite;
9
import org.eclipse.swt.widgets.Display;
10
import org.eclipse.swt.widgets.Label;
11
import org.eclipse.swt.widgets.Shell;
12
13
14
public class CssSelectorPrecedence extends CSSTestCase{
15
	
16
	static final RGB RED = new RGB(255, 0, 0);
17
	static final RGB BLUE = new RGB(0, 0, 255);
18
	public Label labelToTest;
19
	
20
	protected Label labelToTest(String styleSheet) {
21
		Display display = Display.getDefault();
22
		CSSEngine engine = createEngine(styleSheet, display);
23
		
24
		// Create widgets
25
		Shell shell = new Shell(display, SWT.SHELL_TRIM);
26
		FillLayout layout = new FillLayout();
27
		shell.setLayout(layout);
28
29
		Composite panel = new Composite(shell, SWT.NONE);
30
		panel.setLayout(new FillLayout());
31
32
		Label label = new Label(panel, SWT.NONE);
33
		label.setText("Some label text");
34
		label.setData(CSSSWTConstants.CSS_ID_KEY, "labelTest");
35
		label.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "labelTest");
36
		
37
			
38
			// Apply styles
39
		engine.applyStyles(shell,true);
40
41
		shell.pack();
42
		shell.open();
43
		engine.applyStyles(labelToTest, true);
44
		return label;
45
	}
46
	
47
48
	public void testRedundancy(){
49
		labelToTest = labelToTest("Label { background-color: #FF0000;} " +
50
								"Label {background-color: #0000FF;} ");
51
		assertEquals(BLUE, labelToTest.getBackground().getRGB());
52
	}
53
	
54
		public void testBug261018(){
55
		labelToTest = labelToTest("Button, Label {background-color: #FF0000;}" +
56
								"Shell, Label {background-color: #0000FF;}");
57
		assertEquals(BLUE, labelToTest.getBackground().getRGB());
58
	}
59
	
60
	public void testWithClassNameAndID() {
61
		labelToTest = labelToTest("Label { background-color: #FF0000; color: #0000FF} " +
62
								"#labelTest {background-color: #0000FF;} ");
63
		assertEquals(BLUE, labelToTest.getBackground().getRGB());
64
	}
65
	
66
	public void testWithClassNameAndPseudoClass() {
67
		labelToTest = labelToTest("Label { background-color: #FF0000; color: #0000FF} " +
68
								".labelTest {background-color: #0000FF;} ");
69
		assertEquals(BLUE, labelToTest.getBackground().getRGB());
70
	}
71
	
72
	public void testImportant(){
73
		labelToTest = labelToTest("Label {background-color: rgb(255,0,0);}" +
74
								"Label { background-color: rgb(0,0,255) ! important;}" +
75
								"Label {background-color: rgb(255,0,0);}");
76
		assertEquals(BLUE, labelToTest.getBackground().getRGB());
77
	}
78
	
79
}

Return to bug 263081