Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: LayoutTests/fast/encoding/api/basics.html

Issue 15901002: Implement Encoding API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebaseline webexposed global constructor tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/encoding/api/basics.html
diff --git a/LayoutTests/fast/encoding/api/basics.html b/LayoutTests/fast/encoding/api/basics.html
new file mode 100644
index 0000000000000000000000000000000000000000..1aec2159828559684aa27dc6762293db28231273
--- /dev/null
+++ b/LayoutTests/fast/encoding/api/basics.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+
+description("This tests the basics of the Encoding API.");
+
+shouldBeTrue("'TextEncoder' in window");
+shouldBeTrue("'TextDecoder' in window");
+
+shouldBeTrue("'encoding' in new TextEncoder");
+shouldBeTrue("'encoding' in new TextDecoder");
+
+shouldBeEqualToString("typeof (new TextEncoder).encoding", "string");
+shouldBeEqualToString("typeof (new TextDecoder).encoding", "string");
+
+shouldBeTrue("'encode' in new TextEncoder");
+shouldBeTrue("'decode' in new TextDecoder");
+
+shouldBeEqualToString("typeof (new TextEncoder).encode", "function");
+shouldBeEqualToString("typeof (new TextDecoder).decode", "function");
+
+
+shouldBeEqualToString("(new TextEncoder).encoding", "utf-8");
+shouldBeEqualToString("(new TextDecoder).encoding", "utf-8");
+
+function toArray(arrayLike) {
+ return [].map.call(arrayLike, function(x) { return x; });
+}
+
+function testEncodeDecodeSample(encoding, string, bytes) {
+ debug("");
+ debug("test encode/decode sample - " + encoding);
+
+ evalAndLog("encoded = new TextEncoder('" + encoding + "').encode(" + JSON.stringify(string) + ")");
+ shouldBeEqualToString("JSON.stringify(toArray(encoded))", JSON.stringify(bytes));
+ shouldBeEqualToString("new TextDecoder('" + encoding + "').decode(new Uint8Array(" + JSON.stringify(bytes) + "))", string);
+}
+
+testEncodeDecodeSample(
+ "utf-8",
+ "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Private-use character
+ [0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0, 0x9D, 0x84, 0x9E, 0xF4, 0x8F, 0xBF, 0xBD]
+);
+testEncodeDecodeSample(
+ "utf-16le",
+ "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Private-use character
+ [0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xDB, 0xFD, 0xDF]
+);
+testEncodeDecodeSample(
+ "utf-16be",
+ "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Private-use character
+ [0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34, 0xD8, 0x34, 0xDD, 0x1E, 0xDB, 0xFF, 0xDF, 0xFD]
+);
+testEncodeDecodeSample(
+ "utf-16",
+ "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Private-use character
+ [0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xDB, 0xFD, 0xDF]
+);
+
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
« no previous file with comments | « LayoutTests/fast/encoding/api/ascii-supersets-expected.txt ('k') | LayoutTests/fast/encoding/api/basics-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698