aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2014-04-03 08:18:38 (EDT)
committerPaul Webster2014-04-04 16:04:23 (EDT)
commite0c09f30121476543962345ea93f3812de09f6b3 (patch)
tree5c1cd9753fbe98a6ac94e0d399f1fe61b32061ea
parentbbcd42522c3f7fb76f0ec98666ef20786297a58e (diff)
downloadeclipse.platform.ui-e0c09f30121476543962345ea93f3812de09f6b3.zip
eclipse.platform.ui-e0c09f30121476543962345ea93f3812de09f6b3.tar.gz
eclipse.platform.ui-e0c09f30121476543962345ea93f3812de09f6b3.tar.bz2
Bug 430052 - [CSS] Imported rules cannot be overriddenrefs/changes/81/24381/2
Added testcase Change-Id: I4ddf08b274351d17d5e11ce86af6cb2a271d5b79 Signed-off-by: Stefan Winkler <stefan@winklerweb.net>
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/CssCoreTestSuite.java3
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java106
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/CssCoreTestSuite.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/CssCoreTestSuite.java
index a11faee..144f2ee 100644
--- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/CssCoreTestSuite.java
+++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/CssCoreTestSuite.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stefan Winkler <stefan@winklerweb.net> - Bug 430052
*******************************************************************************/
package org.eclipse.e4.ui.tests.css.core;
@@ -15,6 +16,7 @@ import junit.framework.TestSuite;
import org.eclipse.e4.ui.tests.css.core.parser.CascadeTest;
import org.eclipse.e4.ui.tests.css.core.parser.FontFaceRulesTest;
+import org.eclipse.e4.ui.tests.css.core.parser.ImportTest;
import org.eclipse.e4.ui.tests.css.core.parser.RGBColorImplTest;
import org.eclipse.e4.ui.tests.css.core.parser.SelectorTest;
import org.eclipse.e4.ui.tests.css.core.parser.StyleRuleTest;
@@ -38,6 +40,7 @@ public class CssCoreTestSuite extends TestSuite {
addTestSuite(ValueTest.class);
addTestSuite(SelectorTest.class);
addTestSuite(CSSEngineTest.class);
+ addTestSuite(ImportTest.class);
// $JUnit-END$
}
}
diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java
new file mode 100644
index 0000000..ffa30d6
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Stefan Winkler and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Winkler <stefan@winklerweb.net> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.ui.tests.css.core.parser;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl;
+import org.eclipse.e4.ui.css.core.impl.dom.ViewCSSImpl;
+import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil;
+import org.eclipse.e4.ui.tests.css.core.util.TestElement;
+import org.w3c.css.sac.InputSource;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.ViewCSS;
+import org.w3c.dom.stylesheets.StyleSheet;
+
+public class ImportTest extends TestCase {
+
+ private CSSEngine engine;
+
+ @Override
+ protected void setUp() throws Exception {
+ engine = ParserTestUtil.createEngine();
+ }
+
+ /**
+ * Test case for Bug 430052 - [CSS] Imported rules cannot be overridden
+ *
+ * @throws Exception
+ */
+ public void testOverrideImportedRule() throws Exception {
+ String importedCss = ".ClassAlpha {\n" //
+ + " property: value;\n" //
+ + " }\n" + " .ClassBeta {\n" //
+ + " property: value1;\n" //
+ + " }";
+
+ File importedFile = createTempCssFile(importedCss);
+ String importedFileName = importedFile.getName();
+ String importedFilePath = importedFile.getParent();
+
+ String importingCss = "@import url('" + importedFileName + "');\n" //
+ + " .ClassBeta {\n" //
+ + " property: value2;\n" //
+ + " }";
+
+ // we need a file URL so that the import can be resolved
+ String importingUrl = "file:///" + importedFilePath + "/importing.css";
+
+ ViewCSS viewCSS = createViewCss(importingUrl, importingCss);
+
+ TestElement buttonAlpha = new TestElement("Button", engine);
+ buttonAlpha.setClass("ClassAlpha");
+
+ TestElement buttonBeta = new TestElement("Button", engine);
+ buttonBeta.setClass("ClassBeta");
+
+ CSSStyleDeclaration styleAlpha = viewCSS.getComputedStyle(buttonAlpha,
+ null);
+ CSSStyleDeclaration styleBeta = viewCSS.getComputedStyle(buttonBeta,
+ null);
+
+ assertEquals("value", styleAlpha.getPropertyCSSValue("property")
+ .getCssText());
+ assertEquals("value2", styleBeta.getPropertyCSSValue("property")
+ .getCssText());
+ }
+
+ private File createTempCssFile(String cssString) throws Exception {
+ File result = File.createTempFile("e4.ui.tests-", ".css");
+ FileWriter fileWriter = new FileWriter(result);
+ try {
+ fileWriter.write(cssString);
+ return result;
+ } finally {
+ try {
+ fileWriter.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ private ViewCSS createViewCss(String sourceUrl, String cssString)
+ throws IOException {
+ InputSource source = new InputSource();
+ source.setURI(sourceUrl); // must not be null
+ source.setCharacterStream(new StringReader(cssString));
+ StyleSheet styleSheet = engine.parseStyleSheet(source);
+
+ DocumentCSSImpl docCss = new DocumentCSSImpl();
+ docCss.addStyleSheet(styleSheet);
+ return new ViewCSSImpl(docCss);
+ }
+}