Skip to content

Commit 578b680

Browse files
annevkrachelandrew
authored andcommitted
HTTP Refresh header
Tests for whatwg/html#2892.
1 parent 10ada10 commit 578b680

8 files changed

Lines changed: 90 additions & 35 deletions

File tree

html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
var tests_arr = [
1717
{input: '', expected: []},
18-
{input: '1', expected: [1, 'refresh.sub.html']},
19-
{input: '1 ', expected: [1, 'refresh.sub.html']},
20-
{input: '1\t', expected: [1, 'refresh.sub.html']},
21-
{input: '1\r', expected: [1, 'refresh.sub.html']},
22-
{input: '1\n', expected: [1, 'refresh.sub.html']},
23-
{input: '1\f', expected: [1, 'refresh.sub.html']},
24-
{input: '1;', expected: [1, 'refresh.sub.html']},
25-
{input: '1,', expected: [1, 'refresh.sub.html']},
18+
{input: '1', expected: [1, '__filename__']},
19+
{input: '1 ', expected: [1, '__filename__']},
20+
{input: '1\t', expected: [1, '__filename__']},
21+
{input: '1\r', expected: [1, '__filename__']},
22+
{input: '1\n', expected: [1, '__filename__']},
23+
{input: '1\f', expected: [1, '__filename__']},
24+
{input: '1;', expected: [1, '__filename__']},
25+
{input: '1,', expected: [1, '__filename__']},
2626
{input: '1; url=foo', expected: [1, 'foo']},
2727
{input: '1, url=foo', expected: [1, 'foo']},
2828
{input: '1 url=foo', expected: [1, 'foo']},
@@ -76,7 +76,7 @@
7676
{input: '-1', expected: []},
7777
{input: '+0', expected: []},
7878
{input: '-0', expected: []},
79-
{input: '0', expected: [0, 'refresh.sub.html']},
79+
{input: '0', expected: [0, '__filename__']},
8080
{input: '1.9; url=foo', expected: [1, 'foo']},
8181
{input: '1.9..5.; url=foo', expected: [1, 'foo']},
8282
{input: '.9; url=foo', expected: [0, 'foo']},
@@ -90,33 +90,43 @@
9090
];
9191

9292
tests_arr.forEach(function(test_obj) {
93-
async_test(function(t) {
94-
var iframe = document.createElement('iframe');
95-
t.add_cleanup(function() {
96-
document.body.removeChild(iframe);
97-
});
98-
iframe.src = 'support/refresh.sub.html?input=' + encodeURIComponent(test_obj.input);
99-
document.body.appendChild(iframe);
100-
var loadCount = 0;
101-
iframe.onload = t.step_func(function() {
102-
loadCount++;
103-
var got = iframe.contentDocument.body.textContent.trim();
104-
if (test_obj.expected.length === 0) {
105-
assert_equals(got, 'refresh.sub.html');
106-
if (loadCount === 1) {
107-
setTimeout(function() {
108-
t.done();
109-
}, 3000); // want to make sure it doesn't redirect when it shouldn't
93+
["<meta>", "Refresh header"].forEach(type => {
94+
if(type === "Refresh header" && test_obj.input.match("[\n\r\f]")) { // See https://github.com/w3c/wptserve/issues/111 for why \f as well
95+
return;
96+
}
97+
const filename = type === "<meta>" ? "refresh.sub.html" : "refresh.py";
98+
async_test(function(t) {
99+
var iframe = document.createElement('iframe');
100+
t.add_cleanup(function() {
101+
document.body.removeChild(iframe);
102+
});
103+
iframe.src = "support/" + filename + "?input=" + encodeURIComponent(test_obj.input);
104+
document.body.appendChild(iframe);
105+
var loadCount = 0;
106+
iframe.onload = t.step_func(function() {
107+
loadCount++;
108+
var got = iframe.contentDocument.body.textContent.trim();
109+
if (test_obj.expected.length === 0) {
110+
assert_equals(got, filename);
111+
if (loadCount === 1) {
112+
t.step_timeout(function() {
113+
t.done();
114+
}, 3000); // want to make sure it doesn't redirect when it shouldn't
115+
} else {
116+
assert_unreached('Got > 1 load events');
117+
}
110118
} else {
111-
assert_unreached('Got > 1 load events');
112-
}
113-
} else {
114-
if (loadCount === 2) {
115-
assert_equals(got, test_obj.expected[1]);
116-
t.done();
119+
if (loadCount === 2) {
120+
if(test_obj.expected[1] === "__filename__") {
121+
assert_equals(got, filename);
122+
} else {
123+
assert_equals(got, test_obj.expected[1]);
124+
}
125+
t.done();
126+
}
117127
}
118-
}
119-
});
120-
}, format_value(test_obj.input));
128+
});
129+
}, type + ": " + format_value(test_obj.input));
130+
});
121131
});
122132
</script>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def main(request, response):
2+
response.headers.set("Content-Type", "text/html")
3+
response.headers.set("Refresh", request.GET.first("input"))
4+
response.content = "<!doctype html>refresh.py\n"

http/refresh/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See `../../html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh/parsing.html` for more detailed parsing tests (shared with `<meta http-equiv=refresh>`).

http/refresh/navigate.window.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
async_test(t => {
2+
const frame = document.createElement("iframe");
3+
frame.src = "resources/refresh.py"
4+
frame.onload = t.step_func(() => {
5+
// Could be better by verifying that resources/refresh.py loads too
6+
if(frame.contentWindow.location.href === (new URL("resources/refreshed.txt?\u0080\u00FF", self.location)).href) { // Make sure bytes got mapped to code points of the same value
7+
t.done();
8+
}
9+
});
10+
document.body.appendChild(frame)
11+
}, "When navigating the Refresh header needs to be followed");
12+
13+
async_test(t => {
14+
const frame = document.createElement("iframe");
15+
frame.src = "resources/multiple.asis"
16+
frame.onload = t.step_func(() => {
17+
// Could be better by verifying that resources/refresh.py loads too
18+
if(frame.contentWindow.location.href === (new URL("resources/refreshed.txt", self.location)).href) {
19+
t.done();
20+
}
21+
});
22+
document.body.appendChild(frame)
23+
}, "When there's both a Refresh header and <meta> the Refresh header wins")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Refresh: 0,./refreshed.txt
3+
Content-Type:text/html
4+
5+
I don't understand.
6+
<meta http-equiv=refresh content=1;./>

http/refresh/resources/refresh.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def main(request, response):
2+
response.headers.set("Content-Type", "text/plain")
3+
response.headers.set("Refresh", "0;./refreshed.txt?\x80\xFF") # Test byte to Unicode conversion
4+
response.content = "Not refreshed.\n"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Have another.

http/refresh/subresource.any.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
promise_test(() => {
2+
return fetch("resources/refresh.py").then(response => {
3+
assert_equals(response.headers.get("refresh"), "0;./refreshed.txt?\u0080\u00FF"); // Make sure bytes got mapped to code points of the same value
4+
assert_equals(response.url, (new URL("resources/refresh.py", self.location)).href);
5+
});
6+
}, "Refresh does not affect subresources.");

0 commit comments

Comments
 (0)