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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/encoding/resources/char-decoding-utils.js

Issue 2390083002: Text Encoding: Convert fast/encoding tests to testharness.js (Closed)
Patch Set: Review feedback Created 4 years, 2 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
OLDNEW
1 function decodeText(charsetName, characterSequence) 1 function decodeText(charsetName, characterSequence) {
2 { 2 return new Promise((resolve, reject) => {
3 var req = new XMLHttpRequest; 3 const req = new XMLHttpRequest;
4 req.open('GET', 'data:text/plain,' + characterSequence, false); 4 req.open('GET', `data:text/plain,${characterSequence}`);
5 req.overrideMimeType('text/plain; charset="' + charsetName + '"'); 5 req.overrideMimeType(`text/plain; charset="${charsetName}"`);
6 req.send(''); 6 req.send('');
7 return req.responseText; 7 req.onload = () => resolve(req.responseText);
8 req.onerror = () => reject(new Error(req.statusText));
9 });
8 } 10 }
9 11
10 function decode(charsetName, characterSequence) 12 function decode(charsetName, characterSequence) {
11 { 13 return decodeText(charsetName, characterSequence).then(decodedText => {
12 var decodedText = decodeText(charsetName, characterSequence); 14 return decodedText.split('')
13 var result = ""; 15 .map(char => char.charCodeAt(0))
14 for (var i = 0; i < decodedText.length; ++i) { 16 .map(code => 'U+' + ('0000' + code.toString(16).toUpperCase()).slice(-4))
15 var code = decodedText.charCodeAt(i).toString(16).toUpperCase(); 17 .join('/');
16 if (i) 18 });
17 result += "/";
18 result += "U+" + ("0000" + code).slice(-4);
19 }
20 return result;
21 } 19 }
22 20
23 function testDecode(charsetName, characterSequence, unicode) 21 function testDecode(charsetName, characterSequence, unicode) {
24 { 22 promise_test(t => {
25 shouldBe("decode('" + charsetName + "', '" + characterSequence + "')", "'" + unicode + "'"); 23 return decode(charsetName, characterSequence).then(result => {
24 assert_equals(result, unicode);
25 });
26 }, `Decode ${charsetName}: ${characterSequence} => ${unicode}`);
26 } 27 }
27 28
28 function batchTestDecode(inputData) 29 function batchTestDecode(inputData) {
29 { 30 for (let i in inputData.encodings) {
30 for (var i in inputData.encodings) { 31 for (let j in inputData.encoded) {
31 for (var j in inputData.encoded) 32 testDecode(inputData.encodings[i],
32 testDecode(inputData.encodings[i], inputData.encoded[j], inputData.u nicode[j]); 33 inputData.encoded[j],
34 inputData.unicode[j]);
33 } 35 }
36 }
34 } 37 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698