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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/encoding/resources/char-decoding-utils.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function encode(charset, unicode) 1 let uniqueId = 0;
2 { 2 function encodeText(charsetName, unicode) {
3 // Returns a value already encoded, since we can't do it synchronously. 3 return new Promise((resolve, reject) => {
4 return results[charset][unicode]; 4 const frame_id = `subframe${++uniqueId}`;
5
6 const iframe = document.createElement('iframe');
7 iframe.style.display = 'none';
8 // |iframe.name| must be assigned before adding frame to the body or
9 // |form.target| will not find it.
10 iframe.name = frame_id;
11 document.body.appendChild(iframe);
12
13 const form = document.body.appendChild(document.createElement('form'));
14 form.style.display = 'none';
15 form.method = 'GET';
16 form.action = 'resources/dummy.html';
17 form.acceptCharset = charsetName;
18 form.target = frame_id;
19
20 const input = form.appendChild(document.createElement('input'));
21 input.type = 'text';
22 input.name = 'text';
23 input.value = String.fromCharCode(unicode.replace('U+', '0x'));
24
25 iframe.onload = () => {
26 const url = iframe.contentWindow.location.href;
27 const result = url.substr(url.indexOf('=') + 1);
28
29 iframe.remove();
30 form.remove();
31
32 resolve(result);
33 };
34 form.submit();
35 });
5 } 36 }
6 37
7 function testsDone() 38 function testEncode(charsetName, unicode, characterSequence) {
8 { 39 promise_test(t => {
9 var form = document.getElementById('form'); 40 return encodeText(charsetName, unicode).then(result => {
10 var subframe = document.getElementById('subframe'); 41 assert_equals(result, characterSequence);
11 42 });
12 form.parentNode.removeChild(form); 43 }, `Encode ${charsetName}: ${unicode} -> ${characterSequence}`);
13 subframe.parentNode.removeChild(subframe);
14
15 description("This tests encoding characters in various character sets.");
16
17 for (i = 0; i < charsets.length; ++i) {
18 shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + e xpectedResults[i] + "'");
19 }
20
21 if (window.testRunner)
22 testRunner.notifyDone();
23 } 44 }
24
25 function processResult(result)
26 {
27 var charsetResults = results[charsets[i]];
28 if (!charsetResults) {
29 charsetResults = new Object;
30 results[charsets[i]] = charsetResults;
31 }
32 charsetResults[unicodes[i]] = result;
33 }
34
35 function subframeLoaded()
36 {
37 var URL = "" + document.getElementById('subframe').contentWindow.location;
38 processResult(URL.substr(URL.indexOf('=') + 1));
39 ++i;
40 runTest();
41 }
42
43 function runTest()
44 {
45 if (i >= charsets.length) {
46 testsDone();
47 return;
48 }
49
50 var form = document.getElementById('form');
51 var text = document.getElementById('text');
52 var subframe = document.getElementById('subframe');
53
54 form.acceptCharset = charsets[i];
55 form.action = "resources/dummy.html";
56 subframe.onload = subframeLoaded;
57 text.value = String.fromCharCode(unicodes[i].replace('U+', '0x'));
58
59 form.submit();
60 }
61
62 function testEncode(charsetName, unicode, characterSequence)
63 {
64 charsets.push(charsetName);
65 unicodes.push(unicode);
66 expectedResults.push(characterSequence);
67 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/encoding/resources/char-decoding-utils.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698