Add fast/encoding layout tests.

Merged from WebKit at r67178.

The vast majority of these are passing. The exceptions:
- Three Mac-specific tests, won't fix.
- Four failures in the Java HTTP stack (no problem for the Chrome HTTP stack).
- fast/encoding/mailto-always-utf-8 needs a new LayoutTestController callback.

Change-Id: I16c613d42acd0ea2dc146909d514376d0a2e5aaa
diff --git a/LayoutTests/fast/encoding/GBK/EUC-CN-expected.txt b/LayoutTests/fast/encoding/GBK/EUC-CN-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/EUC-CN-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/EUC-CN.html b/LayoutTests/fast/encoding/GBK/EUC-CN.html
new file mode 100644
index 0000000..cb8f53f
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/EUC-CN.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=EUC-CN" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/chinese-expected.txt b/LayoutTests/fast/encoding/GBK/chinese-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/chinese-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/chinese.html b/LayoutTests/fast/encoding/GBK/chinese.html
new file mode 100644
index 0000000..a6a4c08
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/chinese.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=chinese" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/close-gbk-converter-expected.txt b/LayoutTests/fast/encoding/GBK/close-gbk-converter-expected.txt
new file mode 100644
index 0000000..92bd02f
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/close-gbk-converter-expected.txt
@@ -0,0 +1,3 @@
+This tests performs a sequence of actions that result in a GBK converter with substitution enabled being destroyed.
+
+PASS if there is no assertion failure.
diff --git a/LayoutTests/fast/encoding/GBK/close-gbk-converter.html b/LayoutTests/fast/encoding/GBK/close-gbk-converter.html
new file mode 100644
index 0000000..390246a
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/close-gbk-converter.html
@@ -0,0 +1,22 @@
+<head>
+<meta charset="gbk">
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+    var req = new XMLHttpRequest;
+    req.open("GET", "?§Ø", false);
+    req.send();
+
+    req = new XMLHttpRequest;
+    req.open("GET", "/§Ø", false);
+    req.send();
+}
+</script>
+</head>
+<body onload="test()">
+<p>This tests performs a sequence of actions that result in a GBK converter with substitution enabled being destroyed.</p>
+<p>PASS if there is no assertion failure.</p>
+</body>
diff --git a/LayoutTests/fast/encoding/GBK/cn-gb-expected.txt b/LayoutTests/fast/encoding/GBK/cn-gb-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/cn-gb-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/cn-gb.html b/LayoutTests/fast/encoding/GBK/cn-gb.html
new file mode 100644
index 0000000..99b11ff
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/cn-gb.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=cn-gb" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/csgb2312-expected.txt b/LayoutTests/fast/encoding/GBK/csgb2312-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/csgb2312-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/csgb2312.html b/LayoutTests/fast/encoding/GBK/csgb2312.html
new file mode 100644
index 0000000..f7afd45
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/csgb2312.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=csgb2312" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/csgb231280-expected.txt b/LayoutTests/fast/encoding/GBK/csgb231280-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/csgb231280-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/csgb231280.html b/LayoutTests/fast/encoding/GBK/csgb231280.html
new file mode 100644
index 0000000..033d8ef
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/csgb231280.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=csgb231280" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/gb2312-expected.txt b/LayoutTests/fast/encoding/GBK/gb2312-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gb2312-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/gb2312.html b/LayoutTests/fast/encoding/GBK/gb2312.html
new file mode 100644
index 0000000..72e69ea
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gb2312.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=gb2312" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/gb_2312-80-expected.txt b/LayoutTests/fast/encoding/GBK/gb_2312-80-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gb_2312-80-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/gb_2312-80.html b/LayoutTests/fast/encoding/GBK/gb_2312-80.html
new file mode 100644
index 0000000..e16695e
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gb_2312-80.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=gb_2312-80" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/gbk-expected.txt b/LayoutTests/fast/encoding/GBK/gbk-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gbk-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/gbk.html b/LayoutTests/fast/encoding/GBK/gbk.html
new file mode 100644
index 0000000..6632595
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/gbk.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=gbk" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/iso-ir-58-expected.txt b/LayoutTests/fast/encoding/GBK/iso-ir-58-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/iso-ir-58-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/iso-ir-58.html b/LayoutTests/fast/encoding/GBK/iso-ir-58.html
new file mode 100644
index 0000000..7fa90bc
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/iso-ir-58.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=iso-ir-58" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/x-euc-cn-expected.txt b/LayoutTests/fast/encoding/GBK/x-euc-cn-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/x-euc-cn-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/x-euc-cn.html b/LayoutTests/fast/encoding/GBK/x-euc-cn.html
new file mode 100644
index 0000000..4311d05
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/x-euc-cn.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=x-euc-cn" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/GBK/x-gbk-expected.txt b/LayoutTests/fast/encoding/GBK/x-gbk-expected.txt
new file mode 100644
index 0000000..ec39154
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/x-gbk-expected.txt
@@ -0,0 +1,5 @@
+The following two lines should look identically:
+
+一筆€镕
+
+一筆€镕
diff --git a/LayoutTests/fast/encoding/GBK/x-gbk.html b/LayoutTests/fast/encoding/GBK/x-gbk.html
new file mode 100644
index 0000000..04aa636
--- /dev/null
+++ b/LayoutTests/fast/encoding/GBK/x-gbk.html
@@ -0,0 +1,10 @@
+<head>
+    <meta content="text/html; charset=x-gbk" http-equiv="Content-Type"/>
+</head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>The following two lines should look identically:</p>
+<p>Ò»¹P€éF</p>
+<p>&#19968;&#31558;&euro;&#38229;</p>
diff --git a/LayoutTests/fast/encoding/ahram-org-eg-expected.txt b/LayoutTests/fast/encoding/ahram-org-eg-expected.txt
new file mode 100644
index 0000000..990472f
--- /dev/null
+++ b/LayoutTests/fast/encoding/ahram-org-eg-expected.txt
@@ -0,0 +1,3 @@
+Test a particular example of broken markup that was making us ignore a charset declaration.
+
+Encoding: windows-1256 (should be windows-1256)
diff --git a/LayoutTests/fast/encoding/ahram-org-eg.html b/LayoutTests/fast/encoding/ahram-org-eg.html
new file mode 100644
index 0000000..d75cf06
--- /dev/null
+++ b/LayoutTests/fast/encoding/ahram-org-eg.html
@@ -0,0 +1,28 @@
+<htm>
+
+<head>
+<meta http-equiv="content-language" content="en-us">
+<meta http-equiv='content-type' content='text/htm; charset=windows-1256'>
+<script language="javascript">
+	if (navigator.appName == "Netscape")
+	{
+		document.write("<meta http-equiv='content-type' content='text/htm; charset=x-user-defined'>");
+	}
+</script>
+</head>
+
+<body>
+<p>Test a particular example of broken markup that was making us ignore a charset declaration.</p>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var charset = document.characterSet;
+  if (!charset)
+    charset = document.charset;
+  if (!charset)
+    charset = document.inputEncoding;
+  document.write("Encoding: " + charset + " (should be windows-1256)");
+</script>
+</body>
+</htm>
diff --git a/LayoutTests/fast/encoding/bandai-co-jp-releases-expected.txt b/LayoutTests/fast/encoding/bandai-co-jp-releases-expected.txt
new file mode 100644
index 0000000..f069c44
--- /dev/null
+++ b/LayoutTests/fast/encoding/bandai-co-jp-releases-expected.txt
@@ -0,0 +1,3 @@
+Test a particular example of broken markup that was making us ignore a charset declaration.
+
+Encoding: Shift_JIS (should be Shift_JIS)
diff --git a/LayoutTests/fast/encoding/bandai-co-jp-releases.html b/LayoutTests/fast/encoding/bandai-co-jp-releases.html
new file mode 100644
index 0000000..c3c2fdd
--- /dev/null
+++ b/LayoutTests/fast/encoding/bandai-co-jp-releases.html
@@ -0,0 +1,21 @@
+<div class="moz-text-flowed" style="font-family: -moz-fixed">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
+</head>
+
+<body>
+<p>Test a particular example of broken markup that was making us ignore a charset declaration.</p>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var charset = document.characterSet;
+  if (!charset)
+    charset = document.charset;
+  if (!charset)
+    charset = document.inputEncoding;
+  document.write("Encoding: " + charset + " (should be Shift_JIS)");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/bom-in-content-expected.txt b/LayoutTests/fast/encoding/bom-in-content-expected.txt
new file mode 100644
index 0000000..11252db
--- /dev/null
+++ b/LayoutTests/fast/encoding/bom-in-content-expected.txt
@@ -0,0 +1,4 @@
+Test for bug 18681: BOM characters should not be removed from input stream.
+
+
+PASS
diff --git a/LayoutTests/fast/encoding/bom-in-content-utf16-expected.txt b/LayoutTests/fast/encoding/bom-in-content-utf16-expected.txt
new file mode 100644
index 0000000..11252db
--- /dev/null
+++ b/LayoutTests/fast/encoding/bom-in-content-utf16-expected.txt
@@ -0,0 +1,4 @@
+Test for bug 18681: BOM characters should not be removed from input stream.
+
+
+PASS
diff --git a/LayoutTests/fast/encoding/bom-in-content-utf16.html b/LayoutTests/fast/encoding/bom-in-content-utf16.html
new file mode 100644
index 0000000..3b55ad1
--- /dev/null
+++ b/LayoutTests/fast/encoding/bom-in-content-utf16.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/bom-in-content.html b/LayoutTests/fast/encoding/bom-in-content.html
new file mode 100644
index 0000000..c30a914
--- /dev/null
+++ b/LayoutTests/fast/encoding/bom-in-content.html
@@ -0,0 +1,14 @@
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=18681">bug 18681</a>:
+BOM characters should not be removed from input stream.<p>
+<div id=BOMs></div>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.write(document.getElementById("BOMs").innerHTML.length == 1 ? "PASS" : "FAIL");
+</script>
+</body>
diff --git a/LayoutTests/fast/encoding/char-decoding-expected.txt b/LayoutTests/fast/encoding/char-decoding-expected.txt
new file mode 100644
index 0000000..26afe48
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-decoding-expected.txt
@@ -0,0 +1,163 @@
+This tests decoding characters in various character sets.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS decode('UTF-8', '%E2%88%9A') is 'U+221A'
+PASS decode('gb2312', '%A3%A0') is 'U+3000'
+PASS decode('gb_2312-80', '%A3%A0') is 'U+3000'
+PASS decode('chinese', '%A3%A0') is 'U+3000'
+PASS decode('gbk', '%A3%A0') is 'U+3000'
+PASS decode('gb18030', '%A3%A0') is 'U+3000'
+PASS decode('EUC-CN', '%A3%A0') is 'U+3000'
+PASS decode('Shift_JIS', '%82%d0') is 'U+3072'
+PASS decode('shift-jis', '%82%d0') is 'U+3072'
+PASS decode('korean', '%A2%E6') is 'U+20AC'
+PASS decode('korean', '%A1%A4') is 'U+00B7'
+PASS decode('korean', '%A1%A9') is 'U+00AD'
+PASS decode('korean', '%A1%AA') is 'U+2015'
+PASS decode('korean', '%A1%AD') is 'U+223C'
+PASS decode('korean', '%A2%A6') is 'U+FF5E'
+PASS decode('korean', '%A2%C1') is 'U+2299'
+PASS decode('korean', '%1A') is 'U+001A'
+PASS decode('korean', '%1C') is 'U+001C'
+PASS decode('korean', '%8F%A1') is 'U+B8EA'
+PASS decode('korean', '%B4%D3') is 'U+B2D2'
+PASS decode('korean', '%A2%41') is 'U+C910'
+PASS decode('EUC-KR', '%A2%E6') is 'U+20AC'
+PASS decode('EUC-KR', '%A1%A4') is 'U+00B7'
+PASS decode('EUC-KR', '%A1%A9') is 'U+00AD'
+PASS decode('EUC-KR', '%A1%AA') is 'U+2015'
+PASS decode('EUC-KR', '%A1%AD') is 'U+223C'
+PASS decode('EUC-KR', '%A2%A6') is 'U+FF5E'
+PASS decode('EUC-KR', '%A2%C1') is 'U+2299'
+PASS decode('EUC-KR', '%1A') is 'U+001A'
+PASS decode('EUC-KR', '%1C') is 'U+001C'
+PASS decode('EUC-KR', '%8F%A1') is 'U+B8EA'
+PASS decode('EUC-KR', '%B4%D3') is 'U+B2D2'
+PASS decode('EUC-KR', '%A2%41') is 'U+C910'
+PASS decode('windows-949', '%A2%E6') is 'U+20AC'
+PASS decode('windows-949', '%A1%A4') is 'U+00B7'
+PASS decode('windows-949', '%A1%A9') is 'U+00AD'
+PASS decode('windows-949', '%A1%AA') is 'U+2015'
+PASS decode('windows-949', '%A1%AD') is 'U+223C'
+PASS decode('windows-949', '%A2%A6') is 'U+FF5E'
+PASS decode('windows-949', '%A2%C1') is 'U+2299'
+PASS decode('windows-949', '%1A') is 'U+001A'
+PASS decode('windows-949', '%1C') is 'U+001C'
+PASS decode('windows-949', '%8F%A1') is 'U+B8EA'
+PASS decode('windows-949', '%B4%D3') is 'U+B2D2'
+PASS decode('windows-949', '%A2%41') is 'U+C910'
+PASS decode('x-windows-949', '%A2%E6') is 'U+20AC'
+PASS decode('x-windows-949', '%A1%A4') is 'U+00B7'
+PASS decode('x-windows-949', '%A1%A9') is 'U+00AD'
+PASS decode('x-windows-949', '%A1%AA') is 'U+2015'
+PASS decode('x-windows-949', '%A1%AD') is 'U+223C'
+PASS decode('x-windows-949', '%A2%A6') is 'U+FF5E'
+PASS decode('x-windows-949', '%A2%C1') is 'U+2299'
+PASS decode('x-windows-949', '%1A') is 'U+001A'
+PASS decode('x-windows-949', '%1C') is 'U+001C'
+PASS decode('x-windows-949', '%8F%A1') is 'U+B8EA'
+PASS decode('x-windows-949', '%B4%D3') is 'U+B2D2'
+PASS decode('x-windows-949', '%A2%41') is 'U+C910'
+PASS decode('x-uhc', '%A2%E6') is 'U+20AC'
+PASS decode('x-uhc', '%A1%A4') is 'U+00B7'
+PASS decode('x-uhc', '%A1%A9') is 'U+00AD'
+PASS decode('x-uhc', '%A1%AA') is 'U+2015'
+PASS decode('x-uhc', '%A1%AD') is 'U+223C'
+PASS decode('x-uhc', '%A2%A6') is 'U+FF5E'
+PASS decode('x-uhc', '%A2%C1') is 'U+2299'
+PASS decode('x-uhc', '%1A') is 'U+001A'
+PASS decode('x-uhc', '%1C') is 'U+001C'
+PASS decode('x-uhc', '%8F%A1') is 'U+B8EA'
+PASS decode('x-uhc', '%B4%D3') is 'U+B2D2'
+PASS decode('x-uhc', '%A2%41') is 'U+C910'
+PASS decode('iso-ir-149', '%A2%E6') is 'U+20AC'
+PASS decode('iso-ir-149', '%A1%A4') is 'U+00B7'
+PASS decode('iso-ir-149', '%A1%A9') is 'U+00AD'
+PASS decode('iso-ir-149', '%A1%AA') is 'U+2015'
+PASS decode('iso-ir-149', '%A1%AD') is 'U+223C'
+PASS decode('iso-ir-149', '%A2%A6') is 'U+FF5E'
+PASS decode('iso-ir-149', '%A2%C1') is 'U+2299'
+PASS decode('iso-ir-149', '%1A') is 'U+001A'
+PASS decode('iso-ir-149', '%1C') is 'U+001C'
+PASS decode('iso-ir-149', '%8F%A1') is 'U+B8EA'
+PASS decode('iso-ir-149', '%B4%D3') is 'U+B2D2'
+PASS decode('iso-ir-149', '%A2%41') is 'U+C910'
+PASS decode('KS_C_5601-1987', '%A2%E6') is 'U+20AC'
+PASS decode('KS_C_5601-1987', '%A1%A4') is 'U+00B7'
+PASS decode('KS_C_5601-1987', '%A1%A9') is 'U+00AD'
+PASS decode('KS_C_5601-1987', '%A1%AA') is 'U+2015'
+PASS decode('KS_C_5601-1987', '%A1%AD') is 'U+223C'
+PASS decode('KS_C_5601-1987', '%A2%A6') is 'U+FF5E'
+PASS decode('KS_C_5601-1987', '%A2%C1') is 'U+2299'
+PASS decode('KS_C_5601-1987', '%1A') is 'U+001A'
+PASS decode('KS_C_5601-1987', '%1C') is 'U+001C'
+PASS decode('KS_C_5601-1987', '%8F%A1') is 'U+B8EA'
+PASS decode('KS_C_5601-1987', '%B4%D3') is 'U+B2D2'
+PASS decode('KS_C_5601-1987', '%A2%41') is 'U+C910'
+PASS decode('KS_C_5601-1989', '%A2%E6') is 'U+20AC'
+PASS decode('KS_C_5601-1989', '%A1%A4') is 'U+00B7'
+PASS decode('KS_C_5601-1989', '%A1%A9') is 'U+00AD'
+PASS decode('KS_C_5601-1989', '%A1%AA') is 'U+2015'
+PASS decode('KS_C_5601-1989', '%A1%AD') is 'U+223C'
+PASS decode('KS_C_5601-1989', '%A2%A6') is 'U+FF5E'
+PASS decode('KS_C_5601-1989', '%A2%C1') is 'U+2299'
+PASS decode('KS_C_5601-1989', '%1A') is 'U+001A'
+PASS decode('KS_C_5601-1989', '%1C') is 'U+001C'
+PASS decode('KS_C_5601-1989', '%8F%A1') is 'U+B8EA'
+PASS decode('KS_C_5601-1989', '%B4%D3') is 'U+B2D2'
+PASS decode('KS_C_5601-1989', '%A2%41') is 'U+C910'
+PASS decode('iso-8859-9', '%80') is 'U+20AC'
+PASS decode('iso-8859-9', '%9F') is 'U+0178'
+PASS decode('iso-8859-9', '%FD') is 'U+0131'
+PASS decode('latin5', '%80') is 'U+20AC'
+PASS decode('latin5', '%9F') is 'U+0178'
+PASS decode('latin5', '%FD') is 'U+0131'
+PASS decode('windows-1254', '%80') is 'U+20AC'
+PASS decode('windows-1254', '%9F') is 'U+0178'
+PASS decode('windows-1254', '%FD') is 'U+0131'
+PASS decode('ISO-8859-13', '%A1') is 'U+201D'
+PASS decode('ISO-8859-13', '%A5') is 'U+201E'
+PASS decode('ISO-8859-13', '%B4') is 'U+201C'
+PASS decode('ISO-8859-13', '%FF') is 'U+2019'
+PASS decode('windows-1257', '%80') is 'U+20AC'
+PASS decode('windows-1257', '%B4') is 'U+00B4'
+PASS decode('windows-1257', '%FF') is 'U+02D9'
+PASS decode('iso-8859-7', '%A1') is 'U+2018'
+PASS decode('iso-8859-7', '%B5') is 'U+0385'
+PASS decode('iso-8859-7', '%B6') is 'U+0386'
+PASS decode('windows-1253', '%80') is 'U+20AC'
+PASS decode('windows-1253', '%A1') is 'U+0385'
+PASS decode('windows-1253', '%B5') is 'U+00B5'
+PASS decode('windows-1253', '%B6') is 'U+00B6'
+PASS decode('KOI8-R', '%A4') is 'U+2553'
+PASS decode('KOI8-R', '%AD') is 'U+255C'
+PASS decode('KOI8-U', '%A4') is 'U+0454'
+PASS decode('KOI8-U', '%AD') is 'U+0491'
+PASS decode('TIS-620', '%80') is 'U+20AC'
+PASS decode('TIS-620', '%96') is 'U+2013'
+PASS decode('TIS-620', '%A0') is 'U+00A0'
+PASS decode('TIS-620', '%A1') is 'U+0E01'
+PASS decode('TIS-620', '%DB') is 'U+F8C1'
+PASS decode('ISO-8859-11', '%80') is 'U+20AC'
+PASS decode('ISO-8859-11', '%96') is 'U+2013'
+PASS decode('ISO-8859-11', '%A0') is 'U+00A0'
+PASS decode('ISO-8859-11', '%A1') is 'U+0E01'
+PASS decode('ISO-8859-11', '%DB') is 'U+F8C1'
+PASS decode('windows-874', '%80') is 'U+20AC'
+PASS decode('windows-874', '%96') is 'U+2013'
+PASS decode('windows-874', '%A0') is 'U+00A0'
+PASS decode('windows-874', '%A1') is 'U+0E01'
+PASS decode('windows-874', '%DB') is 'U+F8C1'
+PASS decode('dos-874', '%80') is 'U+20AC'
+PASS decode('dos-874', '%96') is 'U+2013'
+PASS decode('dos-874', '%A0') is 'U+00A0'
+PASS decode('dos-874', '%A1') is 'U+0E01'
+PASS decode('dos-874', '%DB') is 'U+F8C1'
+PASS decode('UTF-7', '+AD4') is 'U+002B'
+PASS decode('utf-7', '+AD4') is 'U+002B'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/encoding/char-decoding-mac-expected.txt b/LayoutTests/fast/encoding/char-decoding-mac-expected.txt
new file mode 100644
index 0000000..af236ee
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-decoding-mac-expected.txt
@@ -0,0 +1,19 @@
+This tests decoding characters in various character sets.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS decode('mac', '%C3') is 'U+221A'
+PASS decode('macintosh', '%C3') is 'U+221A'
+PASS decode('MacRoman', '%C3') is 'U+221A'
+PASS decode('x-mac-greek', '%B0') is 'U+0391'
+PASS decode('x-mac-ukrainian', '%80') is 'U+0410'
+PASS decode('x-mac-cyrillic', '%80') is 'U+0410'
+PASS decode('mac-cyrillic', '%80') is 'U+0410'
+PASS decode('x-mac-centraleurroman', '%81') is 'U+0100'
+PASS decode('x-mac-ce', '%81') is 'U+0100'
+PASS decode('x-mac-turkish', '%81') is 'U+00C5'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/encoding/char-decoding-mac.html b/LayoutTests/fast/encoding/char-decoding-mac.html
new file mode 100644
index 0000000..e574e45
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-decoding-mac.html
@@ -0,0 +1,31 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="resources/char-decoding-utils.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("This tests decoding characters in various character sets.");
+
+// Legacy Mac encodings.
+testDecode('mac', '%C3', 'U+221A');
+testDecode('macintosh', '%C3', 'U+221A');
+testDecode('MacRoman', '%C3', 'U+221A');
+testDecode('x-mac-greek', '%B0', 'U+0391');
+testDecode('x-mac-ukrainian', '%80', 'U+0410');
+testDecode('x-mac-cyrillic', '%80', 'U+0410');
+testDecode('mac-cyrillic', '%80', 'U+0410');
+testDecode('x-mac-centraleurroman', '%81', 'U+0100');
+testDecode('x-mac-ce', '%81', 'U+0100');
+testDecode('x-mac-turkish', '%81', 'U+00C5');
+
+successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/char-decoding.html b/LayoutTests/fast/encoding/char-decoding.html
new file mode 100644
index 0000000..b913389
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-decoding.html
@@ -0,0 +1,101 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="resources/char-decoding-utils.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("This tests decoding characters in various character sets.");
+
+testDecode('UTF-8', '%E2%88%9A', 'U+221A');
+
+// <http://bugs.webkit.org/show_bug.cgi?id=17014> EUC-CN code A3A0 is mapped to U+E5E5 instead of U+3000
+testDecode('gb2312', '%A3%A0', 'U+3000');
+testDecode('gb_2312-80', '%A3%A0', 'U+3000');
+testDecode('chinese', '%A3%A0', 'U+3000');
+testDecode('gbk', '%A3%A0', 'U+3000');
+testDecode('gb18030', '%A3%A0', 'U+3000');
+testDecode('EUC-CN', '%A3%A0', 'U+3000');
+
+// Test Shift_JIS aliases.
+testDecode('Shift_JIS', '%82%d0', 'U+3072');
+testDecode('shift-jis', '%82%d0', 'U+3072');
+
+// Test that all Korean encodings of EUC-KR family are treated as windows-949.
+var korean = {
+    encodings: ['korean', 'EUC-KR', 'windows-949', 'x-windows-949', 'x-uhc',
+                'iso-ir-149', 'KS_C_5601-1987', 'KS_C_5601-1989' ],
+    encoded: ['%A2%E6', '%A1%A4', '%A1%A9', '%A1%AA', '%A1%AD', '%A2%A6',
+              '%A2%C1', '%1A',    '%1C',    '%8F%A1', '%B4%D3', '%A2%41'],
+    unicode: ['U+20AC', 'U+00B7', 'U+00AD', 'U+2015', 'U+223C', 'U+FF5E', 
+              'U+2299', 'U+001A', 'U+001C', 'U+B8EA', 'U+B2D2', 'U+C910'] 
+};
+
+batchTestDecode(korean);
+   
+// Test that ISO-8859-9 (Turkish) is upgraded to windows-1254 with Euro symbol.
+var turkish = {
+  encodings: ['iso-8859-9', 'latin5', 'windows-1254'],
+  encoded: ['%80', '%9F', '%FD'],
+  unicode: ['U+20AC', 'U+0178', 'U+0131']
+};
+
+batchTestDecode(turkish);
+
+// FIXME: Have to add tests for Euro and a few new characters added to ISO-8859-x 
+// that are NOT subsets of the corresponding Windows codepages. For instance,
+// ISO-8859-7:2003 has Euro at 0xA4 and a couple of other new characters.
+// ICU 3.8.x or later has them. Perhaps, we need to have a separate test that
+// can be enabled only with modern ICU.
+
+// Baltic encodings fine points.
+testDecode('ISO-8859-13', '%A1', 'U+201D');
+testDecode('ISO-8859-13', '%A5', 'U+201E');
+testDecode('ISO-8859-13', '%B4', 'U+201C');
+testDecode('ISO-8859-13', '%FF', 'U+2019');
+testDecode('windows-1257', '%80', 'U+20AC');
+testDecode('windows-1257', '%B4', 'U+00B4');
+testDecode('windows-1257', '%FF', 'U+02D9');
+
+// Greek encodings fine points.
+testDecode('iso-8859-7', '%A1', 'U+2018');
+testDecode('iso-8859-7', '%B5', 'U+0385');
+testDecode('iso-8859-7', '%B6', 'U+0386');
+testDecode('windows-1253', '%80', 'U+20AC');
+testDecode('windows-1253', '%A1', 'U+0385');
+testDecode('windows-1253', '%B5', 'U+00B5');
+testDecode('windows-1253', '%B6', 'U+00B6');
+
+// KOI-8 variants
+testDecode('KOI8-R', '%A4', 'U+2553');
+testDecode('KOI8-R', '%AD', 'U+255C');
+testDecode('KOI8-U', '%A4', 'U+0454');
+testDecode('KOI8-U', '%AD', 'U+0491');
+
+// Test that TIS-620 and ISO-8859-11 (Thai) are upgraded to windows-874.
+// "0xDB => U+F8C1" is a weird PUA mapping that doesn't seem to be of
+// any use, even on Windows.
+var thai = {
+  encodings: ['TIS-620', 'ISO-8859-11', 'windows-874', 'dos-874'],
+  encoded: ['%80', '%96', '%A0', '%A1', '%DB'],
+  unicode: ['U+20AC', 'U+2013', 'U+00A0', 'U+0E01', 'U+F8C1']
+};
+
+batchTestDecode(thai);
+
+// UTF-7 is expressly forbidden, so decoding it should not work correctly.
+// This attempts to decode '<' as UTF-7 (+AD4) but it ends up being decoded
+// as a '+'.
+testDecode('UTF-7', '+AD4', 'U+002B');
+testDecode('utf-7', '+AD4', 'U+002B');
+
+successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/char-encoding-expected.txt b/LayoutTests/fast/encoding/char-encoding-expected.txt
new file mode 100644
index 0000000..988f73b
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-encoding-expected.txt
@@ -0,0 +1,22 @@
+This tests encoding characters in various character sets.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS encode('UTF-8', 'U+00A0') is '%C2%A0'
+PASS encode('GBK', 'U+00A5') is '%A3%A4'
+PASS encode('gb2312', 'U+00A5') is '%A3%A4'
+PASS encode('GB_2312-80', 'U+00A5') is '%A3%A4'
+PASS encode('EUC-CN', 'U+00A5') is '%A3%A4'
+PASS encode('GBK', 'U+20AC') is '%80'
+PASS encode('gb2312', 'U+20AC') is '%80'
+PASS encode('GB_2312-80', 'U+20AC') is '%80'
+PASS encode('EUC-CN', 'U+20AC') is '%80'
+PASS encode('GBK', 'U+01F9') is '%A8%BF'
+PASS encode('GBK', 'U+1E3F') is '%A8%BC'
+PASS encode('GBK', 'U+22EF') is '%A1%AD'
+PASS encode('GBK', 'U+301C') is '%A1%AB'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/encoding/char-encoding-mac-expected.txt b/LayoutTests/fast/encoding/char-encoding-mac-expected.txt
new file mode 100644
index 0000000..7fd31ba
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-encoding-mac-expected.txt
@@ -0,0 +1,17 @@
+This tests encoding characters in various character sets.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS encode('mac', 'U+221A') is '%C3'
+PASS encode('macintosh', 'U+221A') is '%C3'
+PASS encode('MacRoman', 'U+221A') is '%C3'
+PASS encode('x-mac-greek', 'U+0391') is '%B0'
+PASS encode('x-mac-cyrillic', 'U+0410') is '%80'
+PASS encode('mac-cyrillic', 'U+0410') is '%80'
+PASS encode('x-mac-centraleurroman', 'U+0100') is '%81'
+PASS encode('x-mac-turkish', 'U+00C5') is '%81'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/encoding/char-encoding-mac.html b/LayoutTests/fast/encoding/char-encoding-mac.html
new file mode 100644
index 0000000..fd6ef24
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-encoding-mac.html
@@ -0,0 +1,42 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="../js/resources/js-test-post-function.js"></script>
+<script src="resources/char-encoding-utils.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<form id="form" method="GET" target="subframe"><input type="text" id="text" name="text"></form>
+<iframe id="subframe" name="subframe"></iframe>
+<script>
+
+
+var charsets = new Array;
+var unicodes = new Array;
+var expectedResults = new Array;
+
+var results = new Object;
+
+var i = 0;
+
+// Legacy Mac encodings.
+testEncode('mac', 'U+221A', '%C3');
+testEncode('macintosh', 'U+221A', '%C3');
+testEncode('MacRoman', 'U+221A', '%C3');
+testEncode('x-mac-greek', 'U+0391', '%B0');
+testEncode('x-mac-cyrillic', 'U+0410', '%80');
+testEncode('mac-cyrillic', 'U+0410', '%80');
+testEncode('x-mac-centraleurroman', 'U+0100', '%81');
+testEncode('x-mac-turkish', 'U+00C5', '%81');
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+runTest();
+
+successfullyParsed = true;
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/char-encoding.html b/LayoutTests/fast/encoding/char-encoding.html
new file mode 100644
index 0000000..569cd5e
--- /dev/null
+++ b/LayoutTests/fast/encoding/char-encoding.html
@@ -0,0 +1,52 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="../js/resources/js-test-post-function.js"></script>
+<script src="resources/char-encoding-utils.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<form id="form" method="GET" target="subframe"><input type="text" id="text" name="text"></form>
+<iframe id="subframe" name="subframe"></iframe>
+<script>
+
+
+var charsets = new Array;
+var unicodes = new Array;
+var expectedResults = new Array;
+
+var results = new Object;
+
+var i = 0;
+
+testEncode("UTF-8", "U+00A0", "%C2%A0");
+//Yen symbol in gbk
+testEncode('GBK', 'U+00A5', '%A3%A4');
+testEncode('gb2312', 'U+00A5', '%A3%A4');
+testEncode('GB_2312-80', 'U+00A5', '%A3%A4');
+testEncode('EUC-CN', 'U+00A5', '%A3%A4');
+//Euro symbol in gbk
+testEncode('GBK', 'U+20AC', '%80');
+testEncode('gb2312', 'U+20AC', '%80');
+testEncode('GB_2312-80', 'U+20AC', '%80');
+testEncode('EUC-CN', 'U+20AC', '%80');
+//Misc symbols from TEC specific GBK translation 
+testEncode('GBK', 'U+01F9', '%A8%BF');
+testEncode('GBK', 'U+1E3F', '%A8%BC');
+testEncode('GBK', 'U+22EF', '%A1%AD');
+testEncode('GBK', 'U+301C', '%A1%AB');
+
+// Turning on this test causes a download to occur. FIXME: A bug?
+// testEncode('UTF-8', 'U+221A', '%E2%88%9A');
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+runTest();
+
+successfullyParsed = true;
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/charset-cp1251-expected.txt b/LayoutTests/fast/encoding/charset-cp1251-expected.txt
new file mode 100644
index 0000000..d181b90
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-cp1251-expected.txt
@@ -0,0 +1 @@
+Как видно, приём?
diff --git a/LayoutTests/fast/encoding/charset-cp1251.html b/LayoutTests/fast/encoding/charset-cp1251.html
new file mode 100644
index 0000000..d387d98
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-cp1251.html
@@ -0,0 +1,13 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=cp1251">
+<title>cp1251</title>
+</head>
+<body>
+<script>
+if (window.layoutTestController)
+	layoutTestController.dumpAsText();
+</script>
+Êàê âèäíî, ïðè¸ì?
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/charset-invalid-expected.txt b/LayoutTests/fast/encoding/charset-invalid-expected.txt
new file mode 100644
index 0000000..7fcd112
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-invalid-expected.txt
@@ -0,0 +1,3 @@
+Should be your browser default encoding: ISO-8859-1
+
+If it's latin-1 (ISO-8859-1), this should be accented e: é
diff --git a/LayoutTests/fast/encoding/charset-invalid.html b/LayoutTests/fast/encoding/charset-invalid.html
new file mode 100644
index 0000000..ae81286
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-invalid.html
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=invalid-encoding">
+<title>Invalid encoding</title>
+</head>
+<body>
+<script>
+if (window.layoutTestController)
+	layoutTestController.dumpAsText();
+document.write("<p>Should be your browser default encoding: " + document.characterSet + "</p>");
+document.write("<p>If it's latin-1 (ISO-8859-1), this should be accented e: é</p>");
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/charset-koi8-u-expected.txt b/LayoutTests/fast/encoding/charset-koi8-u-expected.txt
new file mode 100644
index 0000000..3ddb6ba
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-koi8-u-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 4195 - REGRESSION: KOI8-U encoding no longer supported.
+
+The test passes if these two letters look inverted along the vertical axis: "ЭЄ"
diff --git a/LayoutTests/fast/encoding/charset-koi8-u.html b/LayoutTests/fast/encoding/charset-koi8-u.html
new file mode 100644
index 0000000..b7c78b1
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-koi8-u.html
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=KOI8-U">
+<title>KOI8-U</title>
+</head>
+<body>
+<script>
+if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+</script>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=4195"> bug 4195</a> - 
+REGRESSION: KOI8-U encoding no longer supported.</p>
+<p>The test passes if these two letters look inverted along the vertical axis: "ü´"</p>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/charset-unicode-expected.txt b/LayoutTests/fast/encoding/charset-unicode-expected.txt
new file mode 100644
index 0000000..e60439f
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-unicode-expected.txt
@@ -0,0 +1 @@
+Accented e: “é”.
diff --git a/LayoutTests/fast/encoding/charset-unicode.html b/LayoutTests/fast/encoding/charset-unicode.html
new file mode 100644
index 0000000..26b80c5
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-unicode.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
+<head>
+<meta content="text/html; charset=unicode" http-equiv="Content-Type">
+</head>
+<body>
+Accented e: “é”.
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+</body>
+<html>
diff --git a/LayoutTests/fast/encoding/charset-utf16-expected.txt b/LayoutTests/fast/encoding/charset-utf16-expected.txt
new file mode 100644
index 0000000..4da5ba0
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-utf16-expected.txt
@@ -0,0 +1 @@
+This should look like a Roman ‘B’: ‘В’.
diff --git a/LayoutTests/fast/encoding/charset-utf16.html b/LayoutTests/fast/encoding/charset-utf16.html
new file mode 100644
index 0000000..6096ed3
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-utf16.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<meta content="text/html; charset=utf-16" http-equiv="Content-Type">
+</meta>
+</head>
+<body>
+This should look like a Roman ‘B’: ‘В’.
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+</body>
+</html>
+<!-- MSIE treats utf-16 in meta as utf-8 -->
diff --git a/LayoutTests/fast/encoding/charset-xuser-defined-expected.txt b/LayoutTests/fast/encoding/charset-xuser-defined-expected.txt
new file mode 100644
index 0000000..b5ff20b
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-xuser-defined-expected.txt
@@ -0,0 +1,4 @@
+Test bugzilla bug 18270 (Interpreting x-user-defined as windows-1252 when declared in meta tag). Two lines below should be identical.
+
+€ ‚ƒ„…†‡ˆ‰Š‹Œ Ž ‘’“”•–—˜™š›œ žŸ ¡¢£¤¥¦§¨©ª«¬ ®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
+€ ‚ƒ„…†‡ˆ‰Š‹Œ Ž ‘’“”•–—˜™š›œ žŸ ¡¢£¤¥¦§¨©ª«¬ ®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
diff --git a/LayoutTests/fast/encoding/charset-xuser-defined.html b/LayoutTests/fast/encoding/charset-xuser-defined.html
new file mode 100644
index 0000000..45d7c50
--- /dev/null
+++ b/LayoutTests/fast/encoding/charset-xuser-defined.html
@@ -0,0 +1,17 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=x-user-defined">
+<title>x-user-defined (bug </title>
+</head>
+<body>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>Test <a href="http://bugs.webkit.org/show_bug.cgi?id=18270">bugzilla bug 18270</a> (Interpreting x-user-defined as windows-1252 when
+declared in meta tag). Two lines below should be identical.</p>
+
+€ ‚ƒ„…†‡ˆ‰Š‹Œ Ž  ‘’“”•–—˜™š›œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ<br />
+&#x20ac; &#x201a;&#x0192;&#x201e;&#x2026;&#x2020;&#x2021;&#x02c6;&#x2030;&#x0160;&#x2039;&#x0152; &#x017d;  &#x2018;&#x2019;&#x201c;&#x201d;&#x2022;&#x2013;&#x2014;&#x02dc;&#x2122;&#x0161;&#x203a;&#x0153; &#x017e;&#x0178;&#x00a0;&#x00a1;&#x00a2;&#x00a3;&#x00a4;&#x00a5;&#x00a6;&#x00a7;&#x00a8;&#x00a9;&#x00aa;&#x00ab;&#x00ac;&#x00ad;&#x00ae;&#x00af;&#x00b0;&#x00b1;&#x00b2;&#x00b3;&#x00b4;&#x00b5;&#x00b6;&#x00b7;&#x00b8;&#x00b9;&#x00ba;&#x00bb;&#x00bc;&#x00bd;&#x00be;&#x00bf;&#x00c0;&#x00c1;&#x00c2;&#x00c3;&#x00c4;&#x00c5;&#x00c6;&#x00c7;&#x00c8;&#x00c9;&#x00ca;&#x00cb;&#x00cc;&#x00cd;&#x00ce;&#x00cf;&#x00d0;&#x00d1;&#x00d2;&#x00d3;&#x00d4;&#x00d5;&#x00d6;&#x00d7;&#x00d8;&#x00d9;&#x00da;&#x00db;&#x00dc;&#x00dd;&#x00de;&#x00df;&#x00e0;&#x00e1;&#x00e2;&#x00e3;&#x00e4;&#x00e5;&#x00e6;&#x00e7;&#x00e8;&#x00e9;&#x00ea;&#x00eb;&#x00ec;&#x00ed;&#x00ee;&#x00ef;&#x00f0;&#x00f1;&#x00f2;&#x00f3;&#x00f4;&#x00f5;&#x00f6;&#x00f7;&#x00f8;&#x00f9;&#x00fa;&#x00fb;&#x00fc;&#x00fd;&#x00fe;&#x00ff;
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/css-cached-bom-expected.txt b/LayoutTests/fast/encoding/css-cached-bom-expected.txt
new file mode 100644
index 0000000..329ea59
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-cached-bom-expected.txt
@@ -0,0 +1,3 @@
+Test that stylesheet with BOM is correctly parsed when loaded from cache. You should see word SUCCESS below.
+
+SUCCESS
diff --git a/LayoutTests/fast/encoding/css-cached-bom.html b/LayoutTests/fast/encoding/css-cached-bom.html
new file mode 100644
index 0000000..a6e75eb
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-cached-bom.html
@@ -0,0 +1,20 @@
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+function frameLoaded() {
+    if (document.getElementById('f').contentDocument.styleSheets[0].cssRules[0].selectorText == "#success::before")
+        document.getElementById('result').innerHTML = "SUCCESS";
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+</script>
+<link rel=stylesheet href=resources/utf-16-little-endian.css>
+<!-- This halts the parsing until stylesheet has been loaded -->
+<script src=does_not_exists.js></script>
+<div>Test that stylesheet with BOM is correctly parsed when loaded from cache. You should see word SUCCESS below.</div>
+<!-- Load the stylesheet to a different frame. This will use a cached copy of the stylesheet. -->
+<iframe id=f src=resources/css-cached-bom-frame.html></iframe>
+<div id=result>FAIL</div>
+
diff --git a/LayoutTests/fast/encoding/css-charset-default-expected.txt b/LayoutTests/fast/encoding/css-charset-default-expected.txt
new file mode 100644
index 0000000..954790e
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-default-expected.txt
@@ -0,0 +1,9 @@
+Test for bug 11011: External CSS is parsed as iso-8859-1 even though the main document is utf-8.
+
+Stylesheet 1 (inherit document charset using xml-stylesheet processing instruction): SUССЕSS
+
+Stylesheet 2 (inherit document charset using link): SUССЕSS
+
+Stylesheet 3 (inherit referring stylesheet charset): SUССЕSS
+
+Stylesheet 4 (inherit referring inline stylesheet charset): SUССЕSS
diff --git a/LayoutTests/fast/encoding/css-charset-default.xhtml b/LayoutTests/fast/encoding/css-charset-default.xhtml
new file mode 100644
index 0000000..24432f2
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-default.xhtml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="iso-8859-5"?>
+<?xml-stylesheet href="css-charset-inherit-iso-8859-5.css?1" type="text/css"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <title>CSS Default charset</title>
+    <link rel="stylesheet" type="text/css" href="css-charset-inherit-iso-8859-5.css?2"/>
+    <link rel="stylesheet" type="text/css" href="css-charset-import.css"/>
+    <style type="text/css">
+        @import "css-charset-inherit-iso-8859-5.css?4";
+    </style>
+</head>
+<body onload="test()">
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=11011">bug 11011</a>:
+External CSS is parsed as iso-8859-1 even though the main document is utf-8.</p>
+
+<p id="res1">Stylesheet 1 (inherit document charset using xml-stylesheet processing instruction): </p>
+<p id="res2">Stylesheet 2 (inherit document charset using link): </p>
+<p id="res3">Stylesheet 3 (inherit referring stylesheet charset): </p>
+<p id="res4">Stylesheet 4 (inherit referring inline stylesheet charset): </p>
+
+<script type="text/javascript">
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+  try {
+    document.getElementById("res1").innerHTML += document.styleSheets[0].cssRules[0].style.content;
+
+    document.getElementById("res2").innerHTML += document.styleSheets[1].cssRules[0].style.content;
+    
+    document.getElementById("res3").innerHTML += document.styleSheets[2].cssRules[1].styleSheet.cssRules[0].style.content;
+
+    document.getElementById("res4").innerHTML += document.styleSheets[3].cssRules[0].styleSheet.cssRules[0].style.content;
+  } catch (ex) {
+    alert(ex.toString());
+  }
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/css-charset-dom-expected.txt b/LayoutTests/fast/encoding/css-charset-dom-expected.txt
new file mode 100644
index 0000000..3e68c0a
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-dom-expected.txt
@@ -0,0 +1,7 @@
+Test for bug 10676: @charset rules not accessible via DOM
+
+cssText: @charset "utf-8";
+encoding: utf-8
+Resetting encoding...
+cssText: @charset "koi8-r";
+encoding: koi8-r
diff --git a/LayoutTests/fast/encoding/css-charset-dom.html b/LayoutTests/fast/encoding/css-charset-dom.html
new file mode 100644
index 0000000..8d591ae
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-dom.html
@@ -0,0 +1,32 @@
+<html>
+<head>
+    <meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+    <link rel="stylesheet" type="text/css" href="css-charset.css" charset="windows-1251">
+    <!-- The document charset and link charset have lower priority than @charset, so they 
+         shouldn't affect anything. -->
+</head>
+<body onload="test()">
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=10676">bug 10676</a>:
+@charset rules not accessible via DOM</p>
+
+<p id="result"></p>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+  try {
+    charsetRule = document.styleSheets[0].cssRules[0];
+    document.getElementById("result").innerHTML = "cssText: " + charsetRule.cssText + "<br>encoding: " + charsetRule.encoding;
+    document.getElementById("result").innerHTML += "<br>Resetting encoding...";
+    charsetRule.encoding = "koi8-r";
+    document.getElementById("result").innerHTML += "<br>cssText: " + charsetRule.cssText + "<br>encoding: " + charsetRule.encoding;
+  } catch (ex) {
+    document.getElementById("result").textContent = ex.toString();
+  }
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/css-charset-evil-expected.txt b/LayoutTests/fast/encoding/css-charset-evil-expected.txt
new file mode 100644
index 0000000..c555330
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-evil-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 10155: CSS2: @charset is not supported
+
+CSS 2.1 says that @charset " must be written literally, but Firefox and IE allow extra spaces and single quotes.
+
+SUССЕSS
diff --git a/LayoutTests/fast/encoding/css-charset-evil.css b/LayoutTests/fast/encoding/css-charset-evil.css
new file mode 100644
index 0000000..e134cca
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-evil.css
@@ -0,0 +1,2 @@
+@charset	  'utf-8' 	;
+#dummy:before { content: "SUССЕSS"; }
diff --git a/LayoutTests/fast/encoding/css-charset-evil.html b/LayoutTests/fast/encoding/css-charset-evil.html
new file mode 100644
index 0000000..1a7bd70
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-evil.html
@@ -0,0 +1,31 @@
+<html>
+<head>
+    <meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+    <link rel="stylesheet" type="text/css" href="css-charset-evil.css">
+</head>
+<body onload="test()">
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=10155">bug 10155</a>:
+CSS2: @charset is not supported</p>
+
+<p>CSS 2.1 says that <code>@charset "</code> must be written literally, 
+but Firefox and IE allow extra spaces and single quotes.</p>
+
+<p id="result"></p>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+  try {
+    text = document.styleSheets[0].rules[0].style.getPropertyValue("content");
+    text = text.replace(/"/g, "");
+    document.getElementById("result").textContent = text;
+  } catch (ex) {
+    document.getElementById("result").textContent = ex.toString();
+  }
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/css-charset-expected.txt b/LayoutTests/fast/encoding/css-charset-expected.txt
new file mode 100644
index 0000000..a8f5078
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 10155: CSS2: @charset is not supported
+
+Test that @charset works and that indexed rule access via an IE-specific rules property does not take it into account.
+
+SUCCESS
diff --git a/LayoutTests/fast/encoding/css-charset-import.css b/LayoutTests/fast/encoding/css-charset-import.css
new file mode 100644
index 0000000..4b792b5
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-import.css
@@ -0,0 +1,2 @@
+@charset "koi8-r";
+@import "css-charset-inherit-koi-8.css";
diff --git a/LayoutTests/fast/encoding/css-charset-inherit-iso-8859-5.css b/LayoutTests/fast/encoding/css-charset-inherit-iso-8859-5.css
new file mode 100644
index 0000000..9cedea6
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-inherit-iso-8859-5.css
@@ -0,0 +1,2 @@
+/* iso-8859-5 encoding */
+#dummy:before { content: "SUÁÁµSS"; }
diff --git a/LayoutTests/fast/encoding/css-charset-inherit-koi-8.css b/LayoutTests/fast/encoding/css-charset-inherit-koi-8.css
new file mode 100644
index 0000000..3411620
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset-inherit-koi-8.css
@@ -0,0 +1,2 @@
+/* koi-8 encoding */
+#dummy:before { content: "SUóóåSS"; }
diff --git a/LayoutTests/fast/encoding/css-charset.css b/LayoutTests/fast/encoding/css-charset.css
new file mode 100644
index 0000000..675084b
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset.css
@@ -0,0 +1,2 @@
+@charset "utf-8";
+#dummy:before { content: "SUССЕSS"; }
diff --git a/LayoutTests/fast/encoding/css-charset.html b/LayoutTests/fast/encoding/css-charset.html
new file mode 100644
index 0000000..8280667
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-charset.html
@@ -0,0 +1,34 @@
+<html>
+<head>
+    <meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+    <link rel="stylesheet" type="text/css" href="css-charset.css" charset="windows-1251">
+    <!-- The document charset and link charset have lower priority than 
+         @charset, so they shouldn't affect anything. -->
+</head>
+<body onload="test()">
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=10155">bug 10155</a>:
+CSS2: @charset is not supported</p>
+<p>Test that <code>@charset</code> works and that indexed rule access via 
+an IE-specific <code>rules</code> property does not take it into account.</p>
+
+<p id="result"></p>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+  try {
+    text = document.styleSheets[0].rules[0].style.cssText;
+    if (text.match('.*SUÑÑÅSS.*'))
+      result.innerHTML = "SUCCESS";
+    else
+      result.innerHTML = "FAILURE: " + text;
+  } catch (ex) {
+    result.innerHTML = "FAILURE: " + ex;
+  }
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/css-link-charset-expected.txt b/LayoutTests/fast/encoding/css-link-charset-expected.txt
new file mode 100644
index 0000000..8fa78ad
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-link-charset-expected.txt
@@ -0,0 +1,3 @@
+Test to see if the charset property in a link works properly.
+
+SUCCESS
diff --git a/LayoutTests/fast/encoding/css-link-charset.css b/LayoutTests/fast/encoding/css-link-charset.css
new file mode 100644
index 0000000..9092f2e
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-link-charset.css
@@ -0,0 +1 @@
+#dummy:before { content: "SUССЕSS"; }
diff --git a/LayoutTests/fast/encoding/css-link-charset.html b/LayoutTests/fast/encoding/css-link-charset.html
new file mode 100644
index 0000000..033f2cf
--- /dev/null
+++ b/LayoutTests/fast/encoding/css-link-charset.html
@@ -0,0 +1,25 @@
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
+    <link rel="stylesheet" type="text/css" href="css-link-charset.css" charset="utf-8">
+</head>
+<body onload="test()">
+<p>Test to see if the charset property in a link works properly.</p>
+<p id="result"></p>
+<script>
+function test() {
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    try {
+        text = document.styleSheets[0].rules[0].style.cssText;
+        if (text.match('.*SUÑÑÅSS.*'))
+            result.innerHTML = "SUCCESS";
+        else
+            result.innerHTML = "FAILURE: " + text;
+    } catch (ex) {
+        result.innerHTML = "FAILURE: " + ex;
+    }
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/decoder-allow-null-chars-expected.txt b/LayoutTests/fast/encoding/decoder-allow-null-chars-expected.txt
new file mode 100644
index 0000000..60ce3e0
--- /dev/null
+++ b/LayoutTests/fast/encoding/decoder-allow-null-chars-expected.txt
@@ -0,0 +1,5 @@
+This tests that we no longer strip nulls from tags. This matches Firefox behavior.
+
+Test Passed
+
+result.innerHTML = message;
diff --git a/LayoutTests/fast/encoding/decoder-allow-null-chars.html b/LayoutTests/fast/encoding/decoder-allow-null-chars.html
new file mode 100644
index 0000000..e6ee249
--- /dev/null
+++ b/LayoutTests/fast/encoding/decoder-allow-null-chars.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/default-xhtml-encoding-expected.txt b/LayoutTests/fast/encoding/default-xhtml-encoding-expected.txt
new file mode 100644
index 0000000..40ea127
--- /dev/null
+++ b/LayoutTests/fast/encoding/default-xhtml-encoding-expected.txt
@@ -0,0 +1,3 @@
+Test default XHTML encoding (in the absence of an XML declaration).
+
+Charset: UTF-8 (should be UTF-8)
diff --git a/LayoutTests/fast/encoding/default-xhtml-encoding.xhtml b/LayoutTests/fast/encoding/default-xhtml-encoding.xhtml
new file mode 100644
index 0000000..ffbc92c
--- /dev/null
+++ b/LayoutTests/fast/encoding/default-xhtml-encoding.xhtml
@@ -0,0 +1,16 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body>
+<p>Test default XHTML encoding (in the absence of an XML declaration).</p>
+
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be UTF-8)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/denormalised-voiced-japanese-chars.html b/LayoutTests/fast/encoding/denormalised-voiced-japanese-chars.html
new file mode 100644
index 0000000..93791ee
--- /dev/null
+++ b/LayoutTests/fast/encoding/denormalised-voiced-japanese-chars.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+This test checks that the decomposed unicode version of voiced japanese hiragana and katakana characters are rendered the same as the precomposed version. This test is a pixel-test, and passes when the text in the two heading elements are identical.
+<h2>バナナとパナマ</h2>
+<p>The above is decomposed</p>
+
+<h2>バナナとパナマ</h2>
+<p>The above is precomposed</p>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/euckr-name-expected.txt b/LayoutTests/fast/encoding/euckr-name-expected.txt
new file mode 100644
index 0000000..5d352f8
--- /dev/null
+++ b/LayoutTests/fast/encoding/euckr-name-expected.txt
@@ -0,0 +1,6 @@
+Test for bug 25487. Even though we treat EUC-KR as windows-949, the name exposed via DOM APIs should still be EUC-KR.
+
+characterSet: EUC-KR (should be EUC-KR)
+charset: EUC-KR (should be EUC-KR)
+inputEncoding: EUC-KR (should be EUC-KR)
+
diff --git a/LayoutTests/fast/encoding/euckr-name.html b/LayoutTests/fast/encoding/euckr-name.html
new file mode 100644
index 0000000..b8d62fe
--- /dev/null
+++ b/LayoutTests/fast/encoding/euckr-name.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
+</head>
+<BODY>
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=25487">bug 25487</a>. Even though we treat EUC-KR as windows-949, the name exposed via DOM APIs should still be EUC-KR.</p>  
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var encodingElems = ["characterSet", "charset", "inputEncoding"];
+  for (var i in encodingElems) {
+    var charset = eval('document.' + encodingElems[i]);
+    document.write(encodingElems[i] +": " + charset + " (should be EUC-KR)<br>");
+  }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/external-script-charset-expected.txt b/LayoutTests/fast/encoding/external-script-charset-expected.txt
new file mode 100644
index 0000000..6575759
--- /dev/null
+++ b/LayoutTests/fast/encoding/external-script-charset-expected.txt
@@ -0,0 +1,3 @@
+Test that external scripts in XHTML documents inherit document charset.
+
+PASS
diff --git a/LayoutTests/fast/encoding/external-script-charset.js b/LayoutTests/fast/encoding/external-script-charset.js
new file mode 100644
index 0000000..841824d
--- /dev/null
+++ b/LayoutTests/fast/encoding/external-script-charset.js
@@ -0,0 +1,4 @@
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = ("Я" == "\u042F") ? "PASS" : "FAIL";
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/external-script-charset.xhtml b/LayoutTests/fast/encoding/external-script-charset.xhtml
new file mode 100644
index 0000000..d89b9d6
--- /dev/null
+++ b/LayoutTests/fast/encoding/external-script-charset.xhtml
@@ -0,0 +1,7 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" dir="ltr">
+<body>
+    <p>Test that external scripts in XHTML documents inherit document charset.</p>
+    <div id="result"></div>
+    <script type="text/javascript" src="external-script-charset.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/floraexpress-ru-expected.txt b/LayoutTests/fast/encoding/floraexpress-ru-expected.txt
new file mode 100644
index 0000000..5ba4587
--- /dev/null
+++ b/LayoutTests/fast/encoding/floraexpress-ru-expected.txt
@@ -0,0 +1,3 @@
+Test a particular example of broken markup that was making us ignore a charset declaration.
+
+Encoding: windows-1251 (should be windows-1251)
diff --git a/LayoutTests/fast/encoding/floraexpress-ru.html b/LayoutTests/fast/encoding/floraexpress-ru.html
new file mode 100644
index 0000000..8004ef7
--- /dev/null
+++ b/LayoutTests/fast/encoding/floraexpress-ru.html
@@ -0,0 +1,26 @@
+<input type=hidden name=test value=''><input type=hidden name=test1 value=''><input type=hidden name=test value=''><input type=hidden name=test1 value=''>
+<html>
+<head>
+<title>Floraexpress - çàêàç è äîñòàâêà öâåòîâ ïî Ìèðó, ìåæäóíàðîäíàÿ äîñòàâêà öâåòîâ, çàêàç è äîñòàâêà áóêåòîâ</title>
+<title>Çàêàç öâåòîâ è äîñòàâêà áóêåòîâ öâåòîâ ïî âñåìó ìèðó - Floraexpress - ìåæäóíàðîäíàÿ äîñòàâêà öâåòîâ</title>
+
+<meta http-equiv=Content-Type content="text/html; charset=windows-1251">
+</head>
+<body bgcolor=#F5F5EF text="#313131" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
+</head>
+<body>
+
+<p>Test a particular example of broken markup that was making us ignore a charset declaration.</p>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var charset = document.characterSet;
+  if (!charset)
+    charset = document.charset;
+  if (!charset)
+    charset = document.inputEncoding;
+  document.write("Encoding: " + charset + " (should be windows-1251)");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/frame-default-enc-expected.txt b/LayoutTests/fast/encoding/frame-default-enc-expected.txt
new file mode 100644
index 0000000..7ef22e9
--- /dev/null
+++ b/LayoutTests/fast/encoding/frame-default-enc-expected.txt
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/encoding/frame-default-enc.html b/LayoutTests/fast/encoding/frame-default-enc.html
new file mode 100644
index 0000000..6ccf45b
--- /dev/null
+++ b/LayoutTests/fast/encoding/frame-default-enc.html
@@ -0,0 +1,27 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=x-mac-cyrillic">
+<title>Frames and encodings</title>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+window.done = function(charset) {
+    document.open();
+    document.write("<p>" + ((charset == "x-mac-cyrillic") ? "PASS" : "FAIL") + "</p>");
+    <!-- It's unlikely that anyone has x-mac-cyrillic as default -->
+
+    document.close();
+
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+</script>
+</head>
+<frameset rows="0,*">
+    <frame src="about:" scrolling=no marginwidth=0 marginheight=0>
+    <frame src="resources/frame-default-enc-frame.html">
+</frameset>
+</html>
diff --git a/LayoutTests/fast/encoding/hanarei-blog32-fc2-com-expected.txt b/LayoutTests/fast/encoding/hanarei-blog32-fc2-com-expected.txt
new file mode 100644
index 0000000..22fd61b
--- /dev/null
+++ b/LayoutTests/fast/encoding/hanarei-blog32-fc2-com-expected.txt
@@ -0,0 +1,3 @@
+Test a particular example of broken markup that was making us ignore a charset declaration.
+
+Encoding: EUC-JP (should be EUC-JP)
diff --git a/LayoutTests/fast/encoding/hanarei-blog32-fc2-com.html b/LayoutTests/fast/encoding/hanarei-blog32-fc2-com.html
new file mode 100644
index 0000000..a468237
--- /dev/null
+++ b/LayoutTests/fast/encoding/hanarei-blog32-fc2-com.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html lang="ja" dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
+<head>
+
+
+
+<HTML>
+<HEAD>
+<TITLE>̵ÎÁ¥ª¥ó¥é¥¤¥ó¥²¡¼¥à¤Ë»²²Ã¤·¤è¤¦¢ö</TITLE>
+</HEAD>
+
+<BODY>
+<script type="text/javascript"><!--
+var ID="100099131";
+var AD=1;
+var FRAME=0;
+// --></script>
+<script src="about:blank" type="text/javascript"></script>
+<noscript>
+<a href="http://w1.ax.xrea.com/c.f?id=100099131" target="_blank"><img src="about:blank" alt="AX" border="0"></a>
+</noscript>
+
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
+</head>
+<body>
+
+<p>Test a particular example of broken markup that was making us ignore a charset declaration.</p>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var charset = document.characterSet;
+  if (!charset)
+    charset = document.charset;
+  if (!charset)
+    charset = document.inputEncoding;
+  document.write("Encoding: " + charset + " (should be EUC-JP)");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8-e-expected.txt b/LayoutTests/fast/encoding/hebrew/8859-8-e-expected.txt
new file mode 100644
index 0000000..1503d86
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8-e-expected.txt
@@ -0,0 +1,3 @@
+ןוכנ הז
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8-e.html b/LayoutTests/fast/encoding/hebrew/8859-8-e.html
new file mode 100644
index 0000000..9314c39
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8-e.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=iso-8859-8-E" /><body><p id=p>
+ïåëð äæ</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "visual") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8-expected.txt b/LayoutTests/fast/encoding/hebrew/8859-8-expected.txt
new file mode 100644
index 0000000..1503d86
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8-expected.txt
@@ -0,0 +1,3 @@
+ןוכנ הז
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8-i-expected.txt b/LayoutTests/fast/encoding/hebrew/8859-8-i-expected.txt
new file mode 100644
index 0000000..899cd05
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8-i-expected.txt
@@ -0,0 +1,3 @@
+זה נכון
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8-i.html b/LayoutTests/fast/encoding/hebrew/8859-8-i.html
new file mode 100644
index 0000000..ca85599
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8-i.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=iso-8859-8-i" /><body><p id=p>
+æä ðëåï</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "logical") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/8859-8.html b/LayoutTests/fast/encoding/hebrew/8859-8.html
new file mode 100644
index 0000000..c96323c
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/8859-8.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=iso-8859-8" /><body><p id=p>
+ïåëð äæ</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "visual") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/csISO88598I-expected.txt b/LayoutTests/fast/encoding/hebrew/csISO88598I-expected.txt
new file mode 100644
index 0000000..899cd05
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/csISO88598I-expected.txt
@@ -0,0 +1,3 @@
+זה נכון
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/csISO88598I.html b/LayoutTests/fast/encoding/hebrew/csISO88598I.html
new file mode 100644
index 0000000..2c138d6
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/csISO88598I.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=csISO88598I" /><body><p id=p>
+æä ðëåï</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "logical") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/hebrew-expected.txt b/LayoutTests/fast/encoding/hebrew/hebrew-expected.txt
new file mode 100644
index 0000000..1503d86
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/hebrew-expected.txt
@@ -0,0 +1,3 @@
+ןוכנ הז
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/hebrew.html b/LayoutTests/fast/encoding/hebrew/hebrew.html
new file mode 100644
index 0000000..c96323c
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/hebrew.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=iso-8859-8" /><body><p id=p>
+ïåëð äæ</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "visual") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/iso-ir-138-expected.txt b/LayoutTests/fast/encoding/hebrew/iso-ir-138-expected.txt
new file mode 100644
index 0000000..1503d86
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/iso-ir-138-expected.txt
@@ -0,0 +1,3 @@
+ןוכנ הז
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/iso-ir-138.html b/LayoutTests/fast/encoding/hebrew/iso-ir-138.html
new file mode 100644
index 0000000..fd4bb0b
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/iso-ir-138.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=iso-ir-138" /><body><p id=p>
+ïåëð äæ</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "visual") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/hebrew/logical-expected.txt b/LayoutTests/fast/encoding/hebrew/logical-expected.txt
new file mode 100644
index 0000000..899cd05
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/logical-expected.txt
@@ -0,0 +1,3 @@
+זה נכון
+
+PASS
diff --git a/LayoutTests/fast/encoding/hebrew/logical.html b/LayoutTests/fast/encoding/hebrew/logical.html
new file mode 100644
index 0000000..8929576
--- /dev/null
+++ b/LayoutTests/fast/encoding/hebrew/logical.html
@@ -0,0 +1,3 @@
+<meta http-equiv="content-Type" content="text/html; charset=logical" /><body><p id=p>
+æä ðëåï</p><script>if (window.layoutTestController) layoutTestController.dumpAsText();
+document.write((document.defaultView.getComputedStyle(document.getElementById("p"), null).getPropertyValue("-webkit-rtl-ordering") == "logical") ? "PASS" : "FAIL")</script></body>
\ No newline at end of file
diff --git a/LayoutTests/fast/encoding/high-bit-latin1-expected.txt b/LayoutTests/fast/encoding/high-bit-latin1-expected.txt
new file mode 100644
index 0000000..250d65d
--- /dev/null
+++ b/LayoutTests/fast/encoding/high-bit-latin1-expected.txt
@@ -0,0 +1,3 @@
+Test Latin-1 conversion to String
+
+PASS
diff --git a/LayoutTests/fast/encoding/high-bit-latin1.html b/LayoutTests/fast/encoding/high-bit-latin1.html
new file mode 100644
index 0000000..ba8e6d6
--- /dev/null
+++ b/LayoutTests/fast/encoding/high-bit-latin1.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+    <title></title>
+</head>
+<body>
+    <p>
+        Test Latin-1 conversion to String
+    </p>
+    <a id="t" à></a>
+    <p>
+    <script type="text/javascript">
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+        document.write(document.getElementById("t").attributes[1].name == "\u00e0" ? "PASS" : "FAIL");
+    </script>
+    </p>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/idn-security-expected.txt b/LayoutTests/fast/encoding/idn-security-expected.txt
new file mode 100644
index 0000000..23a6f97
--- /dev/null
+++ b/LayoutTests/fast/encoding/idn-security-expected.txt
@@ -0,0 +1,247 @@
+PASS testIDNRoundTrip(0x2e) is '.'
+PASS testIDNRoundTripNotFirstCharacter(0x2e) is '.'
+PASS testIDNRoundTrip(0x2f) is '/'
+PASS testIDNRoundTripNotFirstCharacter(0x2f) is '/'
+PASS testIDNRoundTrip(0x61) is 'a'
+PASS testIDNRoundTripNotFirstCharacter(0x61) is 'a'
+PASS testIDNRoundTrip(0x633) is '%u0633'
+PASS testIDNRoundTripNotFirstCharacter(0x633) is '%u0633'
+PASS testIDNRoundTrip(0x561) is '%u0561'
+PASS testIDNRoundTripNotFirstCharacter(0x561) is '%u0561'
+PASS testIDNRoundTrip(0x3105) is '%u3105'
+PASS testIDNRoundTripNotFirstCharacter(0x3105) is '%u3105'
+PASS testIDNRoundTrip(0x1613) is '%u1613'
+PASS testIDNRoundTripNotFirstCharacter(0x1613) is '%u1613'
+PASS testIDNRoundTrip(0x905) is '%u0905'
+PASS testIDNRoundTripNotFirstCharacter(0x905) is '%u0905'
+PASS testIDNRoundTrip(0xa85) is '%u0A85'
+PASS testIDNRoundTripNotFirstCharacter(0xa85) is '%u0A85'
+PASS testIDNRoundTrip(0xa05) is '%u0A05'
+PASS testIDNRoundTripNotFirstCharacter(0xa05) is '%u0A05'
+PASS testIDNRoundTrip(0x1115) is '%u1115'
+PASS testIDNRoundTripNotFirstCharacter(0x1115) is '%u1115'
+PASS testIDNRoundTrip(0x4e2d) is '%u4E2D'
+PASS testIDNRoundTripNotFirstCharacter(0x4e2d) is '%u4E2D'
+PASS testIDNRoundTrip(0x5d0) is '%u05D0'
+PASS testIDNRoundTripNotFirstCharacter(0x5d0) is '%u05D0'
+PASS testIDNRoundTrip(0x3041) is '%u3041'
+PASS testIDNRoundTripNotFirstCharacter(0x3041) is '%u3041'
+PASS testIDNRoundTrip(0x30a1) is '%u30A1'
+PASS testIDNRoundTripNotFirstCharacter(0x30a1) is '%u30A1'
+PASS testIDNRoundTrip(0xb94) is '%u0B94'
+PASS testIDNRoundTripNotFirstCharacter(0xb94) is '%u0B94'
+PASS testIDNRoundTrip(0xe01) is '%u0E01'
+PASS testIDNRoundTripNotFirstCharacter(0xe01) is '%u0E01'
+PASS testIDNRoundTrip(0xa000) is '%uA000'
+PASS testIDNRoundTripNotFirstCharacter(0xa000) is '%uA000'
+PASS testIDNRoundTrip(0x2024) is '.'
+PASS testIDNRoundTripNotFirstCharacter(0x2024) is '.'
+PASS testIDNRoundTrip(0xfe52) is '.'
+PASS testIDNRoundTripNotFirstCharacter(0xfe52) is '.'
+PASS testIDNRoundTrip(0xff0f) is '/'
+PASS testIDNRoundTripNotFirstCharacter(0xff0f) is '/'
+PASS testIDNRoundTrip(0xfe68) is '%5C'
+PASS testIDNRoundTripNotFirstCharacter(0xfe68) is '%5C'
+PASS testIDNRoundTrip(0xff3c) is '%5C'
+PASS testIDNRoundTripNotFirstCharacter(0xff3c) is '%5C'
+PASS testIDNRoundTrip(0xa0) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0xa0) is '%20'
+PASS testIDNRoundTrip(0x2000) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2000) is '%20'
+PASS testIDNRoundTrip(0x2001) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2001) is '%20'
+PASS testIDNRoundTrip(0x2002) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2002) is '%20'
+PASS testIDNRoundTrip(0x2003) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2003) is '%20'
+PASS testIDNRoundTrip(0x2004) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2004) is '%20'
+PASS testIDNRoundTrip(0x2005) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2005) is '%20'
+PASS testIDNRoundTrip(0x2006) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2006) is '%20'
+PASS testIDNRoundTrip(0x2007) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2007) is '%20'
+PASS testIDNRoundTrip(0x2008) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2008) is '%20'
+PASS testIDNRoundTrip(0x2009) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x2009) is '%20'
+PASS testIDNRoundTrip(0x200a) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x200a) is '%20'
+PASS testIDNRoundTrip(0x202f) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x202f) is '%20'
+PASS testIDNRoundTrip(0x205f) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x205f) is '%20'
+PASS testIDNRoundTrip(0x3000) is '%20'
+PASS testIDNRoundTripNotFirstCharacter(0x3000) is '%20'
+PASS testIDNRoundTrip(0xbc) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xbc) is 'punycode'
+PASS testIDNRoundTrip(0xbd) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xbd) is 'punycode'
+PASS testIDNRoundTrip(0xed) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xed) is 'punycode'
+PASS testIDNRoundTrip(0x1c3) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x1c3) is 'punycode'
+PASS testIDNRoundTrip(0x251) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x251) is 'punycode'
+PASS testIDNRoundTrip(0x261) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x261) is 'punycode'
+PASS testIDNRoundTrip(0x337) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x337) is 'punycode'
+PASS testIDNRoundTrip(0x337) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x337) is 'punycode'
+PASS testIDNRoundTrip(0x338) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x338) is 'punycode'
+PASS testIDNRoundTrip(0x338) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x338) is 'punycode'
+PASS testIDNRoundTrip(0x5b4) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x5b4) is 'punycode'
+PASS testIDNRoundTrip(0x5bc) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x5bc) is 'punycode'
+PASS testIDNRoundTrip(0x660) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x660) is 'punycode'
+PASS testIDNRoundTrip(0x6f0) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x6f0) is 'punycode'
+PASS testIDNRoundTrip(0x115f) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x115f) is 'punycode'
+PASS testIDNRoundTrip(0x1160) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x1160) is 'punycode'
+PASS testIDNRoundTrip(0x2027) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2027) is 'punycode'
+PASS testIDNRoundTrip(0x2039) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2039) is 'punycode'
+PASS testIDNRoundTrip(0x203a) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x203a) is 'punycode'
+PASS testIDNRoundTrip(0x2044) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2044) is 'punycode'
+PASS testIDNRoundTrip(0x2044) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2044) is 'punycode'
+PASS testIDNRoundTrip(0x2154) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2154) is 'punycode'
+PASS testIDNRoundTrip(0x2155) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2155) is 'punycode'
+PASS testIDNRoundTrip(0x2156) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2156) is 'punycode'
+PASS testIDNRoundTrip(0x2159) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2159) is 'punycode'
+PASS testIDNRoundTrip(0x215a) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x215a) is 'punycode'
+PASS testIDNRoundTrip(0x215b) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x215b) is 'punycode'
+PASS testIDNRoundTrip(0x215f) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x215f) is 'punycode'
+PASS testIDNRoundTrip(0x2215) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2215) is 'punycode'
+PASS testIDNRoundTrip(0x2216) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2216) is 'punycode'
+PASS testIDNRoundTrip(0x233f) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x233f) is 'punycode'
+PASS testIDNRoundTrip(0x23ae) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x23ae) is 'punycode'
+PASS testIDNRoundTrip(0x244a) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x244a) is 'punycode'
+PASS testIDNRoundTrip(0x2571) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2571) is 'punycode'
+PASS testIDNRoundTrip(0x2572) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2572) is 'punycode'
+PASS testIDNRoundTrip(0x29f6) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x29f6) is 'punycode'
+PASS testIDNRoundTrip(0x29f8) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x29f8) is 'punycode'
+PASS testIDNRoundTrip(0x29f8) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x29f8) is 'punycode'
+PASS testIDNRoundTrip(0x2afb) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2afb) is 'punycode'
+PASS testIDNRoundTrip(0x2afd) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x2afd) is 'punycode'
+PASS testIDNRoundTrip(0x3014) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x3014) is 'punycode'
+PASS testIDNRoundTrip(0x3015) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x3015) is 'punycode'
+PASS testIDNRoundTrip(0x3033) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x3033) is 'punycode'
+PASS testIDNRoundTrip(0x3035) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x3035) is 'punycode'
+PASS testIDNRoundTrip(0x3164) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x3164) is 'punycode'
+PASS testIDNRoundTrip(0x321d) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x321d) is 'punycode'
+PASS testIDNRoundTrip(0x321e) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x321e) is 'punycode'
+PASS testIDNRoundTrip(0x33ae) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x33ae) is 'punycode'
+PASS testIDNRoundTrip(0x33af) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x33af) is 'punycode'
+PASS testIDNRoundTrip(0x33c6) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x33c6) is 'punycode'
+PASS testIDNRoundTrip(0x33df) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0x33df) is 'punycode'
+PASS testIDNRoundTrip(0xfe14) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xfe14) is 'punycode'
+PASS testIDNRoundTrip(0xfe15) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xfe15) is 'punycode'
+PASS testIDNRoundTrip(0xfe3f) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xfe3f) is 'punycode'
+PASS testIDNRoundTrip(0xfe5d) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xfe5d) is 'punycode'
+PASS testIDNRoundTrip(0xfe5e) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xfe5e) is 'punycode'
+PASS testIDNRoundTrip(0xffa0) is 'punycode'
+PASS testIDNRoundTripNotFirstCharacter(0xffa0) is 'punycode'
+PASS testIDNEncode(0x2028) is '%u2028'
+PASS testIDNEncodeNotFirstCharacter(0x2028) is '%u2028'
+PASS testIDNEncode(0x2029) is '%u2029'
+PASS testIDNEncodeNotFirstCharacter(0x2029) is '%u2029'
+PASS testIDNEncode(0x2ff0) is '%u2FF0'
+PASS testIDNEncodeNotFirstCharacter(0x2ff0) is '%u2FF0'
+PASS testIDNEncode(0x2ff1) is '%u2FF1'
+PASS testIDNEncodeNotFirstCharacter(0x2ff1) is '%u2FF1'
+PASS testIDNEncode(0x2ff2) is '%u2FF2'
+PASS testIDNEncodeNotFirstCharacter(0x2ff2) is '%u2FF2'
+PASS testIDNEncode(0x2ff3) is '%u2FF3'
+PASS testIDNEncodeNotFirstCharacter(0x2ff3) is '%u2FF3'
+PASS testIDNEncode(0x2ff4) is '%u2FF4'
+PASS testIDNEncodeNotFirstCharacter(0x2ff4) is '%u2FF4'
+PASS testIDNEncode(0x2ff5) is '%u2FF5'
+PASS testIDNEncodeNotFirstCharacter(0x2ff5) is '%u2FF5'
+PASS testIDNEncode(0x2ff6) is '%u2FF6'
+PASS testIDNEncodeNotFirstCharacter(0x2ff6) is '%u2FF6'
+PASS testIDNEncode(0x2ff7) is '%u2FF7'
+PASS testIDNEncodeNotFirstCharacter(0x2ff7) is '%u2FF7'
+PASS testIDNEncode(0x2ff8) is '%u2FF8'
+PASS testIDNEncodeNotFirstCharacter(0x2ff8) is '%u2FF8'
+PASS testIDNEncode(0x2ff9) is '%u2FF9'
+PASS testIDNEncodeNotFirstCharacter(0x2ff9) is '%u2FF9'
+PASS testIDNEncode(0x2ffa) is '%u2FFA'
+PASS testIDNEncodeNotFirstCharacter(0x2ffa) is '%u2FFA'
+PASS testIDNEncode(0x2ffb) is '%u2FFB'
+PASS testIDNEncodeNotFirstCharacter(0x2ffb) is '%u2FFB'
+PASS testIDNEncode(0xfff9) is '%uFFF9'
+PASS testIDNEncodeNotFirstCharacter(0xfff9) is '%uFFF9'
+PASS testIDNEncode(0xfffa) is '%uFFFA'
+PASS testIDNEncodeNotFirstCharacter(0xfffa) is '%uFFFA'
+PASS testIDNEncode(0xfffb) is '%uFFFB'
+PASS testIDNEncodeNotFirstCharacter(0xfffb) is '%uFFFB'
+PASS testIDNEncode(0xfffc) is '%uFFFC'
+PASS testIDNEncodeNotFirstCharacter(0xfffc) is '%uFFFC'
+PASS testIDNEncode(0xfffd) is '%uFFFD'
+PASS testIDNEncodeNotFirstCharacter(0xfffd) is '%uFFFD'
+PASS testIDNRoundTrip(0x5c3) is 'punycode'
+PASS testIDNEncodeNotFirstCharacter(0x5c3) is '%u05C3'
+PASS testIDNRoundTrip(0x5f4) is 'punycode'
+PASS testIDNEncodeNotFirstCharacter(0x5f4) is '%u05F4'
+PASS testIDNRoundTrip(0x6d4) is 'punycode'
+PASS testIDNEncodeNotFirstCharacter(0x6d4) is '%u06D4'
+PASS testIDNRoundTrip(0x702) is 'punycode'
+PASS testIDNEncodeNotFirstCharacter(0x702) is '%u0702'
+PASS testIDNEncode(0x200b) is '%u200B'
+PASS testIDNRoundTripNotFirstCharacter(0x200b) is ''
+PASS testIDNEncode(0x3002) is '%u3002'
+PASS testIDNRoundTripNotFirstCharacter(0x3002) is '.'
+PASS testIDNEncode(0xff0e) is '%uFF0E'
+PASS testIDNRoundTripNotFirstCharacter(0xff0e) is '.'
+PASS testIDNEncode(0xff61) is '%uFF61'
+PASS testIDNRoundTripNotFirstCharacter(0xff61) is '.'
+PASS testIDNEncode(0xfeff) is '%uFEFF'
+PASS testIDNRoundTripNotFirstCharacter(0xfeff) is ''
+
diff --git a/LayoutTests/fast/encoding/idn-security.html b/LayoutTests/fast/encoding/idn-security.html
new file mode 100644
index 0000000..12edaf7
--- /dev/null
+++ b/LayoutTests/fast/encoding/idn-security.html
@@ -0,0 +1,276 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+function testIDNEncode(charCode)
+{
+    var str = String.fromCharCode(charCode);
+    str = layoutTestController.encodeHostName(str);
+    if (str.substr(0, 4) == "xn--")
+        return "punycode";
+    return escape(str);
+}
+
+function testIDNEncodeNotFirstCharacter(charCode)
+{
+    var str = String.fromCharCode(charCode);
+    str = "a" + str;
+    str = layoutTestController.encodeHostName(str);
+    if (str.substr(0, 4) == "xn--")
+        return "punycode";
+    if (str.substr(0, 1) == "a")
+        str = str.substr(1, str.length - 1);
+    return escape(str);
+}
+
+function testIDNRoundTrip(charCode)
+{
+    var str = String.fromCharCode(charCode);
+    str = layoutTestController.encodeHostName(str);
+    str = layoutTestController.decodeHostName(str);
+    if (str.substr(0, 4) == "xn--")
+        return "punycode";
+    return escape(str);
+}
+
+function testIDNRoundTripNotFirstCharacter(charCode)
+{
+    var str = String.fromCharCode(charCode);
+    str = "a" + str;
+    str = layoutTestController.encodeHostName(str);
+    str = layoutTestController.decodeHostName(str);
+    if (str.substr(0, 4) == "xn--")
+        return "punycode";
+    if (str.substr(0, 1) == "a")
+        str = str.substr(1, str.length - 1);
+    return escape(str);
+}
+
+function testFunctionName(expected)
+{
+    if (expected == "does not encode")
+        return "testIDNEncode";
+    return "testIDNRoundTrip";
+}
+
+function expectedTestResult(charCode, expected)
+{
+    if (expected == "disallowed")
+        return "'punycode'";
+    if (expected == "allowed" || expected == "does not encode")
+        return "'" + escape(String.fromCharCode(charCode)) + "'";
+    return "'" + expected + "'";
+}
+
+function testIDNCharacter(charCode, expected, expectedNotFirstCharacter)
+{
+    if (expectedNotFirstCharacter == null)
+        expectedNotFirstCharacter = expected;
+
+    shouldBe(testFunctionName(expected) + "(0x" + charCode.toString(16) + ")",
+        expectedTestResult(charCode, expected));
+
+    shouldBe(testFunctionName(expectedNotFirstCharacter) + "NotFirstCharacter(0x" + charCode.toString(16) + ")",
+        expectedTestResult(charCode, expectedNotFirstCharacter));    
+}
+
+function testBecomesSpaceIDNCharacter(charCode)
+{
+    shouldBe("testIDNRoundTrip(0x" + charCode.toString(16) + ")", "'%20'");
+    shouldBe("testIDNRoundTripFirstCharacter(0x" + charCode.toString(16) + ")", "'%20'");
+}
+
+function testBecomesASCIIIDNCharacter(charCode, expected)
+{
+    shouldBe("testIDNRoundTrip(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+    shouldBe("testIDNRoundTripFirstCharacter(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+}
+
+function testDisallowedIDNCharacter(charCode)
+{
+    shouldBe("testIDNRoundTrip(0x" + charCode.toString(16) + ")", "'punycode'");
+    shouldBe("testIDNRoundTripFirstCharacter(0x" + charCode.toString(16) + ")", "'punycode'");
+}
+
+function testAllowedIDNCharacter(charCode)
+{
+    var expected = escape(String.fromCharCode(charCode));
+    shouldBe("testIDNRoundTrip(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+    shouldBe("testIDNRoundTripFirstCharacter(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+}
+
+function testDoesNotEncodeIDNCharacter(charCode)
+{
+    var expected = escape(String.fromCharCode(charCode));
+    shouldBe("testIDNEncode(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+    shouldBe("testIDNEncodeTripFirstCharacter(0x" + charCode.toString(16) + ")", "'" + expected + "'");
+}
+
+var isOlderICU = testIDNEncode(0x3002) == ".";
+
+/* Allowed Characters - dot and slash */
+testIDNCharacter(".".charCodeAt(0), "allowed");
+testIDNCharacter("/".charCodeAt(0), "allowed");
+
+/* Allowed Characters - one character for each script in the default IDN whitelist*/
+testIDNCharacter(0x0061, "allowed");
+testIDNCharacter(0x0633, "allowed");
+testIDNCharacter(0x0561, "allowed");
+testIDNCharacter(0x3105, "allowed");
+testIDNCharacter(0x1613, "allowed");
+testIDNCharacter(0x0905, "allowed");
+testIDNCharacter(0x0A85, "allowed");
+testIDNCharacter(0x0A05, "allowed");
+testIDNCharacter(0x1115, "allowed");
+testIDNCharacter(0x4E2D, "allowed");
+testIDNCharacter(0x05D0, "allowed");
+testIDNCharacter(0x3041, "allowed");
+testIDNCharacter(0x30A1, "allowed");
+testIDNCharacter(0x0B94, "allowed");
+testIDNCharacter(0x0E01, "allowed");
+testIDNCharacter(0xA000, "allowed");
+
+/* ICU converts these to other allowed characters, so the original character can't be used to get to a phishy domain name */
+testIDNCharacter(0x2024, ".");
+testIDNCharacter(0xFE52, ".");
+testIDNCharacter(0xFF0F, "/");
+
+/* ICU converts these characters to backslash, so the original character can't be used to get to a phishy domain name */
+testIDNCharacter(0xFE68, "%5C");
+testIDNCharacter(0xFF3C, "%5C");
+
+/* ICU converts these characters to space, so the original character can't be used to get to a phishy domain name */
+testIDNCharacter(0x00A0, "%20");
+testIDNCharacter(0x2000, "%20");
+testIDNCharacter(0x2001, "%20");
+testIDNCharacter(0x2002, "%20");
+testIDNCharacter(0x2003, "%20");
+testIDNCharacter(0x2004, "%20");
+testIDNCharacter(0x2005, "%20");
+testIDNCharacter(0x2006, "%20");
+testIDNCharacter(0x2007, "%20");
+testIDNCharacter(0x2008, "%20");
+testIDNCharacter(0x2009, "%20");
+testIDNCharacter(0x200A, "%20");
+testIDNCharacter(0x202F, "%20");
+testIDNCharacter(0x205F, "%20");
+testIDNCharacter(0x3000, "%20");
+
+/* Disallow these characters.  Some of these are known lookalike characters for dot and slash.  
+   A lot of these are from Mozilla's blacklist: http://kb.mozillazine.org/Network.IDN.blacklist_chars
+*/
+testIDNCharacter(0x00BC, "disallowed");
+testIDNCharacter(0x00BD, "disallowed");
+testIDNCharacter(0x00ED, "disallowed");
+testIDNCharacter(0x01C3, "disallowed");
+testIDNCharacter(0x0251, "disallowed");
+testIDNCharacter(0x0261, "disallowed");
+testIDNCharacter(0x0337, "disallowed");
+testIDNCharacter(0x0337, "disallowed");
+testIDNCharacter(0x0338, "disallowed");
+testIDNCharacter(0x0338, "disallowed");
+testIDNCharacter(0x05B4, "disallowed");
+testIDNCharacter(0x05BC, "disallowed");
+testIDNCharacter(0x0660, "disallowed");
+testIDNCharacter(0x06F0, "disallowed");
+testIDNCharacter(0x115F, "disallowed");
+testIDNCharacter(0x1160, "disallowed");
+testIDNCharacter(0x2027, "disallowed");
+testIDNCharacter(0x2039, "disallowed");
+testIDNCharacter(0x203A, "disallowed");
+testIDNCharacter(0x2044, "disallowed");
+testIDNCharacter(0x2044, "disallowed");
+testIDNCharacter(0x2154, "disallowed");
+testIDNCharacter(0x2155, "disallowed");
+testIDNCharacter(0x2156, "disallowed");
+testIDNCharacter(0x2159, "disallowed");
+testIDNCharacter(0x215A, "disallowed");
+testIDNCharacter(0x215B, "disallowed");
+testIDNCharacter(0x215F, "disallowed");
+testIDNCharacter(0x2215, "disallowed");
+testIDNCharacter(0x2216, "disallowed");
+testIDNCharacter(0x233F, "disallowed");
+testIDNCharacter(0x23AE, "disallowed");
+testIDNCharacter(0x244A, "disallowed");
+testIDNCharacter(0x2571, "disallowed");
+testIDNCharacter(0x2572, "disallowed");
+testIDNCharacter(0x29F6, "disallowed");
+testIDNCharacter(0x29F8, "disallowed");
+testIDNCharacter(0x29F8, "disallowed");
+testIDNCharacter(0x2AFB, "disallowed");
+testIDNCharacter(0x2AFD, "disallowed");
+testIDNCharacter(0x3014, "disallowed");
+testIDNCharacter(0x3015, "disallowed");
+testIDNCharacter(0x3033, "disallowed");
+testIDNCharacter(0x3035, "disallowed");
+testIDNCharacter(0x3164, "disallowed");
+testIDNCharacter(0x321D, "disallowed");
+testIDNCharacter(0x321E, "disallowed");
+testIDNCharacter(0x33AE, "disallowed");
+testIDNCharacter(0x33AF, "disallowed");
+testIDNCharacter(0x33C6, "disallowed");
+testIDNCharacter(0x33DF, "disallowed");
+testIDNCharacter(0xFE14, "disallowed");
+testIDNCharacter(0xFE15, "disallowed");
+testIDNCharacter(0xFE3F, "disallowed");
+testIDNCharacter(0xFE5D, "disallowed");
+testIDNCharacter(0xFE5E, "disallowed");
+testIDNCharacter(0xFFA0, "disallowed");
+
+/* ICU won't encode these characters in IDN, thus we should always get 'host not found'. */
+testIDNCharacter(0x2028, "does not encode");
+testIDNCharacter(0x2029, "does not encode");
+testIDNCharacter(0x2FF0, "does not encode");
+testIDNCharacter(0x2FF1, "does not encode");
+testIDNCharacter(0x2FF2, "does not encode");
+testIDNCharacter(0x2FF3, "does not encode");
+testIDNCharacter(0x2FF4, "does not encode");
+testIDNCharacter(0x2FF5, "does not encode");
+testIDNCharacter(0x2FF6, "does not encode");
+testIDNCharacter(0x2FF7, "does not encode");
+testIDNCharacter(0x2FF8, "does not encode");
+testIDNCharacter(0x2FF9, "does not encode");
+testIDNCharacter(0x2FFA, "does not encode");
+testIDNCharacter(0x2FFB, "does not encode");
+testIDNCharacter(0xFFF9, "does not encode");
+testIDNCharacter(0xFFFA, "does not encode");
+testIDNCharacter(0xFFFB, "does not encode");
+testIDNCharacter(0xFFFC, "does not encode");
+testIDNCharacter(0xFFFD, "does not encode");
+
+/* ICU won't encode these characters if they're not the first character in the host name.  
+   If the character does get encoded as the first character, then we will disallow it */
+   
+testIDNCharacter(0x05C3, "disallowed", "does not encode");
+testIDNCharacter(0x05F4, "disallowed", "does not encode");
+testIDNCharacter(0x06D4, "disallowed", "does not encode");
+testIDNCharacter(0x0702, "disallowed", "does not encode");
+
+/* ICU won't encode these characters if they're the first character in the host name.  
+   If the character does get encoded as the first character, then ICU converts it to another allowed character */
+
+if (isOlderICU) {
+    testIDNCharacter(0x200B, "");
+    testIDNCharacter(0x3002, ".");
+    testIDNCharacter(0xFF0E, ".");
+    testIDNCharacter(0xFF61, ".");
+    testIDNCharacter(0xFEFF, "");
+} else {
+    testIDNCharacter(0x200B, "does not encode", "");
+    testIDNCharacter(0x3002, "does not encode", ".");
+    testIDNCharacter(0xFF0E, "does not encode", ".");
+    testIDNCharacter(0xFF61, "does not encode", ".");
+    testIDNCharacter(0xFEFF, "does not encode", "");
+}
+
+successfullyParsed = true;
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/invalid-UTF-8-2-expected.txt b/LayoutTests/fast/encoding/invalid-UTF-8-2-expected.txt
new file mode 100644
index 0000000..66c6f22
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-UTF-8-2-expected.txt
@@ -0,0 +1,4 @@
+This tests the decoding of invalid UTF-8 sequences.
+
+The following should be: "т��т ���" or "т��т ��������":
+т��т ���
diff --git a/LayoutTests/fast/encoding/invalid-UTF-8-2.html b/LayoutTests/fast/encoding/invalid-UTF-8-2.html
new file mode 100644
index 0000000..d6ddd94
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-UTF-8-2.html
@@ -0,0 +1,23 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<style>
+/* Force font fallback on Windows to match Mac OS X */
+@font-face {
+    font-family: 'times';
+    src: local('Lucida Grande');
+    unicode-range: U+FFFD;
+}
+</style>
+</head>
+<body>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+</script>
+<p>This tests the decoding of invalid UTF-8 sequences.</p>
+The following should be: "т��т ���" or "т��т ��������":
+<p>т��т ���</p>
+</body>
+</html>
+
diff --git a/LayoutTests/fast/encoding/invalid-UTF-8.html b/LayoutTests/fast/encoding/invalid-UTF-8.html
new file mode 100644
index 0000000..ca8a9b1
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-UTF-8.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<style>
+/* Force font fallback on Windows to match Mac OS X */
+@font-face {
+    font-family: 'times';
+    src: local('Lucida Grande');
+    unicode-range: U+FFFD;
+}
+</style>
+</head>
+<body>
+<p>This tests the rendering of invalid UTF-8 sequences.</p>
+<p>The output should be: "т??т" (with black diamonds in place of question marks).</p>
+<hr>
+<p>т��т</p>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption-expected.txt b/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption-expected.txt
new file mode 100644
index 0000000..4d542ab
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption-expected.txt
@@ -0,0 +1,4 @@
+Test if an invalid multi-byte sequence is onverconsumed leading to an XSS vector
+
+ABCD" onchange="test='Failed'" using malformed byte sequence 0x83 0x22
+Passed
diff --git a/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption.html b/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption.html
new file mode 100644
index 0000000..60d7f0c
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-multi-byte-over-consumption.html
@@ -0,0 +1,34 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var test = "Passed";
+
+function runTest() {
+    var t = document.getElementById("input1");
+    if (document.all)  {  
+        t.fireEvent("onchange");  
+    } else {  
+        var evt = document.createEvent("HTMLEvents");  
+        evt.initEvent("change",true,true);  
+        t.dispatchEvent(evt);  
+    }
+ 
+    var r = document.getElementById("result");
+
+    if (test=="Passed")
+        r.innerHTML = "Passed";
+    else
+        r.innerHTML = "Failed";
+}
+</script>
+</head>
+<body onload="runTest();">
+<p>Test if an invalid multi-byte sequence is onverconsumed leading to an
+XSS vector</p>
+<input id="input1" src="" type="xss�">ABCD" onchange="test='Failed'" using malformed byte sequence 0x83 0x22<br>
+<div id="result"></div>
+</body>
diff --git a/LayoutTests/fast/encoding/invalid-xml-expected.txt b/LayoutTests/fast/encoding/invalid-xml-expected.txt
new file mode 100644
index 0000000..a4c0b0e
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-xml-expected.txt
@@ -0,0 +1,16 @@
+Testing: invalid-xml-utf8.xml
+PASS iframe.contentDocument.documentElement.tagName is "root"
+PASS iframe.contentDocument.documentElement.getElementsByTagName('test').length < 1 is true
+Testing: invalid-xml-utf16.xml
+PASS iframe.contentDocument.documentElement.tagName is "root"
+PASS iframe.contentDocument.documentElement.getElementsByTagName('test').length < 1 is true
+Testing: invalid-xml-shift-jis.xml
+PASS iframe.contentDocument.documentElement.tagName is "root"
+PASS iframe.contentDocument.documentElement.getElementsByTagName('test').length < 1 is true
+Testing: invalid-xml-x-mac-thai.xml
+FAIL iframe.contentDocument.documentElement.tagName should be root. Was html.
+PASS iframe.contentDocument.documentElement.getElementsByTagName('test').length < 1 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/encoding/invalid-xml.html b/LayoutTests/fast/encoding/invalid-xml.html
new file mode 100644
index 0000000..fbed47b
--- /dev/null
+++ b/LayoutTests/fast/encoding/invalid-xml.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/invalid-xml.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/japanese-encoding-mix-expected.txt b/LayoutTests/fast/encoding/japanese-encoding-mix-expected.txt
new file mode 100644
index 0000000..f7b1382
--- /dev/null
+++ b/LayoutTests/fast/encoding/japanese-encoding-mix-expected.txt
@@ -0,0 +1,5 @@
+Some text here is encoded as EUC-JP, and some (in comment) as Shift_JIS. Since there is an explicit encoding declaration, auto-detection shouldn't change the encoding.
+
+ニッポンテレビ
+
+Should be EUC-JP: EUC-JP
diff --git a/LayoutTests/fast/encoding/japanese-encoding-mix.html b/LayoutTests/fast/encoding/japanese-encoding-mix.html
new file mode 100644
index 0000000..7d9403b
--- /dev/null
+++ b/LayoutTests/fast/encoding/japanese-encoding-mix.html
@@ -0,0 +1,9 @@
+<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html dir="LTR" lang="ja">
+<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
+<p>Some text here is encoded as EUC-JP, and some (in comment) as Shift_JIS. Since there is an explicit encoding declaration, auto-detection shouldn't change the encoding.</p><p>¥Ë¥Ã¥Ý¥ó¥Æ¥ì¥Ó</p>
+<!--‰EƒJƒ‰ƒ€ƒRƒƒ“ƒgƒAƒEƒg ‚±‚±‚©‚ç -->
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+document.write("Should be EUC-JP: " + (document.charset ? document.charset : document.characterSet));</script>
diff --git a/LayoutTests/fast/encoding/latin1-winlatin-expected.txt b/LayoutTests/fast/encoding/latin1-winlatin-expected.txt
new file mode 100644
index 0000000..f58c141
--- /dev/null
+++ b/LayoutTests/fast/encoding/latin1-winlatin-expected.txt
@@ -0,0 +1,17 @@
+We need to treat Latin-1 as if it were windows-1252, see bug 7602.
+
+As entities: €ƒ†‡
+
+(escaped): %u20AC%81%u0192%u2020%u2021
+
+Inline: €ƒ†‡
+
+(escaped): %u20AC%81%u0192%u2020%u2021
+
+document.write of unicode escapes: €ƒ†‡
+
+(escaped): %80%81%83%86%87
+
+innerHTML assignment of unicode escapes: €ƒ†‡
+
+(escaped): %80%81%83%86%87
diff --git a/LayoutTests/fast/encoding/latin1-winlatin.html b/LayoutTests/fast/encoding/latin1-winlatin.html
new file mode 100644
index 0000000..8fe64d2
--- /dev/null
+++ b/LayoutTests/fast/encoding/latin1-winlatin.html
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv='Content-Type' content='text/html; charset=latin1'>
+</head>
+<body>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<p>We need to treat Latin-1 as if it were windows-1252, see <a href="https://bugs.webkit.org/show_bug.cgi?id=7602">bug 7602</a>.</p>
+<p>As entities: <span id='entities'>&#x80;&#x81;&#x83;&#x86;&#x87;</span></p>
+<script>document.write('<p>(escaped): ' + escape(document.getElementById('entities').innerHTML) + '</p>');</script><p>Inline: <span id='inline'>€ƒ†‡</span></p>
+<script>document.write('<p>(escaped): ' + escape(document.getElementById('inline').innerHTML) + '</p>');</script><p>document.write of unicode escapes: <script>document.write('<span id="write">\x80\x81\u0083\u0086\u0087</span>');</script></p><script>document.write('<p>(escaped): ' + escape(document.getElementById('write').innerHTML) + '</p>');</script><p>innerHTML assignment of unicode escapes: <span id='inner'></span></p><script>document.getElementById('inner').innerHTML = '\x80\x81\u0083\u0086\u0087';</script><script>document.write('<p>(escaped): ' + escape(document.getElementById('inner').innerHTML) + '</p>');</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/mailto-always-utf-8-expected.txt b/LayoutTests/fast/encoding/mailto-always-utf-8-expected.txt
new file mode 100644
index 0000000..66b9118
--- /dev/null
+++ b/LayoutTests/fast/encoding/mailto-always-utf-8-expected.txt
@@ -0,0 +1,4 @@
+Policy delegate: attempt to load mailto:?subject=%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB&body=%E6%9C%AC%E6%96%87 with navigation type 'link clicked' originating from #text > SPAN > A > BODY > HTML > #document
+Test encoding of mailto URLs. Click on the URL - a new message with Japanese subject and body should open in your mail client.
+
+Subject : Japanese Body : Japanese
diff --git a/LayoutTests/fast/encoding/mailto-always-utf-8.html b/LayoutTests/fast/encoding/mailto-always-utf-8.html
new file mode 100644
index 0000000..0bb6206
--- /dev/null
+++ b/LayoutTests/fast/encoding/mailto-always-utf-8.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="ja">
+<HEAD>
+    <meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS">
+</HEAD>
+<body onload="test()">
+    <p>Test encoding of mailto URLs. Click on the URL - a new message
+    with Japanese subject and body should open in your mail client.</p>
+
+    <a href="mailto:?subject=ƒ^ƒCƒgƒ‹&body=–{•¶">
+    <span>Subject : Japanese   Body : Japanese</span>
+    </a>
+
+<script>
+function test() {
+  if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitForPolicyDelegate();
+    var a = document.getElementsByTagName("a")[0];
+    eventSender.mouseMoveTo(a.offsetLeft + 5, a.offsetTop + 5);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+  }
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/meta-charset-expected.txt b/LayoutTests/fast/encoding/meta-charset-expected.txt
new file mode 100644
index 0000000..6f985f9
--- /dev/null
+++ b/LayoutTests/fast/encoding/meta-charset-expected.txt
@@ -0,0 +1,3 @@
+Should see Hebrew letter Aleph twice: אא
+
+windows-1255
diff --git a/LayoutTests/fast/encoding/meta-charset.html b/LayoutTests/fast/encoding/meta-charset.html
new file mode 100644
index 0000000..fe12f21
--- /dev/null
+++ b/LayoutTests/fast/encoding/meta-charset.html
@@ -0,0 +1,14 @@
+<HTML>
+<HEAD>
+<meta charset=windows-1255>
+</HEAD>
+<BODY>
+<p>Should see Hebrew letter Aleph twice: à&#1488;</p>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.write(document.inputEncoding);
+</script>
+</BODY>
+</HTML>
diff --git a/LayoutTests/fast/encoding/meta-in-xhtml-expected.txt b/LayoutTests/fast/encoding/meta-in-xhtml-expected.txt
new file mode 100644
index 0000000..9ff4140
--- /dev/null
+++ b/LayoutTests/fast/encoding/meta-in-xhtml-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 5620: Should only honor encoding from <meta> in HTML
+
+Charset: UTF-8 (should be UTF-8)
diff --git a/LayoutTests/fast/encoding/meta-in-xhtml.xhtml b/LayoutTests/fast/encoding/meta-in-xhtml.xhtml
new file mode 100644
index 0000000..d9c6065
--- /dev/null
+++ b/LayoutTests/fast/encoding/meta-in-xhtml.xhtml
@@ -0,0 +1,23 @@
+<?xml version="1.0" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+</head>
+<body>
+<p>Test for <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=5620">bug 5620</a>:
+Should only honor encoding from &lt;meta> in HTML</p>
+
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be UTF-8)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/misplaced-xml-declaration-expected.txt b/LayoutTests/fast/encoding/misplaced-xml-declaration-expected.txt
new file mode 100644
index 0000000..34b2987
--- /dev/null
+++ b/LayoutTests/fast/encoding/misplaced-xml-declaration-expected.txt
@@ -0,0 +1 @@
+Should be your browser default encoding: ISO-8859-1
diff --git a/LayoutTests/fast/encoding/misplaced-xml-declaration.html b/LayoutTests/fast/encoding/misplaced-xml-declaration.html
new file mode 100644
index 0000000..b4f559d
--- /dev/null
+++ b/LayoutTests/fast/encoding/misplaced-xml-declaration.html
@@ -0,0 +1,10 @@
+ <?xml version="1.0" encoding="koi8-r"?>
+<html>
+<body>
+Should be your browser default encoding: 
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+  document.write(document.characterSet)
+</script>
+</body>
diff --git a/LayoutTests/fast/encoding/mispositioned-meta-expected.txt b/LayoutTests/fast/encoding/mispositioned-meta-expected.txt
new file mode 100644
index 0000000..a21684b
--- /dev/null
+++ b/LayoutTests/fast/encoding/mispositioned-meta-expected.txt
@@ -0,0 +1,5 @@
+This test checks if WebKit can find a charset defined in an HTTP-EQUIV meta after the HEAD.
+
+The first letter should look like a Latin "C" here:
+
+Сайт Гоблина - Тупичок ст.о/у Гоблина (Goblin). Фильмы Гоблина. полный Пэ. Божья Искра.
diff --git a/LayoutTests/fast/encoding/mispositioned-meta.html b/LayoutTests/fast/encoding/mispositioned-meta.html
new file mode 100644
index 0000000..4eb0859
--- /dev/null
+++ b/LayoutTests/fast/encoding/mispositioned-meta.html
@@ -0,0 +1,22 @@
+<html>
+ <head>
+  <title>çÏÂÌÉÎ, Goblin, ÓÁÊÔ çÏÂÌÉÎÁ</title>
+  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
+  <script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+  </script>
+ </head>
+ <meta http-equiv="Content-Type" content="text/html; charset=KOI8-R">
+ <body>
+  <p>This test checks if WebKit can find a charset defined in an HTTP-EQUIV meta after the HEAD.</p>
+  <p>The first letter should look like a Latin "C" here:</p>
+  <p>
+  óÁÊÔ çÏÂÌÉÎÁ - ôÕÐÉÞÏË ÓÔ.Ï/Õ çÏÂÌÉÎÁ (Goblin). æÉÌØÍÙ çÏÂÌÉÎÁ. ÐÏÌÎÙÊ ðÜ. âÏÖØÑ éÓËÒÁ.
+  </p>
+ </body>
+</html>
+<!--
+     See https://bugs.webkit.org/show_bug.cgi?id=3590
+     and https://bugzilla.mozilla.org/show_bug.cgi?id=98700 
+ -->
diff --git a/LayoutTests/fast/encoding/namespace-tolerance-expected.txt b/LayoutTests/fast/encoding/namespace-tolerance-expected.txt
new file mode 100644
index 0000000..a349969
--- /dev/null
+++ b/LayoutTests/fast/encoding/namespace-tolerance-expected.txt
@@ -0,0 +1,5 @@
+This test ensures a UTF-8 encoding is properly set on documents that: 
+(1) use namespace prefixes on HTML elements 
+(2) specify a non-latin charset 
+(3) contain non-latin characters 
+If this test passes, the UTF-8 character below should exactly match the character the character in namespace-tolerance-expected.txt. 法
diff --git a/LayoutTests/fast/encoding/namespace-tolerance.html b/LayoutTests/fast/encoding/namespace-tolerance.html
new file mode 100644
index 0000000..c7841d2
--- /dev/null
+++ b/LayoutTests/fast/encoding/namespace-tolerance.html
@@ -0,0 +1,15 @@
+<xhtml:html xmlns:xhtml="">
+<meta content="charset=UTF-8">
+
+This test ensures a UTF-8 encoding is properly set on documents that:
+<br>
+(1) use namespace prefixes on HTML elements
+<br>
+(2) specify a non-latin charset 
+<br>
+(3) contain non-latin characters
+<br>
+If this test passes, the UTF-8 character below should exactly match the character the character in namespace-tolerance-expected.txt.
+法
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+<html>
diff --git a/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt
new file mode 100644
index 0000000..b817801
--- /dev/null
+++ b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load-expected.txt
@@ -0,0 +1,2 @@
+This page tests that the character encoding is used for dynamically loaded scripts when no charset is specified directly or provided by the server.
+PASS: UTF-8 was correctly used for this script.
diff --git a/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html
new file mode 100644
index 0000000..363c261
--- /dev/null
+++ b/LayoutTests/fast/encoding/no-charset-on-dynamic-script-load.html
@@ -0,0 +1,22 @@
+<html>
+    <head>
+        <title>Encoding test.</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+           </head>
+    <body>
+        This page tests that the character encoding is used for dynamically loaded 
+        scripts when no charset is specified directly or provided by the server.
+        
+        <div id="target"></div>
+        <script>
+            if (window.layoutTestController) {
+                window.layoutTestController.waitUntilDone();
+                window.layoutTestController.dumpAsText();
+            }
+            tokyo = 'とうきょう';
+            oDIVResults=document.createElement('script'); 
+            oDIVResults.src="resources/dynamic-load-target.js";
+            document.getElementsByTagName("head").item(0).appendChild(oDIVResults);
+        </script>
+    </body>
+</html>
diff --git a/LayoutTests/fast/encoding/noscript-in-head-expected.txt b/LayoutTests/fast/encoding/noscript-in-head-expected.txt
new file mode 100644
index 0000000..c00baa4
--- /dev/null
+++ b/LayoutTests/fast/encoding/noscript-in-head-expected.txt
@@ -0,0 +1,7 @@
+Test for bug 12389: Chinese decoding error at hk.antispam.yahoo.com
+
+You should see two identical lines below:
+
+雅虎香港
+
+雅虎香港
diff --git a/LayoutTests/fast/encoding/noscript-in-head.html b/LayoutTests/fast/encoding/noscript-in-head.html
new file mode 100644
index 0000000..bd8acd2
--- /dev/null
+++ b/LayoutTests/fast/encoding/noscript-in-head.html
@@ -0,0 +1,17 @@
+<script language=javascript>
+</script><noscript><img src=about:blank><table></table><p></p></noscript><html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=big5">
+</head><body>
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=12389">bug 12389</a>:
+Chinese decoding error at hk.antispam.yahoo.com</p>
+<p>You should see two identical lines below:</p>
+<p>¶®ªê­»´ä</p>
+<p>&#38597;&#34382;&#39321;&#28207;</p>
+
+<script>
+if (window.layoutTestController)
+  layoutTestController.dumpAsText();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/percent-escaping-expected.txt b/LayoutTests/fast/encoding/percent-escaping-expected.txt
new file mode 100644
index 0000000..37665db
--- /dev/null
+++ b/LayoutTests/fast/encoding/percent-escaping-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 6452 - KURL::appendEscapingBadChars() should never escape percent characters.
+
+SUCCESS
diff --git a/LayoutTests/fast/encoding/percent-escaping.html b/LayoutTests/fast/encoding/percent-escaping.html
new file mode 100644
index 0000000..a2d0ea8
--- /dev/null
+++ b/LayoutTests/fast/encoding/percent-escaping.html
@@ -0,0 +1,23 @@
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<title>Percent escaping</title>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=6452">bug 6452</a> - 
+KURL::appendEscapingBadChars() should never escape percent characters.</p>
+<form action='resources/%2525%u0435 0 %xx%25%%ulike.html' name=f>
+ <input type=hidden name=q value=''>
+</form>
+<script>
+
+  if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+  }
+
+  document.f.submit();
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/preload-encoding-expected.txt b/LayoutTests/fast/encoding/preload-encoding-expected.txt
new file mode 100644
index 0000000..578c51d
--- /dev/null
+++ b/LayoutTests/fast/encoding/preload-encoding-expected.txt
@@ -0,0 +1,4 @@
+Script with charset: SUССЕSS.
+Link rel=stylesheet with charset: SUCCESS
+Script without charset: SUССЕSS
+Link rel=stylesheet without charset: SUCCESS
diff --git a/LayoutTests/fast/encoding/preload-encoding.html b/LayoutTests/fast/encoding/preload-encoding.html
new file mode 100644
index 0000000..ef7b2f5
--- /dev/null
+++ b/LayoutTests/fast/encoding/preload-encoding.html
@@ -0,0 +1,47 @@
+<meta charset="gb2312">
+<body onload="testStylesheets()">
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+
+<!--
+ This test uses the word "SUCCESS" spelled with Cyrillic letters "CCE",
+ making decoding problems visible.
+-->
+
+<ol>
+<li>Script with charset:
+<span id="testdiv1"></span>.
+<li>Link rel=stylesheet with charset:
+<span id="testdiv2"></span>
+<li>Script without charset:
+<span id="testdiv3"></span>
+<li>Link rel=stylesheet without charset:
+<span id="testdiv4"></span>
+</ol>
+
+<script type='text/javascript' src='this-does-not-need-to-exist.js'></script>
+
+<script type='text/javascript' src='resources/preloaded-utf-8.js' charset='utf-8'></script>
+
+<link rel='stylesheet' href='resources/preloaded-utf-8.css' charset='utf-8'>
+
+<script charset="utf-8"></script>
+
+<script type='text/javascript' src='resources/preloaded-gb2312.js'></script>
+
+<link rel='stylesheet' charset='utf-8'>
+
+<link rel='stylesheet' href='resources/preloaded-gb2312.css'>
+
+<script>
+function testStylesheets()
+{
+    document.getElementById('testdiv2').innerText = 
+        (/SU§³§³§¦SS/.test(document.styleSheets[0].cssRules[0].cssText)) ? "SUCCESS" : "FAILURE";
+
+    document.getElementById('testdiv4').innerText = 
+        (/SU§³§³§¦SS/.test(document.styleSheets[1].cssRules[0].cssText)) ? "SUCCESS" : "FAILURE";
+}
+</script>
diff --git a/LayoutTests/fast/encoding/pseudo-tags-in-attributes-expected.txt b/LayoutTests/fast/encoding/pseudo-tags-in-attributes-expected.txt
new file mode 100644
index 0000000..134245f
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-tags-in-attributes-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 12506: REGRESSION: Safari doesn't display hebrew text on a web page, displayed correctly on Tiger.
+
+SUССЕSS
+
+Charset: UTF-8
diff --git a/LayoutTests/fast/encoding/pseudo-tags-in-attributes.html b/LayoutTests/fast/encoding/pseudo-tags-in-attributes.html
new file mode 100644
index 0000000..2e6e015
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-tags-in-attributes.html
@@ -0,0 +1,20 @@
+<HTML>
+  <HEAD>
+    <TITLE></TITLE>
+    <LINK rel="stylesheet" type="<foobar><>" href="">
+    <meta name="keywords" content="<body>, <foobar>, <>">
+    <META HTTP-EQUIV="Content-Type" CONTENT="text/html" charset="utf-8">
+
+  </HEAD>
+  <BODY>
+  <P>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=12506">bug 12506</a>:
+  REGRESSION: Safari doesn't display hebrew text on a web page, displayed correctly on Tiger.</P>
+  <P>SUССЕSS</P>
+  
+  <SCRIPT>
+  document.write("<p>Charset: " + document.inputEncoding + "</p>");
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+  </SCRIPT>
+  </BODY>
+</HTML>
diff --git a/LayoutTests/fast/encoding/pseudo-xml-2-expected.txt b/LayoutTests/fast/encoding/pseudo-xml-2-expected.txt
new file mode 100644
index 0000000..2ece178
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-2-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 9783: An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document
+
+Test that an XML declaration with an explicit encoding is still honored. This is what Firefox 1.5 and Safari 2.0 do, unlike WinIE 6.
+
+Charset: KOI8-R (should be KOI8-R)
diff --git a/LayoutTests/fast/encoding/pseudo-xml-2.html b/LayoutTests/fast/encoding/pseudo-xml-2.html
new file mode 100644
index 0000000..94f9b32
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-2.html
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="koi8-r" ?>
+<html>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=9783">bug 9783</a>:
+An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document</p>
+<p>Test that an XML declaration <b>with</b> an explicit encoding is still honored. This is what Firefox 1.5 and Safari 2.0 do, unlike WinIE 6.</p>
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be KOI8-R)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/pseudo-xml-3-expected.txt b/LayoutTests/fast/encoding/pseudo-xml-3-expected.txt
new file mode 100644
index 0000000..74f20f2
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-3-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 9783: An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document
+
+Charset: KOI8-R (should be KOI8-R)
diff --git a/LayoutTests/fast/encoding/pseudo-xml-3.html b/LayoutTests/fast/encoding/pseudo-xml-3.html
new file mode 100644
index 0000000..486d01e
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-3.html
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta content="text/html; charset=KOI8-R" http-equiv="Content-Type"/>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=9783">bug 9783</a>:
+An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document</p>
+
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be KOI8-R)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/pseudo-xml-4-expected.txt b/LayoutTests/fast/encoding/pseudo-xml-4-expected.txt
new file mode 100644
index 0000000..da4a985
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-4-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 9783: An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document
+
+Charset: windows-1251 (should be windows-1251)
diff --git a/LayoutTests/fast/encoding/pseudo-xml-4.html b/LayoutTests/fast/encoding/pseudo-xml-4.html
new file mode 100644
index 0000000..fd5de7a
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-4.html
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="KOI8-R" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta content="text/html; charset=windows-1251" http-equiv="Content-Type"/>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=9783">bug 9783</a>:
+An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document</p>
+
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be windows-1251)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/pseudo-xml-expected.txt b/LayoutTests/fast/encoding/pseudo-xml-expected.txt
new file mode 100644
index 0000000..1b56ef3
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml-expected.txt
@@ -0,0 +1,3 @@
+Test for bug 9783: An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document
+
+Charset: ISO-8859-1 (should be your browser default one)
diff --git a/LayoutTests/fast/encoding/pseudo-xml.html b/LayoutTests/fast/encoding/pseudo-xml.html
new file mode 100644
index 0000000..e71d39e
--- /dev/null
+++ b/LayoutTests/fast/encoding/pseudo-xml.html
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=9783">bug 9783</a>:
+An XML declaration without an explicit encoding incorrectly triggers UTF-8 encoding in an HTML document</p>
+
+<p id="result" />
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.getElementById("result").innerHTML = "Charset: " + 
+    (document.charset ? document.charset : document.characterSet) + " (should be your browser default one)";
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/resources/%25%u0435 0 %xx%%%ulike.html b/LayoutTests/fast/encoding/resources/%25%u0435 0 %xx%%%ulike.html
new file mode 100644
index 0000000..ae0d86f
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/%25%u0435 0 %xx%%%ulike.html
@@ -0,0 +1,14 @@
+<html>
+<body onload="javascript:
+  // WinIE and Firefox use the same URL, but in WinIE, document.URL returns unescaped text
+  if (document.URL.match('%25.*html') == '%2525%u0435%200%20%xx%25%%ulike.html' || 
+      document.URL.match('%25.*html') == '%25%u0435 0 %xx%%%ulike.html')
+     document.getElementById('result').firstChild.nodeValue = 'SUCCESS';
+
+  layoutTestController.notifyDone();
+">
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=6452">bug 6452</a> - 
+KURL::appendEscapingBadChars() should never escape percent characters.</p>
+<p id=result>FAILURE</p>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/resources/char-decoding-utils.js b/LayoutTests/fast/encoding/resources/char-decoding-utils.js
new file mode 100644
index 0000000..a091ad8
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/char-decoding-utils.js
@@ -0,0 +1,34 @@
+function hex(number)
+{
+    var hexDigit = "0123456789ABCDEF";
+    var hex = hexDigit.substr(number & 0xf, 1);
+    while (number > 15) {
+        number >>= 4;
+        hex = hexDigit.substr(number & 15, 1) + hex;
+    }
+    return hex;
+}
+
+function decode(charsetName, characterSequence)
+{
+    var req = new XMLHttpRequest;
+    req.open('GET', 'data:text/plain,' + characterSequence, false);
+    req.overrideMimeType('text/plain; charset="' + charsetName + '"');
+    req.send('');
+    var code = hex(req.responseText.charCodeAt(0));
+    return "U+" + ("0000" + code).substr(code.length, 4);
+}
+
+function testDecode(charsetName, characterSequence, unicode)
+{
+    shouldBe("decode('" + charsetName + "', '" + characterSequence + "')", "'" + unicode + "'");
+}
+
+function batchTestDecode(inputData)
+{
+    for (var i in inputData.encodings) {
+        for (var j in inputData.encoded)
+            testDecode(inputData.encodings[i], inputData.encoded[j], inputData.unicode[j]);
+    }
+}
+
diff --git a/LayoutTests/fast/encoding/resources/char-encoding-utils.js b/LayoutTests/fast/encoding/resources/char-encoding-utils.js
new file mode 100644
index 0000000..2007c7f
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/char-encoding-utils.js
@@ -0,0 +1,69 @@
+function encode(charset, unicode)
+{
+    // Returns a value already encoded, since we can't do it synchronously.
+    return results[charset][unicode];
+}
+
+function testsDone()
+{
+    var form = document.getElementById('form');
+    var subframe = document.getElementById('subframe');
+
+    form.parentNode.removeChild(form);
+    subframe.parentNode.removeChild(subframe);
+
+    description("This tests encoding characters in various character sets.");
+
+    for (i = 0; i < charsets.length; ++i) {
+        shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + expectedResults[i] + "'");
+    }
+
+    isSuccessfullyParsed();
+
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+function processResult(result)
+{
+    var charsetResults = results[charsets[i]];
+    if (!charsetResults) {
+        charsetResults = new Object;
+        results[charsets[i]] = charsetResults;
+    }
+    charsetResults[unicodes[i]] = result; 
+}
+
+function subframeLoaded()
+{
+    var URL = "" + document.getElementById('subframe').contentWindow.location;
+    processResult(URL.substr(URL.indexOf('=') + 1));
+    ++i;
+    runTest();
+}
+
+function runTest()
+{    
+    if (i >= charsets.length) {
+        testsDone();
+        return;
+    }
+
+    var form = document.getElementById('form');
+    var text = document.getElementById('text');
+    var subframe = document.getElementById('subframe');
+
+    form.acceptCharset = charsets[i];
+    form.action = "resources/dummy.html";
+    subframe.onload = subframeLoaded;
+    text.value = String.fromCharCode(unicodes[i].replace('U+', '0x'));
+    
+    form.submit();
+}
+
+function testEncode(charsetName, unicode, characterSequence)
+{
+    charsets.push(charsetName);
+    unicodes.push(unicode);
+    expectedResults.push(characterSequence);
+}
diff --git a/LayoutTests/fast/encoding/resources/css-cached-bom-frame.html b/LayoutTests/fast/encoding/resources/css-cached-bom-frame.html
new file mode 100644
index 0000000..0412e3f
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/css-cached-bom-frame.html
@@ -0,0 +1,5 @@
+<link rel=stylesheet href=utf-16-little-endian.css>
+<script>
+window.parent.frameLoaded();
+</script>
+
diff --git a/LayoutTests/fast/encoding/resources/dummy.html b/LayoutTests/fast/encoding/resources/dummy.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/dummy.html
diff --git a/LayoutTests/fast/encoding/resources/dynamic-load-target.js b/LayoutTests/fast/encoding/resources/dynamic-load-target.js
new file mode 100644
index 0000000..6a0e175
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/dynamic-load-target.js
@@ -0,0 +1,9 @@
+
+
+if ('とうきょう' == tokyo)
+    document.getElementById("target").innerHTML = "PASS: UTF-8 was correctly used for this script.";
+else
+    document.getElementById("target").innerHTML = "FAIL: Incorrect encoding used.  Expected '" + tokyo + "' but got '" + 'とうきょう' + "'.";
+
+if (window.layoutTestController) 
+    window.layoutTestController.notifyDone();
diff --git a/LayoutTests/fast/encoding/resources/frame-default-enc-frame.html b/LayoutTests/fast/encoding/resources/frame-default-enc-frame.html
new file mode 100644
index 0000000..8e928e3
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/frame-default-enc-frame.html
@@ -0,0 +1,17 @@
+<html>
+<head>
+<title>Frame</title>
+</head>
+<body>
+<script>
+    chs = document.inputEncoding;
+    if (!chs)
+        chs = document.charset;
+    if (!chs)
+        chs = document.characterSet;
+
+    parent.done(chs);
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/resources/invalid-xml-shift-jis.xml b/LayoutTests/fast/encoding/resources/invalid-xml-shift-jis.xml
new file mode 100644
index 0000000..c33a08c
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/invalid-xml-shift-jis.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="shift-jis" ?>
+<root>
+ <fail> This is an invalid byte pair in shift-jis:  </fail>
+ <test/> <!-- shouldn't ever be parsed, as the parser should abort at the first sign of non-well-formedness -->
+</root>
diff --git a/LayoutTests/fast/encoding/resources/invalid-xml-utf16.xml b/LayoutTests/fast/encoding/resources/invalid-xml-utf16.xml
new file mode 100644
index 0000000..cb7da3a
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/invalid-xml-utf16.xml
Binary files differ
diff --git a/LayoutTests/fast/encoding/resources/invalid-xml-utf8.xml b/LayoutTests/fast/encoding/resources/invalid-xml-utf8.xml
new file mode 100644
index 0000000..b47850e
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/invalid-xml-utf8.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<root>
+ <fail> This is an invalid byte in UTF-8: ¿ </fail>
+ <test/> <!-- shouldn't ever be parsed, as the parser should abort at the first sign of non-well-formedness -->
+</root>
diff --git a/LayoutTests/fast/encoding/resources/invalid-xml-x-mac-thai.xml b/LayoutTests/fast/encoding/resources/invalid-xml-x-mac-thai.xml
new file mode 100644
index 0000000..198d0ee
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/invalid-xml-x-mac-thai.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="x-mac-thai" ?>
+<root>
+ <fail> This is an invalid byte in x-mac-thai:  </fail>
+ <test/> <!-- shouldn't ever be parsed, as the parser should abort at the first sign of non-well-formedness -->
+</root>
diff --git a/LayoutTests/fast/encoding/resources/invalid-xml.js b/LayoutTests/fast/encoding/resources/invalid-xml.js
new file mode 100644
index 0000000..e241a0c
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/invalid-xml.js
@@ -0,0 +1,43 @@
+// test 70: XML encoding test
+// q.v. XML 1.0, section 4.3.3 Character Encoding in Entities
+// this only tests one of a large number of conditions that should cause fatal errors
+
+function runEncodingTest(event)
+{
+    debug("Testing: " + encodingTests[currentTest-1]);
+    shouldBeEqualToString("iframe.contentDocument.documentElement.tagName", "root");
+    shouldBeTrue("iframe.contentDocument.documentElement.getElementsByTagName('test').length < 1");
+    setTimeout(runNextTest, 0);
+}
+
+var currentTest = 0;
+var encodingTests = [
+    "invalid-xml-utf8.xml",
+    "invalid-xml-utf16.xml",
+    "invalid-xml-shift-jis.xml",
+    "invalid-xml-x-mac-thai.xml",
+];
+
+function runNextTest()
+{
+    if (currentTest >= encodingTests.length) {
+        var script = document.createElement("script");
+        script.src = "../js/resources/js-test-post.js";
+        if (window.layoutTestController)
+            script.setAttribute("onload", "layoutTestController.notifyDone()");
+        document.body.appendChild(script);
+        iframe.parentNode.removeChild(iframe);
+        return;
+    }
+    iframe.src = "resources/" + encodingTests[currentTest++];
+}
+
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+var iframe = document.createElement("iframe");
+document.body.appendChild(iframe);
+iframe.onload = runEncodingTest;
+runNextTest();
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/encoding/resources/preloaded-gb2312.css b/LayoutTests/fast/encoding/resources/preloaded-gb2312.css
new file mode 100644
index 0000000..9d83e62
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/preloaded-gb2312.css
@@ -0,0 +1 @@
+#foobar:before { content: "SU§³§³§¦SS"; }
diff --git a/LayoutTests/fast/encoding/resources/preloaded-gb2312.js b/LayoutTests/fast/encoding/resources/preloaded-gb2312.js
new file mode 100644
index 0000000..c324df0
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/preloaded-gb2312.js
@@ -0,0 +1 @@
+document.getElementById('testdiv3').innerText = 'SU§³§³§¦SS';
diff --git a/LayoutTests/fast/encoding/resources/preloaded-utf-8.css b/LayoutTests/fast/encoding/resources/preloaded-utf-8.css
new file mode 100644
index 0000000..d4d992b
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/preloaded-utf-8.css
@@ -0,0 +1 @@
+#foobar:before { content: "SUССЕSS"; }
diff --git a/LayoutTests/fast/encoding/resources/preloaded-utf-8.js b/LayoutTests/fast/encoding/resources/preloaded-utf-8.js
new file mode 100644
index 0000000..6160a18
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/preloaded-utf-8.js
@@ -0,0 +1 @@
+document.getElementById('testdiv1').innerText = 'SUССЕSS';
diff --git a/LayoutTests/fast/encoding/resources/utf-16-little-endian.css b/LayoutTests/fast/encoding/resources/utf-16-little-endian.css
new file mode 100644
index 0000000..2ca0c95
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/utf-16-little-endian.css
Binary files differ
diff --git a/LayoutTests/fast/encoding/resources/yentestexternal.js b/LayoutTests/fast/encoding/resources/yentestexternal.js
new file mode 100644
index 0000000..01262ea
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/yentestexternal.js
@@ -0,0 +1,4 @@
+function writeYenExternal()
+{
+    document.write("two backslashes external: " + "\\" + "<br>");
+}
diff --git a/LayoutTests/fast/encoding/resources/yentestexternal2.js b/LayoutTests/fast/encoding/resources/yentestexternal2.js
new file mode 100644
index 0000000..a6db72b
--- /dev/null
+++ b/LayoutTests/fast/encoding/resources/yentestexternal2.js
@@ -0,0 +1,5 @@
+function writeYenExternal()
+{
+    document.write("two backslashes external: \\ <br>");
+    document.write("one backslash external: \ <br>");
+}
diff --git a/LayoutTests/fast/encoding/script-in-head-expected.txt b/LayoutTests/fast/encoding/script-in-head-expected.txt
new file mode 100644
index 0000000..c29dde5
--- /dev/null
+++ b/LayoutTests/fast/encoding/script-in-head-expected.txt
@@ -0,0 +1,5 @@
+Test for bug 12165: text encoding problem at jn.sapo.pt
+
+Should see a success message below.
+
+SUССЕSS
diff --git a/LayoutTests/fast/encoding/script-in-head.html b/LayoutTests/fast/encoding/script-in-head.html
new file mode 100644
index 0000000..d6dc1ca
--- /dev/null
+++ b/LayoutTests/fast/encoding/script-in-head.html
@@ -0,0 +1,30 @@
+<!-- temp --><script language="JavaScript" type="text/JavaScript">
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+document.write ('<SCR' + 'IPT>' +
+
+    'setTimeout(function () {' +
+        <!-- The letters CCE below are Cyrillic, so we do test that the encoding is correct. -->
+        <!-- We also take an opportunity to test that this weirdly located script actually executes. -->
+        'document.getElementById("result").innerHTML="SUóóåSS";' +
+        'if (window.layoutTestController)' +
+            'layoutTestController.notifyDone();' +
+    '}, 0);' +
+'</SCR' + 'IPT>');document.close(); </script>
+<!-- /temp --><!--HEADER-->
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
+</head>
+<body>
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=12165">bug 12165</a>:
+text encoding problem at jn.sapo.pt</p>
+<p>Should see a success message below.</p>
+<div id="result"></div>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/tag-in-title-expected.txt b/LayoutTests/fast/encoding/tag-in-title-expected.txt
new file mode 100644
index 0000000..6fef9b4
--- /dev/null
+++ b/LayoutTests/fast/encoding/tag-in-title-expected.txt
@@ -0,0 +1,5 @@
+This test checks that WebKit doesn't stop looking for a charset defined in an HTTP-EQUIV meta when it encounters a tag within <title>.
+
+The first letter should look like a Latin "K" here:
+
+Какая гадость!
diff --git a/LayoutTests/fast/encoding/tag-in-title.html b/LayoutTests/fast/encoding/tag-in-title.html
new file mode 100644
index 0000000..ff7ca4e
--- /dev/null
+++ b/LayoutTests/fast/encoding/tag-in-title.html
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>ôÜÇÉ <b><font color=red>[R]</font></b> × &lt;title&gt;</title>
+ <link rel="shortcut icon" href=/favicon.ico type=image/x-icon>
+ <meta http-equiv="Content-Type" content="text/html; charset=KOI8-R">
+ <script>
+   if (window.layoutTestController)
+       layoutTestController.dumpAsText();
+ </script>
+ </head>
+
+<body>
+  <p>This test checks that WebKit doesn't stop looking for a charset defined in an HTTP-EQUIV meta when it encounters a tag within &lt;title&gt;.</p>
+  <p>The first letter should look like a Latin "K" here:</p>
+  <p>
+  ëÁËÁÑ ÇÁÄÏÓÔØ!
+  </p>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/url-host-name-non-ascii-expected.txt b/LayoutTests/fast/encoding/url-host-name-non-ascii-expected.txt
new file mode 100644
index 0000000..ed78fc8
--- /dev/null
+++ b/LayoutTests/fast/encoding/url-host-name-non-ascii-expected.txt
@@ -0,0 +1,3 @@
+Test for http://bugs.webkit.org/show_bug.cgi?id=17676 REGRESSION (r30240-r30267): href attribute values with non-ASCII characters in the host part do not work.
+
+PASS
diff --git a/LayoutTests/fast/encoding/url-host-name-non-ascii.html b/LayoutTests/fast/encoding/url-host-name-non-ascii.html
new file mode 100644
index 0000000..639b7ba
--- /dev/null
+++ b/LayoutTests/fast/encoding/url-host-name-non-ascii.html
@@ -0,0 +1,13 @@
+<p>
+    Test for <i><a href="http://bugs.webkit.org/show_bug.cgi?id=17676">http://bugs.webkit.org/show_bug.cgi?id=17676</a>
+    REGRESSION (r30240-r30267): href attribute values with non-ASCII characters in the host part do not work</i>.
+</p>
+<a id="anchor" href="http://w&#xe9;bkit.org/"></a>
+<div id="result"></div>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var encodedURL = document.getElementById("anchor").href;
+    document.getElementById("result").innerText = encodedURL == "http://xn--wbkit-bsa.org/" ? "PASS" : "FAIL: The encoded URL was '" + encodedURL + "'.";
+</script>
diff --git a/LayoutTests/fast/encoding/utf-16-big-endian.html b/LayoutTests/fast/encoding/utf-16-big-endian.html
new file mode 100644
index 0000000..00db967
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-16-big-endian.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-16-little-endian.html b/LayoutTests/fast/encoding/utf-16-little-endian.html
new file mode 100644
index 0000000..540d7bf
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-16-little-endian.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-16-no-bom.xml b/LayoutTests/fast/encoding/utf-16-no-bom.xml
new file mode 100644
index 0000000..17f9367
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-16-no-bom.xml
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-32-big-endian-bom-expected.txt b/LayoutTests/fast/encoding/utf-32-big-endian-bom-expected.txt
new file mode 100644
index 0000000..8c860aa
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-big-endian-bom-expected.txt
@@ -0,0 +1,5 @@
+When dumped into a text file by the test controller, this needs to be viewed as UTF-8:
+
+This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.
+
+Success : UTF-32BE
diff --git a/LayoutTests/fast/encoding/utf-32-big-endian-bom.html b/LayoutTests/fast/encoding/utf-32-big-endian-bom.html
new file mode 100644
index 0000000..bab8e9c
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-big-endian-bom.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-32-big-endian-nobom-expected.txt b/LayoutTests/fast/encoding/utf-32-big-endian-nobom-expected.txt
new file mode 100644
index 0000000..8c860aa
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-big-endian-nobom-expected.txt
@@ -0,0 +1,5 @@
+When dumped into a text file by the test controller, this needs to be viewed as UTF-8:
+
+This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.
+
+Success : UTF-32BE
diff --git a/LayoutTests/fast/encoding/utf-32-big-endian-nobom.xml b/LayoutTests/fast/encoding/utf-32-big-endian-nobom.xml
new file mode 100644
index 0000000..78dc012
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-big-endian-nobom.xml
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-32-little-endian-bom-expected.txt b/LayoutTests/fast/encoding/utf-32-little-endian-bom-expected.txt
new file mode 100644
index 0000000..9179de0
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-little-endian-bom-expected.txt
@@ -0,0 +1,5 @@
+When dumped into a text file by the test controller, this needs to be viewed as UTF-8:
+
+This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.
+
+Success : UTF-32LE
diff --git a/LayoutTests/fast/encoding/utf-32-little-endian-bom.html b/LayoutTests/fast/encoding/utf-32-little-endian-bom.html
new file mode 100644
index 0000000..2f566b4
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-little-endian-bom.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/utf-32-little-endian-nobom-expected.txt b/LayoutTests/fast/encoding/utf-32-little-endian-nobom-expected.txt
new file mode 100644
index 0000000..9179de0
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-little-endian-nobom-expected.txt
@@ -0,0 +1,5 @@
+When dumped into a text file by the test controller, this needs to be viewed as UTF-8:
+
+This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.
+
+Success : UTF-32LE
diff --git a/LayoutTests/fast/encoding/utf-32-little-endian-nobom.xml b/LayoutTests/fast/encoding/utf-32-little-endian-nobom.xml
new file mode 100644
index 0000000..af7a8f9
--- /dev/null
+++ b/LayoutTests/fast/encoding/utf-32-little-endian-nobom.xml
Binary files differ
diff --git a/LayoutTests/fast/encoding/xmacroman-encoding-test.html b/LayoutTests/fast/encoding/xmacroman-encoding-test.html
new file mode 100644
index 0000000..92702e0
--- /dev/null
+++ b/LayoutTests/fast/encoding/xmacroman-encoding-test.html
Binary files differ
diff --git a/LayoutTests/fast/encoding/xml-charset-utf16-expected.txt b/LayoutTests/fast/encoding/xml-charset-utf16-expected.txt
new file mode 100644
index 0000000..4da5ba0
--- /dev/null
+++ b/LayoutTests/fast/encoding/xml-charset-utf16-expected.txt
@@ -0,0 +1 @@
+This should look like a Roman ‘B’: ‘В’.
diff --git a/LayoutTests/fast/encoding/xml-charset-utf16.html b/LayoutTests/fast/encoding/xml-charset-utf16.html
new file mode 100644
index 0000000..8257726
--- /dev/null
+++ b/LayoutTests/fast/encoding/xml-charset-utf16.html
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-16"?>
+<html>
+<head>
+<meta content="text/html; charset=windows-1251" http-equiv="Content-Type">
+</meta>
+</head>
+<body>
+This should look like a Roman ‘B’: ‘Â’.
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/xml-utf-8-default-expected.txt b/LayoutTests/fast/encoding/xml-utf-8-default-expected.txt
new file mode 100644
index 0000000..04a1c26
--- /dev/null
+++ b/LayoutTests/fast/encoding/xml-utf-8-default-expected.txt
@@ -0,0 +1,3 @@
+When dumped into a text file by the test controller, this needs to be viewed as UTF-8:
+
+This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.
diff --git a/LayoutTests/fast/encoding/xml-utf-8-default.xml b/LayoutTests/fast/encoding/xml-utf-8-default.xml
new file mode 100644
index 0000000..1f07505
--- /dev/null
+++ b/LayoutTests/fast/encoding/xml-utf-8-default.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<body>
+<p>When dumped into a text file by the test controller, this needs to be viewed as UTF-8:</p>
+<p>This is an em dash, —, this is is a delta symbol, ∆, this is an uppercase pi, ∏, and this is a lowercase pi, π.</p>
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/yahoo-mail-expected.txt b/LayoutTests/fast/encoding/yahoo-mail-expected.txt
new file mode 100644
index 0000000..89ac9f6
--- /dev/null
+++ b/LayoutTests/fast/encoding/yahoo-mail-expected.txt
@@ -0,0 +1,3 @@
+Test a particular example of broken markup that was making us ignore a charset declaration.
+
+Encoding: UTF-8 (should be UTF-8)
diff --git a/LayoutTests/fast/encoding/yahoo-mail.html b/LayoutTests/fast/encoding/yahoo-mail.html
new file mode 100644
index 0000000..82331c8
--- /dev/null
+++ b/LayoutTests/fast/encoding/yahoo-mail.html
@@ -0,0 +1,26 @@
+<html>
+<head>
+		<title>
+Yahoo! Mail - someone@yahoo.com</title>
+</head>
+<body>
+
+<div id=yiv1034332614><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html
+><head><meta http-equiv="content-type"
+ content="text/html; charset=UTF-8"/></head>
+
+<p>Test a particular example of broken markup that was making us ignore a charset declaration.</p>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  var charset = document.characterSet;
+  if (!charset)
+    charset = document.charset;
+  if (!charset)
+    charset = document.inputEncoding;
+  document.write("Encoding: " + charset + " (should be UTF-8)");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/yentest-expected.txt b/LayoutTests/fast/encoding/yentest-expected.txt
new file mode 100644
index 0000000..341a23a
--- /dev/null
+++ b/LayoutTests/fast/encoding/yentest-expected.txt
@@ -0,0 +1,3 @@
+two backslashes external: \
+two backslashes inline: \
+
diff --git a/LayoutTests/fast/encoding/yentest.html b/LayoutTests/fast/encoding/yentest.html
new file mode 100644
index 0000000..a3a2a17
--- /dev/null
+++ b/LayoutTests/fast/encoding/yentest.html
@@ -0,0 +1,15 @@
+<HTML>
+<HEAD>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=shift-jis">
+<script src="resources/yentestexternal.js" type="text/javascript"></script>
+</HEAD>
+<BODY>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+writeYenExternal();
+document.write("two backslashes inline: " + "\\" + "<br>");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/encoding/yentest2-expected.txt b/LayoutTests/fast/encoding/yentest2-expected.txt
new file mode 100644
index 0000000..95557a3
--- /dev/null
+++ b/LayoutTests/fast/encoding/yentest2-expected.txt
@@ -0,0 +1,5 @@
+two backslashes external: \ 
+one backslash external: 
+two backslashes inline: \ 
+one backslash inline: 
+
diff --git a/LayoutTests/fast/encoding/yentest2.html b/LayoutTests/fast/encoding/yentest2.html
new file mode 100644
index 0000000..132069c
--- /dev/null
+++ b/LayoutTests/fast/encoding/yentest2.html
@@ -0,0 +1,16 @@
+<HTML>
+<HEAD>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=shift-jis">
+<script src="resources/yentestexternal2.js" type="text/javascript"></script>
+</HEAD>
+<BODY>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+writeYenExternal();
+document.write("two backslashes inline: \\ <br>");
+document.write("one backslash inline: \ <br>");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/android/test_expectations.txt b/LayoutTests/platform/android/test_expectations.txt
index aa87b25..021b97d 100644
--- a/LayoutTests/platform/android/test_expectations.txt
+++ b/LayoutTests/platform/android/test_expectations.txt
@@ -43,6 +43,11 @@
 // This first block of tests are for features for which Android
 // should pass all tests. They are skipped only temporarily.
 // TODO: Fix these failing tests and remove them from this list.
