| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../js/resources/js-test-pre.js"></script> |
| 3 <script> |
| 4 |
| 5 description("This tests the basics of the Encoding API."); |
| 6 |
| 7 shouldBeTrue("'TextEncoder' in window"); |
| 8 shouldBeTrue("'TextDecoder' in window"); |
| 9 |
| 10 shouldBeTrue("'encoding' in new TextEncoder"); |
| 11 shouldBeTrue("'encoding' in new TextDecoder"); |
| 12 |
| 13 shouldBeEqualToString("typeof (new TextEncoder).encoding", "string"); |
| 14 shouldBeEqualToString("typeof (new TextDecoder).encoding", "string"); |
| 15 |
| 16 shouldBeTrue("'encode' in new TextEncoder"); |
| 17 shouldBeTrue("'decode' in new TextDecoder"); |
| 18 |
| 19 shouldBeEqualToString("typeof (new TextEncoder).encode", "function"); |
| 20 shouldBeEqualToString("typeof (new TextDecoder).decode", "function"); |
| 21 |
| 22 |
| 23 shouldBeEqualToString("(new TextEncoder).encoding", "utf-8"); |
| 24 shouldBeEqualToString("(new TextDecoder).encoding", "utf-8"); |
| 25 |
| 26 function toArray(arrayLike) { |
| 27 return [].map.call(arrayLike, function(x) { return x; }); |
| 28 } |
| 29 |
| 30 function testEncodeDecodeSample(encoding, string, bytes) { |
| 31 debug(""); |
| 32 debug("test encode/decode sample - " + encoding); |
| 33 |
| 34 evalAndLog("encoded = new TextEncoder('" + encoding + "').encode(" + JSON.st
ringify(string) + ")"); |
| 35 shouldBeEqualToString("JSON.stringify(toArray(encoded))", JSON.stringify(byt
es)); |
| 36 shouldBeEqualToString("new TextDecoder('" + encoding + "').decode(new Uint8A
rray(" + JSON.stringify(bytes) + "))", string); |
| 37 } |
| 38 |
| 39 testEncodeDecodeSample( |
| 40 "utf-8", |
| 41 "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Privat
e-use character |
| 42 [0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0, 0x9D, 0x84, 0x9E, 0xF4, 0x8F, 0xB
F, 0xBD] |
| 43 ); |
| 44 testEncodeDecodeSample( |
| 45 "utf-16le", |
| 46 "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Privat
e-use character |
| 47 [0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xDB, 0xF
D, 0xDF] |
| 48 ); |
| 49 testEncodeDecodeSample( |
| 50 "utf-16be", |
| 51 "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Privat
e-use character |
| 52 [0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34, 0xD8, 0x34, 0xDD, 0x1E, 0xDB, 0xFF, 0xD
F, 0xFD] |
| 53 ); |
| 54 testEncodeDecodeSample( |
| 55 "utf-16", |
| 56 "z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD", // z, cent, CJK water, G-Clef, Privat
e-use character |
| 57 [0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xDB, 0xF
D, 0xDF] |
| 58 ); |
| 59 |
| 60 </script> |
| 61 <script src="../../js/resources/js-test-post.js"></script> |
| OLD | NEW |