Skip to content

Commit 865a920

Browse files
authored
URL and HTML: correct protocol setter tests
For whatwg/url#609.
1 parent 64406f0 commit 865a920

File tree

4 files changed

+86
-19
lines changed

4 files changed

+86
-19
lines changed

Diff for: html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
[
1010
'x',
1111
'data',
12-
// 'mailto' opens an email client in Firefox...
12+
// 'mailto' opens an email client in Chrome and Firefox and then ends up passing anyway...
1313
'file',
1414
'ftp',
1515
'http+x'
1616
].forEach((val) => {
1717
async_test((t) => {
1818
// HTTP URL <iframe>
1919
const frame = document.createElement("iframe")
20+
t.add_cleanup(() => frame.remove())
2021
frame.src = "/common/blank.html"
2122
frame.onload = t.step_func(() => {
2223
frame.contentWindow.location.protocol = val
@@ -25,14 +26,17 @@
2526
assert_equals(frame.contentWindow.location.host, location.host)
2627
assert_equals(frame.contentWindow.location.port, location.port)
2728
t.done()
28-
}, 500)
29+
// Matches the timeout from location-protocol-setter-non-broken-weird.html which suggests
30+
// that 4 seconds is enough for a navigation to complete.
31+
}, 4000)
2932
})
3033
document.body.appendChild(frame)
3134
}, "Set HTTP URL frame location.protocol to " + val)
3235

3336
async_test((t) => {
3437
// data URL <iframe>
3538
const dataFrame = document.createElement("iframe")
39+
t.add_cleanup(() => dataFrame.remove())
3640
const channel = new MessageChannel()
3741
dataFrame.src = `data:text/html,<script>
3842
onmessage = (e) => {
@@ -42,7 +46,7 @@
4246
} catch(e) {
4347
result = true
4448
}
45-
setTimeout(() => e.ports[0].postMessage([result, location.protocol]), 100)
49+
setTimeout(() => e.ports[0].postMessage([result, location.protocol]), 4000)
4650
}
4751
<\/script>`
4852
dataFrame.onload = t.step_func(() => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<title>Set location.protocol to the scheme it already was</title>
3+
<script src=/resources/testharness.js></script>
4+
<script src=/resources/testharnessreport.js></script>
5+
<div id=log></div>
6+
<iframe src=/common/blank.html></iframe>
7+
<iframe src=/common/blank.html></iframe>
8+
<iframe src=/common/blank.html></iframe>
9+
<iframe src=/common/blank.html></iframe>
10+
<script>
11+
self.onload = () => {
12+
[
13+
"http",
14+
"ht\x0Atp",
15+
"http\x0A",
16+
"\x09ht\x09\x0AtP"
17+
].forEach((val, index) => {
18+
async_test(t => {
19+
self[index].frameElement.onload = t.step_func_done(() => {
20+
assert_equals(self[index].location.protocol, "http:");
21+
});
22+
self[index].location.protocol = val;
23+
}, `Set location.protocol to ${encodeURI(val)} (percent-encoded here for clarity)`);
24+
});
25+
}
26+
</script>

Diff for: html/browsers/history/the-location-interface/location-protocol-setter.html

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<title>Set location.protocol to broken schemes</title>
2+
<title>Set location.protocol to schemes that throw</title>
33
<script src=/resources/testharness.js></script>
44
<script src=/resources/testharnessreport.js></script>
55
<div id=log></div>
@@ -32,14 +32,13 @@
3232
}
3333
</script>"></iframe>
3434
<script>
35-
// Tests with '\x0A' (i.e., '\n') don't conform to the URL Standard as of the
36-
// time of writing, as according to spec they should be ignored.
37-
// See https://github.com/whatwg/url/issues/609.
38-
39-
let broken = [
35+
const broken = [
4036
'\x00',
4137
'\x01',
42-
'\x0A',
38+
'\x09', // becomes the empty string
39+
'\x0A', // becomes the empty string
40+
'\x0C',
41+
'\x0D',
4342
'\x20',
4443
'\x21',
4544
'\x7F',
@@ -49,7 +48,6 @@
4948
'†',
5049
'\x00x',
5150
'\x01x',
52-
'\x0Ax',
5351
'\x20x',
5452
'\x21x',
5553
'\x7Fx',
@@ -59,7 +57,6 @@
5957
'†x',
6058
'\x00X',
6159
'\x01X',
62-
'\x0AX',
6360
'\x20X',
6461
'\x21X',
6562
'\x7FX',
@@ -69,7 +66,6 @@
6966
'†X',
7067
'x\x00',
7168
'x\x01',
72-
'x\x0A',
7369
'x\x20',
7470
'x\x21',
7571
'x\x7F',
@@ -78,20 +74,18 @@
7874
'x†',
7975
'X\x00',
8076
'X\x01',
81-
'X\x0A',
8277
'X\x20',
8378
'X\x21',
8479
'X\x7F',
8580
'X\x80',
8681
'X\xFF',
8782
'X†',
88-
'a\x0A',
89-
'a+-.\x0A'
90-
]
91-
;broken.forEach((val) => {
83+
];
84+
85+
broken.forEach(val => {
9286
test(() => {
9387
assert_throws_dom("SyntaxError", () => { location.protocol = val })
94-
}, encodeURI(val) + " (percent-encoded) is not a scheme")
88+
}, `${encodeURI(val)} (percent-encoded here for clarity) is not a scheme`)
9589
})
9690
let c = 0
9791
async_test((t) => {

Diff for: url/resources/setters_tests.json

+43
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,49 @@
269269
"protocol": "https:",
270270
"port": ""
271271
}
272+
},
273+
{
274+
"comment": "Tab and newline are stripped",
275+
"href": "http://test/",
276+
"new_value": "h\u000A\u000Att\u0009ps",
277+
"expected": {
278+
"href": "https://test/",
279+
"protocol": "https:",
280+
"port": ""
281+
}
282+
},
283+
{
284+
"comment": "Non-tab/newline C0 controls result in no-op",
285+
"href": "http://test/",
286+
"new_value": "https\u0000",
287+
"expected": {
288+
"href": "http://test/",
289+
"protocol": "http:"
290+
}
291+
},
292+
{
293+
"href": "http://test/",
294+
"new_value": "https\u000C",
295+
"expected": {
296+
"href": "http://test/",
297+
"protocol": "http:"
298+
}
299+
},
300+
{
301+
"href": "http://test/",
302+
"new_value": "https\u000D",
303+
"expected": {
304+
"href": "http://test/",
305+
"protocol": "http:"
306+
}
307+
},
308+
{
309+
"href": "http://test/",
310+
"new_value": "https\u0020",
311+
"expected": {
312+
"href": "http://test/",
313+
"protocol": "http:"
314+
}
272315
}
273316
],
274317
"username": [

0 commit comments

Comments
 (0)