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

Unified Diff: third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html

Issue 1862453003: [Blink>TextEncoder] Removed UTF-16 support from TextEncoder API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compositor-proxy-supports test Created 4 years, 6 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: third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html
diff --git a/third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html b/third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html
index b190fffd161cda862c6562aad8bacce8b5451270..58b363bf30f30e6100b3f14bb15b1782bb26d463 100644
--- a/third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html
+++ b/third_party/WebKit/LayoutTests/fast/encoding/api/utf-round-trip.html
@@ -31,16 +31,41 @@ function makeBatch(cp) {
}
utf_encodings.forEach(function(encoding) {
+ if (encoding === 'utf-8') {
+ test(function() {
+ for (var i = 0; i < 0x10FFFF; i += BATCH_SIZE) {
+ var string = makeBatch(i);
+ var encoded = new TextEncoder().encode(string);
+ var decoded = new TextDecoder(encoding).decode(encoded);
+ assert_equals(string, decoded);
+ }
+ }, encoding + ' - encode/decode round trip');
+ }
+});
+
+['utf-16le', 'utf-16be'].forEach(function(encoding) {
test(function() {
for (var i = 0; i < 0x10FFFF; i += BATCH_SIZE) {
var string = makeBatch(i);
- var encoded = new TextEncoder(encoding).encode(string);
+
+ if (encoding === 'utf-16le')
+ var encoded = encode_utf16(string, true);
+ else
+ var encoded = encode_utf16(string, false);
+
var decoded = new TextDecoder(encoding).decode(encoded);
- assert_equals(decoded, string);
+ assert_equals(string, decoded);
}
}, encoding + ' - encode/decode round trip');
});
+function encode_utf16(s, littleEndian) {
+ var a = new Uint8Array(s.length * 2), view = new DataView(a.buffer);
+ s.split('').forEach(function(c, i) {
+ view.setUint16(i * 2, c.charCodeAt(0), littleEndian);
+ });
+ return a;
+}
// Inspired by:
// http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
@@ -61,7 +86,7 @@ test(function() {
for (var i = 0; i < 0x10FFFF; i += BATCH_SIZE) {
var string = makeBatch(i);
var expected = encode_utf8(string);
- var actual = new TextEncoder('UTF-8').encode(string);
+ var actual = new TextEncoder().encode(string);
assert_array_equals(actual, expected);
}
}, 'UTF-8 encoding (compare against unescape/encodeURIComponent)');
@@ -71,9 +96,8 @@ test(function() {
var string = makeBatch(i);
var encoded = encode_utf8(string);
var expected = decode_utf8(encoded);
- var actual = new TextDecoder('UTF-8').decode(new Uint8Array(encoded));
+ var actual = new TextDecoder().decode(new Uint8Array(encoded));
assert_equals(actual, expected);
}
}, 'UTF-8 decoding (compare against decodeURIComponent/escape)');
-
-</script>
+</script>

Powered by Google App Engine
This is Rietveld 408576698