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/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);
(-)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/swt/CTabFolderTest.java (-1 / +123 lines)
Lines 4-9 Link Here
4
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.SWT;
5
import org.eclipse.swt.custom.CTabFolder;
5
import org.eclipse.swt.custom.CTabFolder;
6
import org.eclipse.swt.custom.CTabItem;
6
import org.eclipse.swt.custom.CTabItem;
7
import org.eclipse.swt.graphics.FontData;
7
import org.eclipse.swt.graphics.RGB;
8
import org.eclipse.swt.graphics.RGB;
8
import org.eclipse.swt.layout.FillLayout;
9
import org.eclipse.swt.layout.FillLayout;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Composite;
Lines 30-42 Link Here
30
31
31
		CTabFolder folderToTest = new CTabFolder(panel, SWT.NONE);
32
		CTabFolder folderToTest = new CTabFolder(panel, SWT.NONE);
32
		CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
33
		CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
33
		tab1.setText("A TAB ITEM");
34
		
34
		
35
		engine.applyStyles(shell, true);
35
		engine.applyStyles(shell, true);
36
36
37
		shell.pack();
37
		shell.pack();
38
		shell.open();
38
		shell.open();
39
		return folderToTest;
39
		return folderToTest;
40
		
41
		
40
	}
42
	}
41
	
43
	
42
	public void testBackgroundColor() throws Exception {
44
	public void testBackgroundColor() throws Exception {
Lines 50-55 Link Here
50
		assertEquals(BLUE, folderToTest.getForeground().getRGB());
52
		assertEquals(BLUE, folderToTest.getForeground().getRGB());
51
		folderToTest.getShell().close();
53
		folderToTest.getShell().close();
52
	}
54
	}
55
	
56
	public void testFontRegular() throws Exception {
57
		CTabFolder folderToTest = createTestCTabFolder("Label { font: Verdana 16px }");
58
		assertEquals(1, folderToTest.getFont().getFontData().length);
59
		FontData fontData = folderToTest.getFont().getFontData()[0];
60
		assertEquals("Verdana", fontData.getName());
61
		assertEquals(16, fontData.getHeight());
62
		assertEquals(SWT.NORMAL, fontData.getStyle());		
63
		folderToTest.getShell().close();
64
	}
65
66
	public void testFontBold() throws Exception {
67
		CTabFolder folderToTest = createTestCTabFolder("Label { font: Arial 12px; font-weight: bold }");
68
		assertEquals(1, folderToTest.getFont().getFontData().length);
69
		FontData fontData = folderToTest.getFont().getFontData()[0];
70
		assertEquals("Arial", fontData.getName());
71
		assertEquals(12, fontData.getHeight());
72
		assertEquals(SWT.BOLD, fontData.getStyle());		
73
		folderToTest.getShell().close();
74
	}
75
76
	public void testFontItalic() throws Exception {
77
		CTabFolder folderToTest = createTestCTabFolder("Label { font: Arial 12px; font-style: italic }");
78
		assertEquals(1, folderToTest.getFont().getFontData().length);
79
		FontData fontData = folderToTest.getFont().getFontData()[0];
80
		assertEquals("Arial", fontData.getName());
81
		assertEquals(12, fontData.getHeight());
82
		assertEquals(SWT.ITALIC, fontData.getStyle());		
83
		folderToTest.getShell().close();
84
	}
53
85
54
//	public void testGradientColor() throws Exception {
86
//	public void testGradientColor() throws Exception {
55
//		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { background-color: #FF0000  #0000FF }");
87
//		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { background-color: #FF0000  #0000FF }");
Lines 67-70 Link Here
67
		assertEquals(GREEN, folderToTest.getSelectionBackground().getRGB());
99
		assertEquals(GREEN, folderToTest.getSelectionBackground().getRGB());
68
		folderToTest.getShell().close();
100
		folderToTest.getShell().close();
69
	}
101
	}
102
	
103
	public void testBorderVisible() throws Exception {
104
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { borderVisible: true}");
105
		assertEquals(true, folderToTest.getBorderVisible());
106
		folderToTest.getShell().close();
107
		folderToTest = createTestCTabFolder("CTabFolder { borderVisible: false}");
108
		assertEquals(false, folderToTest.getBorderVisible());
109
		folderToTest.getShell().close();
110
	}