+fast/encoding/char-encoding.html FAIL // fails in Java HTTP stack, see http://b/issue?id=3047156
+fast/encoding/char-decoding.html FAIL // fails in Java HTTP stack, see http://b/issue?id=3047156
+fast/encoding/hanarei-blog32-fc2-com.html FAIL // fails in Java HTTP stack, see http://b/issue?id=3046986
+fast/encoding/mailto-always-utf-8.html FAIL // Requires waitForPolicyDelegate(), see http://b/issue?id=3043468
+fast/encoding/percent-escaping.html FAIL // fails in Java HTTP stack, see http://b/issue?id=3046984
 fast/events/touch/basic-multi-touch-events.html FAIL // Requires multi-touch
 fast/events/touch/touch-target.html FAIL // Requires multi-touch
 http/tests/appcache/empty-manifest.html FAIL // flaky
@@ -60,6 +65,9 @@
 storage/transaction-success-callback-isolated-world.html FAIL // Requires layoutTestController.evaluateScriptInIsolatedWorld()
 
 // Expected failures due to unsupported features.
+fast/encoding/char-decoding-mac.html FAIL // Mac-specific encodings (also marked Won't Fix in Chromium, bug 7388)
+fast/encoding/char-encoding-mac.html FAIL // Mac-specific encodings (also marked Won't Fix in Chromium, bug 7388)
+fast/encoding/idn-security.html FAIL // Mac-specific IDN checks (also marked Won't Fix in Chromium, bug 21814)
 fast/events/touch/touch-coords-in-zoom-and-scroll.html FAIL // Requires eventSender.zoomPageIn(),zoomPageOut()
 fast/workers FAIL // workers not supported
 http/tests/eventsource/workers FAIL // workers not supported