Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-utils.js |
| diff --git a/third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-utils.js b/third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-utils.js |
| index 03d10e90a586bcd8151ef541ccb670714152c980..80bbaa63c3d7ef661f91f5f2038452bb550727dc 100644 |
| --- a/third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-utils.js |
| +++ b/third_party/WebKit/LayoutTests/fast/encoding/resources/char-encoding-utils.js |
| @@ -1,67 +1,45 @@ |
| -function encode(charset, unicode) |
| -{ |
| - // Returns a value already encoded, since we can't do it synchronously. |
| - return results[charset][unicode]; |
| -} |
| - |
| -function testsDone() |
| -{ |
| - var form = document.getElementById('form'); |
| - var subframe = document.getElementById('subframe'); |
| - |
| - form.parentNode.removeChild(form); |
| - subframe.parentNode.removeChild(subframe); |
| - |
| - description("This tests encoding characters in various character sets."); |
| - |
| - for (i = 0; i < charsets.length; ++i) { |
| - shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + expectedResults[i] + "'"); |
| - } |
| - |
| - if (window.testRunner) |
| - testRunner.notifyDone(); |
| -} |
| - |
| -function processResult(result) |
| -{ |
| - var charsetResults = results[charsets[i]]; |
| - if (!charsetResults) { |
| - charsetResults = new Object; |
| - results[charsets[i]] = charsetResults; |
| - } |
| - charsetResults[unicodes[i]] = result; |
| -} |
| - |
| -function subframeLoaded() |
| -{ |
| - var URL = "" + document.getElementById('subframe').contentWindow.location; |
| - processResult(URL.substr(URL.indexOf('=') + 1)); |
| - ++i; |
| - runTest(); |
| -} |
| - |
| -function runTest() |
| -{ |
| - if (i >= charsets.length) { |
| - testsDone(); |
| - return; |
| - } |
| - |
| - var form = document.getElementById('form'); |
| - var text = document.getElementById('text'); |
| - var subframe = document.getElementById('subframe'); |
| - |
| - form.acceptCharset = charsets[i]; |
| - form.action = "resources/dummy.html"; |
| - subframe.onload = subframeLoaded; |
| - text.value = String.fromCharCode(unicodes[i].replace('U+', '0x')); |
| - |
| +let uniqueId = 0; |
| +function encodeText(charsetName, unicode) { |
| + return new Promise((resolve, reject) => { |
| + const frame_id = `subframe${++uniqueId}`; |
| + |
| + const iframe = document.createElement('iframe'); |
| + iframe.style.display = 'none'; |
| + // |iframe.name| must be assigned before adding frame to the body or |
| + // |form.target| will not find it. |
| + iframe.name = frame_id; |
| + document.body.appendChild(iframe); |
| + |
| + const form = document.body.appendChild(document.createElement('form')); |
| + form.style.display = 'none'; |
| + form.method = 'GET'; |
| + form.action = 'resources/dummy.html'; |
| + form.acceptCharset = charsetName; |
| + form.target = frame_id; |
| + |
| + const input = form.appendChild(document.createElement('input')); |
| + input.type = 'text'; |
| + input.setAttribute('name', 'text'); |
|
foolip
2016/10/04 09:35:18
input.name = 'text'?
jsbell
2016/10/04 17:41:39
Thanks - leftover from investigating why iframe.na
|
| + input.value = String.fromCharCode(unicode.replace('U+', '0x')); |
| + |
| + iframe.onload = e => { |
|
foolip
2016/10/04 09:35:18
e is unused, so ()?
jsbell
2016/10/04 17:41:39
Sure, done.
|
| + const url = String(iframe.contentWindow.location); |
|
foolip
2016/10/04 09:35:18
Maybe intentional, but iframe.contentWindow.locati
jsbell
2016/10/04 17:41:39
I don't believe it was intentional. Changed.
|
| + const result = url.substr(url.indexOf('=') + 1); |
| + |
| + iframe.remove(); |
| + form.remove(); |
| + |
| + resolve(result); |
| + }; |
| form.submit(); |
| + }); |
| } |
| -function testEncode(charsetName, unicode, characterSequence) |
| -{ |
| - charsets.push(charsetName); |
| - unicodes.push(unicode); |
| - expectedResults.push(characterSequence); |
| +function testEncode(charsetName, unicode, characterSequence) { |
| + promise_test(t => { |
| + return encodeText(charsetName, unicode).then(result => { |
| + assert_equals(result, characterSequence); |
| + t.done(); |
|
foolip
2016/10/04 09:35:18
t.done() ought not be needed with promise_test?
jsbell
2016/10/04 17:41:39
D'oh, was an async_test for a while. Thanks, remov
|
| + }); |
| + }, `Encode ${charsetName}: ${unicode} -> ${characterSequence}`); |
| } |