111
	
112
	public void testSimple() throws Exception {
113
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { simple: true}");
114
		assertEquals(true, folderToTest.getSimple());
115
		folderToTest.getShell().close();
116
		folderToTest = createTestCTabFolder("CTabFolder { simple: false}");
117
		assertEquals(false, folderToTest.getSimple());
118
		folderToTest.getShell().close();
119
	}
120
	
121
	public void testMaximizeVisible() throws Exception {
122
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { maximizeVisible: true}");
123
		assertEquals(true, folderToTest.getMaximizeVisible());
124
		folderToTest.getShell().close();
125
		folderToTest = createTestCTabFolder("CTabFolder { maximizeVisible: false}");
126
		assertEquals(false, folderToTest.getMaximizeVisible());
127
		folderToTest.getShell().close();
128
	}
129
	
130
	public void testMinimizeVisible() throws Exception {
131
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { minimizeVisible: true}");
132
		assertEquals(true, folderToTest.getMinimizeVisible());
133
		folderToTest.getShell().close();
134
		folderToTest = createTestCTabFolder("CTabFolder { minimizeVisible: false}");
135
		assertEquals(false, folderToTest.getMinimizeVisible());
136
		folderToTest.getShell().close();
137
	}
138
	
139
	public void testMRUVisible() throws Exception {
140
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { mruVisible: true}");
141
		assertEquals(true, folderToTest.getMRUVisible());
142
		folderToTest.getShell().close();
143
		folderToTest = createTestCTabFolder("CTabFolder { mruVisible: false}");
144
		assertEquals(false, folderToTest.getMRUVisible());
145
		folderToTest.getShell().close();
146
	}
147
	
148
	public void testMaximized() throws Exception {
149
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { maximized: true}");
150
		assertEquals(true, folderToTest.getMaximized());
151
		folderToTest.getShell().close();
152
		folderToTest = createTestCTabFolder("CTabFolder { maximized: false}");
153
		assertEquals(false, folderToTest.getMaximized());
154
		folderToTest.getShell().close();
155
	}
156
	
157
	public void testMinimized() throws Exception {
158
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { minimized: true}");
159
		assertEquals(true, folderToTest.getMinimized());
160
		folderToTest.getShell().close();
161
		folderToTest = createTestCTabFolder("CTabFolder { minimized: false}");
162
		assertEquals(false, folderToTest.getMinimized());
163
		folderToTest.getShell().close();
164
	}
165
	
166
	public void testSingle() throws Exception {
167
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { single: true}");
168
		assertEquals(true, folderToTest.getSingle());
169
		folderToTest.getShell().close();
170
		folderToTest = createTestCTabFolder("CTabFolder { single: false}");
171
		assertEquals(false, folderToTest.getSingle());
172
		folderToTest.getShell().close();
173
	}
174
	
175
	public void testUnselectedCloseVisible() throws Exception {
176
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { unselectedCloseVisible: true}");
177
		assertEquals(true, folderToTest.getUnselectedCloseVisible());
178
		folderToTest.getShell().close();
179
		folderToTest = createTestCTabFolder("CTabFolder { unselectedCloseVisible: false}");
180
		assertEquals(false, folderToTest.getUnselectedCloseVisible());
181
		folderToTest.getShell().close();
182
	}
183
	
184
	public void testUnselectedImageVisible() throws Exception {
185
		CTabFolder folderToTest = createTestCTabFolder("CTabFolder { unselectedImageVisible: true}");
186
		assertEquals(true, folderToTest.getUnselectedImageVisible());
187
		folderToTest.getShell().close();
188
		folderToTest = createTestCTabFolder("CTabFolder { unselectedImageVisible: false}");
189
		assertEquals(false, folderToTest.getUnselectedImageVisible());
190
		folderToTest.getShell().close();
191
	}
70
}
192
}
(-)src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java (+3 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(ShellTest.class);
22
		addTestSuite(ButtonTest.class);
23
		addTestSuite(CssSelectorPrecedence.class);
21
	}
24
	}
