Skip to content

Commit

Permalink
HTML: split out navigation tests for URL query-encoding tests
Browse files Browse the repository at this point in the history
Part of #11269 and #4934.
  • Loading branch information
zcorpan committed Jun 1, 2018
1 parent b14e923 commit 596c572
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 99 deletions.
@@ -0,0 +1,129 @@
<!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>
<script src="/common/utils.js"></script>
<link rel=help href=https://html.spec.whatwg.org/multipage/#following-hyperlinks>
<link rel=help href=https://html.spec.whatwg.org/multipage/#hyperlink-auditing>
<link rel=help href=https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-refresh>
<div id=log></div>
<script>
function expected(encoding) {
return {
"UTF-8": "%C3%BF",
"windows-1251": "%26%23255%3B",
"windows-1252": "%FF"
}[encoding];
}
var encoding = document.characterSet;
var blank = 'resources/blank.py?encoding=' + encoding;
var stash_put = 'resources/stash.py?q=\u00FF&action=put&id=';
var stash_take = 'resources/stash.py?action=take&id=';
var input_url_html = 'resources/resource.py?q=\u00FF&encoding=' + encoding + '&type=html';
var expected_current = expected(encoding);
var expected_utf8 = expected('UTF-8');

function assert_ends_with(input, endsWith) {
assert_true(input.endsWith(endsWith), input + " did not end with " + endsWith);
}


function poll_for_stash(test_obj, uuid, expected) {
var start = new Date();
var poll = test_obj.step_func(function () {
var xhr = new XMLHttpRequest();
xhr.open('GET', stash_take + uuid);
xhr.onload = test_obj.step_func(function(e) {
if (xhr.response == "") {
if (new Date() - start > 10000) {
// If we set the status to TIMEOUT here we avoid a race between the
// page and the test timing out
test_obj.force_timeout();
}
test_obj.step_timeout(poll, 200);
} else {
assert_equals(xhr.response, expected);
test_obj.done();
}
});
xhr.send();
})
test_obj.step_timeout(poll, 200);
}

function setup_navigation(elm, iframe, id, test_obj) {
iframe.name = id;
elm.target = id;
elm.setAttribute('href', input_url_html);
document.body.appendChild(iframe);
document.body.appendChild(elm);
test_obj.add_cleanup(function() {
document.body.removeChild(iframe);
document.body.removeChild(elm);
});
}

// follow hyperlink
function test_follow_link(tag) {
async_test(function() {
var elm = document.createElement(tag);
var iframe = document.createElement('iframe');
setup_navigation(elm, iframe, 'test_follow_link_'+tag, this);
iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded
assert_equals(iframe.contentDocument.body.textContent, expected_current);
});
// follow the hyperlink
elm.click();
// check that navigation succeeded by ...??? XXX
}, 'follow hyperlink <'+tag+' href>');
}

'a, area, link'.split(', ').forEach(function(str) {
test_follow_link(str);
});

// follow hyperlink with ping attribute
function test_follow_link_ping(tag) {
async_test(function() {
var uuid = token();
var elm = document.createElement(tag);
// check if ping is supported
assert_true('ping' in elm, 'ping not supported');
elm.setAttribute('ping', stash_put + uuid);
var iframe = document.createElement('iframe');
setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this);
// follow the hyperlink
elm.click();
// check that navigation succeeded by ...??? XXX
// check that the right URL was requested for the ping
poll_for_stash(this, uuid, expected_current);
}, 'hyperlink auditing <'+tag+' ping>');
}

'a, area'.split(', ').forEach(function(str) {
test_follow_link_ping(str);
});

// navigating with meta refresh
async_test(function() {
var iframe = document.createElement('iframe');
iframe.src = blank;
document.body.appendChild(iframe);
this.add_cleanup(function() {
document.body.removeChild(iframe);
});
iframe.onload = this.step_func_done(function() {
var doc = iframe.contentDocument;
var got = doc.body.textContent;
if (got == '') {
doc.write('<meta http-equiv=refresh content="0; URL='+input_url_html+'">REFRESH');
doc.close();
return;
}
assert_equals(got, expected_current);
});
}, 'meta refresh');

</script>
Expand Up @@ -26,105 +26,6 @@ onload = function() {
return 'expected substring '+expected+' got '+got;
}

function poll_for_stash(test_obj, uuid, expected) {
var start = new Date();
var poll = test_obj.step_func(function () {
var xhr = new XMLHttpRequest();
xhr.open('GET', stash_take + uuid);
xhr.onload = test_obj.step_func(function(e) {
if (xhr.response == "") {
if (new Date() - start > 10000) {
// If we set the status to TIMEOUT here we avoid a race between the
// page and the test timing out
test_obj.force_timeout();
}
test_obj.step_timeout(poll, 200);
} else {
assert_equals(xhr.response, expected);
test_obj.done();
}
});
xhr.send();
})
test_obj.step_timeout(poll, 200);
}

function setup_navigation(elm, iframe, id, test_obj) {
iframe.name = id;
elm.target = id;
elm.setAttribute('href', input_url_html);
document.body.appendChild(iframe);
document.body.appendChild(elm);
test_obj.add_cleanup(function() {
document.body.removeChild(iframe);
document.body.removeChild(elm);
});
}

// follow hyperlink
function test_follow_link(tag) {
async_test(function() {
var elm = document.createElement(tag);
var iframe = document.createElement('iframe');
setup_navigation(elm, iframe, 'test_follow_link_'+tag, this);
iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded
assert_equals(iframe.contentDocument.body.textContent, expected_current);
});
// follow the hyperlink
elm.click();
// check that navigation succeeded by ...??? XXX
}, 'follow hyperlink <'+tag+' href>',
{help:'https://html.spec.whatwg.org/multipage/#following-hyperlinks'});
}

'a, area, link'.split(', ').forEach(function(str) {
test_follow_link(str);
});

// follow hyperlink with ping attribute
function test_follow_link_ping(tag) {
async_test(function() {
var uuid = token();
var elm = document.createElement(tag);
// check if ping is supported
assert_true('ping' in elm, 'ping not supported');
elm.setAttribute('ping', stash_put + uuid);
var iframe = document.createElement('iframe');
setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this);
// follow the hyperlink
elm.click();
// check that navigation succeeded by ...??? XXX
// check that the right URL was requested for the ping
poll_for_stash(this, uuid, expected_current);
}, 'hyperlink auditing <'+tag+' ping>',
{help:'https://html.spec.whatwg.org/multipage/#hyperlink-auditing'});
}

'a, area'.split(', ').forEach(function(str) {
test_follow_link_ping(str);
});

// navigating with meta refresh
async_test(function() {
var iframe = document.createElement('iframe');
iframe.src = blank;
document.body.appendChild(iframe);
this.add_cleanup(function() {
document.body.removeChild(iframe);
});
iframe.onload = this.step_func_done(function() {
var doc = iframe.contentDocument;
var got = doc.body.textContent;
if (got == '') {
doc.write('<meta http-equiv=refresh content="0; URL='+input_url_html+'">REFRESH');
doc.close();
return;
}
assert_equals(got, expected_current);
});
}, 'meta refresh',
{help:'https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-refresh'});

// loading html (or actually svg to support <embed>)
function test_load_nested_browsing_context(tag, attr, spec_url) {
async_test(function() {
Expand Down

0 comments on commit 596c572

Please sign in to comment.