Skip to content

Commit

Permalink
Test query encoding of attributes separately
Browse files Browse the repository at this point in the history
This also changes how we test the ping IDL attribute as the HTML Standard
does not require it to be reflected other than as a string. It also adds
testing for <area>.

Helps with #4934.
  • Loading branch information
annevk committed May 24, 2018
1 parent dd43ad0 commit 81c2899
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!doctype html>
<meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is 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/rendering.html#the-page>
<link rel=help href=https://html.spec.whatwg.org/multipage/rendering.html#tables-2>
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -49,55 +49,6 @@ onload = function() {
test_obj.step_timeout(poll, 200);
}

// background attribute, check with getComputedStyle
function test_background(tag) {
var spec_url = 'https://html.spec.whatwg.org/multipage/rendering.html';
spec_url += tag == 'body' ? '#the-page' : '#tables';
test(function() {
var elm = document.createElement(tag);
document.body.appendChild(elm);
this.add_cleanup(function() {
document.body.removeChild(elm);
});
elm.setAttribute('background', input_url_png);
var got = getComputedStyle(elm).backgroundImage;
assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got));
}, 'getComputedStyle <'+tag+' background>',
{help:spec_url});
}

'body, table, thead, tbody, tfoot, tr, td, th'.split(', ').forEach(function(str) {
test_background(str);
});

// get a reflecting IDL attributes whose content attribute takes a URL or a list of space-separated URLs
function test_reflecting(tag, attr, idlAttr, multiple) {
idlAttr = idlAttr || attr;
var input = input_url_html;
if (multiple) {
input += ' ' + input;
}
test(function() {
var elm = document.createElement(tag);
assert_true(idlAttr in elm, idlAttr + ' is not supported');
elm.setAttribute(attr, input);
var got = elm[idlAttr];
assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got));
}, 'Getting <'+tag+'>.'+idlAttr + (multiple ? ' (multiple URLs)' : ''),
{help:'https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes'});
}

('iframe src, a 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(function(str) {
var arr = str.split(' ');
test_reflecting(arr[0], arr[1], arr[2]);
});

'a ping'.split(', ').forEach(function(str) {
var arr = str.split(' ');
test_reflecting(arr[0], arr[1], arr[2], true);
});

function setup_navigation(elm, iframe, id, test_obj) {
iframe.name = id;
elm.target = id;
Expand Down

0 comments on commit 81c2899

Please sign in to comment.