gecko-dev/testing/web-platform/tests/encoding/resources/decoding-helpers.js
James Graham 2dc7a68af1 Bug 1386604 - Update web-platform-tests to revision 8b5316ad93c6c1238eea26a3d8052e32b34bbabd, a=testonly
MozReview-Commit-ID: 3HXcvTYpAkA


--HG--
rename : testing/web-platform/tests/fonts/matching/README.md => testing/web-platform/tests/css-fonts/matching/README.md
rename : testing/web-platform/tests/fonts/matching/fixed-stretch-style-over-weight-ref.html => testing/web-platform/tests/css-fonts/matching/fixed-stretch-style-over-weight-ref.html
rename : testing/web-platform/tests/fonts/matching/fixed-stretch-style-over-weight.html => testing/web-platform/tests/css-fonts/matching/fixed-stretch-style-over-weight.html
rename : testing/web-platform/tests/fonts/matching/font-matching.css => testing/web-platform/tests/css-fonts/matching/font-matching.css
rename : testing/web-platform/tests/fonts/matching/resources/variabletest_matching.ttf => testing/web-platform/tests/css-fonts/matching/resources/variabletest_matching.ttf
rename : testing/web-platform/tests/fonts/matching/stretch-distance-over-weight-distance-ref.html => testing/web-platform/tests/css-fonts/matching/stretch-distance-over-weight-distance-ref.html
rename : testing/web-platform/tests/fonts/matching/stretch-distance-over-weight-distance.html => testing/web-platform/tests/css-fonts/matching/stretch-distance-over-weight-distance.html
rename : testing/web-platform/tests/fonts/matching/style-ranges-over-weight-direction-ref.html => testing/web-platform/tests/css-fonts/matching/style-ranges-over-weight-direction-ref.html
rename : testing/web-platform/tests/fonts/matching/style-ranges-over-weight-direction.html => testing/web-platform/tests/css-fonts/matching/style-ranges-over-weight-direction.html
rename : testing/web-platform/tests/payment-request/OWNERS => testing/web-platform/tests/payment-method-id/OWNERS
rename : testing/web-platform/tests/storage/interfaces.worker.js => testing/web-platform/tests/storage/interfaces.https.worker.js
rename : testing/web-platform/tests/tools/browserutils/requirements.txt => testing/web-platform/tests/tools/wpt/requirements.txt
rename : testing/web-platform/tests/tools/browserutils/utils.py => testing/web-platform/tests/tools/wpt/utils.py
rename : testing/web-platform/tests/tools/wptrunner/wptrunner/executors/reftest-wait.js => testing/web-platform/tests/tools/wptrunner/wptrunner/executors/reftest-wait_marionette.js
rename : testing/web-platform/tests/uievents/keyboard/key-manual.css => testing/web-platform/tests/uievents/keyboard/key.css
rename : testing/web-platform/tests/uievents/keyboard/key-manual.js => testing/web-platform/tests/uievents/keyboard/key.js
2017-08-03 11:31:54 +01:00

32 lines
1.1 KiB
JavaScript

// Decode an URL encoded string, using XHR and data: URL. Returns a Promise.
function decode(label, url_encoded_string) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest;
req.open('GET', `data:text/plain,${url_encoded_string}`);
req.overrideMimeType(`text/plain; charset="${label}"`);
req.send();
req.onload = () => resolve(req.responseText);
req.onerror = () => reject(new Error(req.statusText));
});
}
// Convert code units in a decoded string into: "U+0001/U+0002/...'
function to_code_units(string) {
return string.split('')
.map(unit => unit.charCodeAt(0))
.map(code => 'U+' + ('0000' + code.toString(16).toUpperCase()).slice(-4))
.join('/');
}
function decode_test(label,
url_encoded_input,
expected_code_units,
description) {
promise_test(() => {
return decode(label, url_encoded_input)
.then(decoded => to_code_units(decoded))
.then(actual => {
assert_equals(actual, expected_code_units, `Decoding with ${label}`);
});
}, description);
}