22
}
25
}
(-)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/CTabFolderAddedProperties.java (+112 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.swt.SWT;
5
import org.eclipse.swt.custom.CTabFolder;
6
import org.eclipse.swt.custom.CTabItem;
7
import org.eclipse.swt.layout.FillLayout;
8
import org.eclipse.swt.widgets.Display;
9
import org.eclipse.swt.widgets.Shell;
10
11
12
public class CTabFolderAddedProperties extends CSSTestCase {
13
	
14
	protected CTabFolder createFolder(String styleSheet) {
15
		Display display = Display.getDefault();
16
		CSSEngine engine = createEngine(styleSheet, display);
17
		
18
		// Create widgets
19
        Shell shell = new Shell(display, SWT.SHELL_TRIM);
20
 		FillLayout layout = new FillLayout();
21
 		shell.setLayout(layout);
22
 		
23
 		CTabFolder folderToTest = new CTabFolder(shell, SWT.NONE);
24
 		CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
25
26
         // Apply Styles
27
 		engine.applyStyles(shell, true);
28
		
29
 		shell.pack();
30
        shell.open();
31
		return folderToTest;
32
	}
33
	        
34
//	        	Display display = Display.getDefault();
35
//	             CSSEngine engine = new CSSSWTEngineImpl(display);
36
//	             engine.parseStyleSheet(new StringReader("CTabFolder {showClose: true;}"));
37
//
38
//	             Shell shell = new Shell(display, SWT.SHELL_TRIM);
39
//	     		FillLayout layout = new FillLayout();
40
//	     		shell.setLayout(layout);
41
//	     		
42
//	     		CTabFolder folderToTest = new CTabFolder(shell, SWT.NONE);
43
//	     		CTabItem tab1 = new CTabItem(folderToTest, SWT.NONE);
44
//	     		tab1.setText("A TAB ITEM");
45
//
46
//	             // Apply Styles
47
//	     		engine.applyStyles(shell, true);
48
//	    		
49
//	     		shell.pack();
50
//	            shell.open();
51
	            
52
	public void testBorderVisible() throws Exception {
53
		CTabFolder folderToTest = createFolder("CTabFolder { borderVisible: true}");
54
		assertEquals(true, folderToTest.getBorderVisible());
55
		folderToTest.getShell().close();
56
	}
57
	
58
	public void testSimple() throws Exception {
59
		CTabFolder folderToTest = createFolder("CTabFolder { simple: true}");
60
		assertEquals(true, folderToTest.getSimple());
61
		folderToTest.getShell().close();
62
	}
63
	
64
	public void testMaximizeVisible() throws Exception {
65
		CTabFolder folderToTest = createFolder("CTabFolder { maximizeVisible: true}");
66
		assertEquals(true, folderToTest.getMaximizeVisible());
67
		folderToTest.getShell().close();
68
	}
69
	
70
	public void testMinimizeVisible() throws Exception {
71
		CTabFolder folderToTest = createFolder("CTabFolder { minimizeVisible: true}");
72
		assertEquals(true, folderToTest.getMinimizeVisible());
73
		folderToTest.getShell().close();
74
	}
75
	
76
	public void testMRUVisible() throws Exception {
77
		CTabFolder folderToTest = createFolder("CTabFolder { mruVisible: true}");
78
		assertEquals(true, folderToTest.getMRUVisible());
79
		folderToTest.getShell().close();
80
	}
81
	
82
	public void testMaximized() throws Exception {
83
		CTabFolder folderToTest = createFolder("CTabFolder { maximized: true}");
84
		assertEquals(true, folderToTest.getMaximized());
85
		folderToTest.getShell().close();
86
	}
87
	
88
	public void testMinimized() throws Exception {
89
		CTabFolder folderToTest = createFolder("CTabFolder { minimized: true}");
90
		assertEquals(true, folderToTest.getMinimized());
91
		folderToTest.getShell().close();
92
	}
93
	
94
	public void testSingle() throws Exception {
95
		CTabFolder folderToTest = createFolder("CTabFolder { single: true}");
96
		assertEquals(true, folderToTest.getSingle());
97
		folderToTest.getShell().close();
98
	}
99
	
100
	public void testUnselectedCloseVisible() throws Exception {
101
		CTabFolder folderToTest = createFolder("CTabFolder { unselectedCloseVisible: true}");
102
		assertEquals(true, folderToTest.getUnselectedCloseVisible());
103
		folderToTest.getShell().close();
104
	}
105
	
106
	public void testUnselectedImageVisible() throws Exception {
107
		CTabFolder folderToTest = createFolder("CTabFolder { unselectedImageVisible: true}");
108
		assertEquals(true, folderToTest.getUnselectedImageVisible());
109
		folderToTest.getShell().close();
110
	}
111
	    
112
}
(-)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("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
}
(-)src/org/eclipse/e4/ui/tests/css/swt/WidgetBehaviour.java (+65 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.custom.CTabFolder;
7
import org.eclipse.swt.graphics.RGB;
8
import org.eclipse.swt.layout.FillLayout;
9
import org.eclipse.swt.widgets.Button;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Display;
12
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.swt.widgets.Shell;
14
import org.eclipse.swt.widgets.Text;
15
16
17
public class WidgetBehaviour extends CSSTestCase {
18
19
	public static Button button;
20
	public static Text text;
21
	public static Label label;
22
	public static CTabFolder tabFolder;
23
	public static Shell shell;
24
	public static Composite panel;
25
	public static FillLayout layout;
26
	static final RGB RED = new RGB(255, 0, 0);
27
28
	public void createTest(String styleSheet) {
29
		Display display = Display.getDefault();
30
		CSSEngine engine = createEngine(styleSheet, display);
31
		
32
		// Create widgets
33
		shell = new Shell(display, SWT.SHELL_TRIM);
34
		layout = new FillLayout();
35
		shell.setLayout(layout);
36
37
		panel = new Composite(shell, SWT.NONE);
38
		panel.setLayout(new FillLayout());
39
40
		label = new Label(panel, SWT.NONE);
41
		label.setText("Some label text");
42
		
43
		button = new Button(panel, SWT.NONE);
44
		button.setText("Some button text");
45
		
46
		text = new Text(panel, SWT.NONE);
47
		text.setText("Some text");
48
		
49
		tabFolder = new CTabFolder(panel, SWT.NONE);
50
			// Apply styles
51
		engine.applyStyles(shell,true);
52
53
		shell.pack();
54
		shell.open();
55
		engine.applyStyles(shell, true);
56
	}
57
	
58
	public void testBackgroudColor(){
59
		createTest("Label, Button, Shell  { background-color: #FF0000;}");
60
		assertEquals(RED, button.getBackground().getRGB());
61
		assertEquals(RED, label.getBackground().getRGB());
62
63
	}
64
65
}
(-)src/org/eclipse/e4/ui/tests/css/swt/ShellTest.java (+74 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.swt.SWT;
5
import org.eclipse.swt.graphics.FontData;
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.Shell;
11
12
public class ShellTest extends CSSTestCase {
13
14
	static final RGB RED = new RGB(255, 0, 0);
15
	static final RGB GREEN = new RGB(0, 255, 0);
16
	static final RGB BLUE = new RGB(0, 0, 255);
17
		
18
	protected Shell createTestShell(String styleSheet) {
19
		Display display = Display.getDefault();
20
		CSSEngine engine = createEngine(styleSheet, display);
21
		
22
		// Create widgets
23
		Shell shell = new Shell(display, SWT.SHELL_TRIM);
24
		FillLayout layout = new FillLayout();
25
		shell.setLayout(layout);
26
27
		Composite panel = new Composite(shell, SWT.NONE);
28
		panel.setLayout(new FillLayout());
29
30
		// Apply styles
31
		engine.applyStyles(shell, true);
32
33
		shell.pack();
34
		shell.open();
35
		return shell;
36
	}
37
	
38
	
39
	public void testColor() throws Exception {
40
		Shell shellToTest = createTestShell("Shell { background-color: #FF0000; color: #0000FF }");
41
		assertEquals(RED, shellToTest.getBackground().getRGB());
42
		assertEquals(BLUE, shellToTest.getForeground().getRGB());
43
		shellToTest.getShell().close();
44
	}
45
46
	public void testFontRegular() throws Exception {
47
		Shell shellToTest = createTestShell("Shell { font: Verdana 16px }");
48
		assertEquals(1, shellToTest.getFont().getFontData().length);
49
		FontData fontData = shellToTest.getFont().getFontData()[0];
50
		assertEquals("Verdana", fontData.getName());
51
		assertEquals(16, fontData.getHeight());
52
		assertEquals(SWT.NORMAL, fontData.getStyle());		
53
		shellToTest.getShell().close();
54
	}
55
56
	public void testFontBold() throws Exception {
57
		Shell shellToTest = createTestShell("Shell { font: Arial 12px; font-weight: bold }");
58
		assertEquals(1, shellToTest.getFont().getFontData().length);
59
		FontData fontData = shellToTest.getFont().getFontData()[0];
60
		assertEquals("Arial", fontData.getName());
61
		assertEquals(12, fontData.getHeight());
62
		assertEquals(SWT.BOLD, fontData.getStyle());		
63
		shellToTest.getShell().close();
64
	}
65
66
	public void testFontItalic() throws Exception {
67
		Shell shellToTest = createTestShell("Shell { font-style: italic }");
68
		assertEquals(1, shellToTest.getFont().getFontData().length);
69
		FontData fontData = shellToTest.getFont().getFontData()[0];
70
		assertEquals(SWT.ITALIC, fontData.getStyle());		
71
		shellToTest.getShell().close();
72
	}
73
74
}
(-)src/org/eclipse/e4/ui/tests/css/swt/ButtonTest.java (+84 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.swt.SWT;
5
import org.eclipse.swt.graphics.FontData;
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.Button;
11
import org.eclipse.swt.widgets.Shell;
12
13
public class ButtonTest extends CSSTestCase {
14
15
	static final RGB RED = new RGB(255, 0, 0);
16
	static final RGB GREEN = new RGB(0, 255, 0);
17
	static final RGB BLUE = new RGB(0, 0, 255);
18
		
19
	protected Button createTestButton(String styleSheet) {
20
		Display display = Display.getDefault();
21
		CSSEngine engine = createEngine(styleSheet, display);
22
		
23
		// Create widgets
24
		Shell shell = new Shell(display, SWT.SHELL_TRIM);
25
		FillLayout layout = new FillLayout();
26
		shell.setLayout(layout);
27
28
		Composite panel = new Composite(shell, SWT.NONE);
29
		panel.setLayout(new FillLayout());
30
31
		Button buttonToTest = new Button(panel, SWT.NONE);
32
		buttonToTest.setText("Some button text");
33
34
		// Apply styles
35
		engine.applyStyles(shell, true);
36
37
		shell.pack();
38
		shell.open();
39
		return buttonToTest;
40
	}
41
	
42
	
43
	public void testColor() throws Exception {
44
		Button buttonToTest = createTestButton("Button { background-color: #FF0000; color: #0000FF }");
45
		assertEquals(RED, buttonToTest.getBackground().getRGB());
46
		assertEquals(BLUE, buttonToTest.getForeground().getRGB());
47
		buttonToTest.getShell().close();
48
	}
49
50
	public void testFontRegular() throws Exception {
51
		Button buttonToTest = createTestButton("Button { font: Verdana 16px }");
52
		assertEquals(1, buttonToTest.getFont().getFontData().length);
53
		FontData fontData = buttonToTest.getFont().getFontData()[0];
54
		assertEquals("Verdana", fontData.getName());
55
		assertEquals(16, fontData.getHeight());
56
		assertEquals(SWT.NORMAL, fontData.getStyle());		
57
		buttonToTest.getShell().close();
58
	}
59
60
	public void testFontBold() throws Exception {
61
		Button buttonToTest = createTestButton("Button { font: Arial 12px; font-weight: bold }");
62
		assertEquals(1, buttonToTest.getFont().getFontData().length);
63
		FontData fontData = buttonToTest.getFont().getFontData()[0];
64
		assertEquals("Arial", fontData.getName());
65
		assertEquals(12, fontData.getHeight());
66
		assertEquals(SWT.BOLD, fontData.getStyle());		
67
		buttonToTest.getShell().close();
68
	}
69
70
	public void testFontItalic() throws Exception {
71
		Button buttonToTest = createTestButton("Button { font-style: italic }");
72
		assertEquals(1, buttonToTest.getFont().getFontData().length);
73
		FontData fontData = buttonToTest.getFont().getFontData()[0];
74
		assertEquals(SWT.ITALIC, fontData.getStyle());		
75
		buttonToTest.getShell().close();
76
	}
77
	
78
	public void testBorder() throws Exception {
79
		Button buttonToTest = createTestButton("Button { border-width: 2;}");
80
		assertEquals(buttonToTest.getBorderWidth(), 2);		
81
		buttonToTest.getShell().close();
82
	}
83
84
}

Return to bug 263081