Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/infrastructure/urls/resolving-urls/query-encoding/attributes.sub.html?encoding=utf8 - WPT Dashboard Interop Dashboard
- /html/infrastructure/urls/resolving-urls/query-encoding/attributes.sub.html?encoding=windows-1252 - WPT Dashboard Interop Dashboard
- /html/infrastructure/urls/resolving-urls/query-encoding/attributes.sub.html?encoding=x-cp1251 - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is windows-1252 -->
<meta name=variant content="?encoding=windows-1252">
<meta name=variant content="?encoding=x-cp1251">
<meta name=variant content="?encoding=utf8">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<link rel=help href=https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes>
<div id=log></div>
<script>
function expected(encoding) {
return "?" + {
"UTF-8": "%C3%BF",
"windows-1251": "%26%23255%3B",
"windows-1252": "%FF"
}[encoding];
}
function assert_ends_with(input, endsWith) {
assert_true(input.endsWith(endsWith), input + " did not end with " + endsWith);
}
"body table thead tbody tfoot tr td th".split(" ").forEach(localName => {
test(t => {
const elm = document.createElement(localName);
document.body.appendChild(elm);
t.add_cleanup(() => { document.body.removeChild(elm); });
elm.setAttribute("background", "?\u00FF");
assert_ends_with(getComputedStyle(elm).backgroundImage, expected(document.characterSet) + "\")");
}, "getComputedStyle <" + localName + " background>");
});
function test_url_reflecting(localName, attr, idlAttr) {
idlAttr = idlAttr || attr;
test(() => {
let input = "?\u00FF";
const elm = document.createElement(localName);
assert_true(idlAttr in elm, idlAttr + " is not supported");
elm.setAttribute(attr, input);
assert_ends_with(elm[idlAttr], expected(document.characterSet));
}, "Getting <" + localName + ">." + idlAttr);
}
("iframe src, a href, area href, base href, link href, img src, embed src, object data, " +
"track src, video src, audio src, input src, form action, input formaction formAction, " +
"button formaction formAction, script src").split(", ").forEach(str => {
const arr = str.split(" ");
test_url_reflecting(arr[0], arr[1], arr[2]);
});
function test_string_reflecting(localName, attr) {
test(() => {
let input = "?\u00FF ?\u00FF";
const elm = document.createElement(localName);
assert_true(attr in elm, attr + " is not supported");
elm.setAttribute(attr, input);
assert_equals(elm[attr], input);
}, "Getting <" + localName + ">." + attr);
}
"a ping, area ping".split(", ").forEach(str => {
const arr = str.split(" ");
test_string_reflecting(arr[0], arr[1]);
});
</script>