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

Side by Side Diff: LayoutTests/fast/encoding/api/surrogate-pairs.html

Issue 240283013: Convert Encoding API tests to W3C testharness.js (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../../resources/js-test.js"></script> 2 <title>Encoding API: Invalid UTF-16 surrogate pairs with UTF-8 encoding</title>
3 <script src="../../../resources/testharness.js"></script>
4 <script src="../../../resources/testharnessreport.js"></script>
3 <script> 5 <script>
4 6
5 description("Test invalid UTF-16 surrogate pairs with UTF-8 encoding");
6
7 var badStrings = [ 7 var badStrings = [
8 { input: "'abc123'", expected: [97, 98, 99, 49, 50, 51] }, // Sanity check. 8 {
9 { input: "'\\ud800'", expected: [0xef, 0xbf, 0xbd] }, // Surrogate half. 9 input: 'abc123',
10 { input: "'\\udc00'", expected: [0xef, 0xbf, 0xbd] }, // Surrogate half. 10 expected: [97, 98, 99, 49, 50, 51],
jungshik at Google 2014/04/29 16:51:04 nit: Would you use hexadecimal here, too?
jsbell 2014/04/29 21:41:18 Done.
11 { input: "'abc\\ud800123'", expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0 x31, 0x32, 0x33] }, // Surrogate half. 11 decoded: 'abc123',
12 { input: "'abc\\udc00123'", expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0 x31, 0x32, 0x33] }, // Surrogate half. 12 name: 'Sanity check'
13 { input: "'\\udc00\\ud800'", expected: [239, 191, 189, 239, 191, 189] } // Wrong order. 13 },
14 {
15 input: '\uD800',
16 expected: [0xef, 0xbf, 0xbd],
17 decoded: '\uFFFD',
18 name: 'Surrogate half (low)'
19 },
20 {
21 input: '\uDC00',
22 expected: [0xef, 0xbf, 0xbd],
23 decoded: '\uFFFD',
24 name: 'Surrogate half (high)'
25 },
26 {
27 input: 'abc\uD800123',
28 expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
29 decoded: 'abc\uFFFD123',
30 name: 'Surrogate half (low), in a string'
31 },
32 {
33 input: 'abc\uDC00123',
34 expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
35 decoded: 'abc\uFFFD123',
36 name: 'Surrogate half (high), in a string'
37 },
38 {
39 input: '\uDC00\uD800',
40 expected: [239, 191, 189, 239, 191, 189],
jsbell 2014/04/29 21:41:18 Here too.
41 decoded: '\uFFFD\uFFFD',
42 name: 'Wrong order'
43 }
14 ]; 44 ];
15 45
16 badStrings.forEach( 46 badStrings.forEach(function(t) {
17 function(t) { 47 test(function() {
18 evalAndLog("encoded = new TextEncoder('utf-8').encode(" + t.input + ")") ; 48 var encoded = new TextEncoder('utf-8').encode(t.input);
19 shouldBeEqualToString("JSON.stringify([].slice.call(encoded))", JSON.str ingify(t.expected)); 49 assert_array_equals([].slice.call(encoded), t.expected);
20 debug(""); 50 assert_equals(new TextDecoder('utf-8').decode(encoded), t.decoded);
21 }); 51 }, 'Invalid surrogate pairs encoded into UTF-8: ' + t.name);
52 });
22 53
23 </script> 54 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698