[371430] Wrong encoding type returned for XHTML file without 'html' as document root
diff --git a/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java b/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java
index 7555650..9e49db4 100644
--- a/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java
+++ b/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/HTMLCoreTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation 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
@@ -14,6 +14,7 @@
import junit.framework.TestSuite;
import org.eclipse.wst.html.core.tests.cleanup.TestHTMLCleanupProcessor;
+import org.eclipse.wst.html.core.tests.contenttype.TestHTMLResourceEncodingDetector;
import org.eclipse.wst.html.core.tests.format.TestFormatProcessorHTML;
import org.eclipse.wst.html.core.tests.format.TestFormatUtility;
import org.eclipse.wst.html.core.tests.html5.model.HTML5ContentModelTest;
@@ -55,6 +56,6 @@
addTest(new TestSuite(TestCatalogContentModels.class));
addTest(TestHTMLCleanupProcessor.suite());
addTest(new TestSuite(HTML5ContentModelTest.class));
-
+ addTest(new TestSuite(TestHTMLResourceEncodingDetector.class));
}
}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/contenttype/TestHTMLResourceEncodingDetector.java b/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/contenttype/TestHTMLResourceEncodingDetector.java
new file mode 100644
index 0000000..32b3cea
--- /dev/null
+++ b/tests/org.eclipse.wst.html.core.tests/src/org/eclipse/wst/html/core/tests/contenttype/TestHTMLResourceEncodingDetector.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.html.core.tests.contenttype;
+
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.eclipse.wst.html.core.internal.contenttype.HTMLResourceEncodingDetector;
+
+import junit.framework.TestCase;
+/**
+ *
+ * Create due to bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=371430
+ *
+ */
+public class TestHTMLResourceEncodingDetector extends TestCase {
+
+ HTMLResourceEncodingDetector htmlResouceEncodingDetector;
+ private static final String XMLDeclContent_UTF8= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
+ private static final String XMLDeclContent_ISO= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
+ private static final String XHTMLContent_HTML_AS_ROOTELEMENT = "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
+ private static final String XHTMLContent_NOT_HTML_AS_ROOTELEMENT= "<ui:composition attribut=43 xmlns=\"http://www.w3.org/1999/xhtml\">";
+ private static final String METAContent = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />";
+
+
+ public TestHTMLResourceEncodingDetector() {
+ this("HTML Resource Encoding Detector");
+ }
+
+ public TestHTMLResourceEncodingDetector(String string) {
+ super(string);
+ }
+
+
+ protected void setUp() throws Exception {
+ htmlResouceEncodingDetector = new HTMLResourceEncodingDetector();
+ }
+
+
+ private String getContentType(String content) throws IOException{
+ Reader contentReader = new CharArrayReader(content.toCharArray());
+ htmlResouceEncodingDetector.set(contentReader);
+ return htmlResouceEncodingDetector.getEncoding();
+ }
+
+
+ public void testXMLDecl() throws IOException{
+ String contentType=getContentType(XMLDeclContent_UTF8+XHTMLContent_HTML_AS_ROOTELEMENT+METAContent);
+ assertEquals("UTF-8", contentType);
+
+ contentType=getContentType(XMLDeclContent_ISO+XHTMLContent_HTML_AS_ROOTELEMENT+METAContent);
+ assertEquals("ISO-8859-1", contentType);
+
+ contentType=getContentType(XMLDeclContent_UTF8+XHTMLContent_NOT_HTML_AS_ROOTELEMENT+METAContent);
+ assertEquals("UTF-8", contentType);
+
+ contentType=getContentType (XMLDeclContent_ISO + XHTMLContent_NOT_HTML_AS_ROOTELEMENT);
+ assertEquals("ISO-8859-1", contentType);
+ }
+
+ public void testMetaDecl() throws IOException{
+ String contentType = getContentType(XHTMLContent_HTML_AS_ROOTELEMENT+METAContent);
+ assertEquals("ISO-8859-1", contentType);
+
+ contentType = getContentType(XHTMLContent_NOT_HTML_AS_ROOTELEMENT+METAContent);
+ assertEquals("ISO-8859-1", contentType);
+ }
+
+
+ public void testXHTML() throws IOException{
+ String contentType = getContentType(XHTMLContent_HTML_AS_ROOTELEMENT);
+ assertEquals("UTF-8", contentType);
+
+ contentType = getContentType(XHTMLContent_NOT_HTML_AS_ROOTELEMENT);
+ assertEquals("UTF-8", contentType);
+ }
+}