|
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 |
} |