Skip to content

Commit

Permalink
Bug 1810968 [wpt PR 38032] - URL and HTML: correct protocol setter te…
Browse files Browse the repository at this point in the history
…sts, a=testonly

Automatic update from web-platform-tests
URL and HTML: correct protocol setter tests

For whatwg/url#609.
--

wpt-commits: 865a920dd12159c324560f482288094088cba1ce
wpt-pr: 38032
  • Loading branch information
annevk authored and moz-wptsync-bot committed Feb 1, 2023
1 parent 3438dd1 commit cadebbb
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
[
'x',
'data',
// 'mailto' opens an email client in Firefox...
// 'mailto' opens an email client in Chrome and Firefox and then ends up passing anyway...
'file',
'ftp',
'http+x'
].forEach((val) => {
async_test((t) => {
// HTTP URL <iframe>
const frame = document.createElement("iframe")
t.add_cleanup(() => frame.remove())
frame.src = "/common/blank.html"
frame.onload = t.step_func(() => {
frame.contentWindow.location.protocol = val
Expand All @@ -25,14 +26,17 @@
assert_equals(frame.contentWindow.location.host, location.host)
assert_equals(frame.contentWindow.location.port, location.port)
t.done()
}, 500)
// Matches the timeout from location-protocol-setter-non-broken-weird.html which suggests
// that 4 seconds is enough for a navigation to complete.
}, 4000)
})
document.body.appendChild(frame)
}, "Set HTTP URL frame location.protocol to " + val)

async_test((t) => {
// data URL <iframe>
const dataFrame = document.createElement("iframe")
t.add_cleanup(() => dataFrame.remove())
const channel = new MessageChannel()
dataFrame.src = `data:text/html,<script>
onmessage = (e) => {
Expand All @@ -42,7 +46,7 @@
} catch(e) {
result = true
}
setTimeout(() => e.ports[0].postMessage([result, location.protocol]), 100)
setTimeout(() => e.ports[0].postMessage([result, location.protocol]), 4000)
}
<\/script>`
dataFrame.onload = t.step_func(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<title>Set location.protocol to the scheme it already was</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<script>
self.onload = () => {
[
"http",
"ht\x0Atp",
"http\x0A",
"\x09ht\x09\x0AtP"
].forEach((val, index) => {
async_test(t => {
self[index].frameElement.onload = t.step_func_done(() => {
assert_equals(self[index].location.protocol, "http:");
});
self[index].location.protocol = val;
}, `Set location.protocol to ${encodeURI(val)} (percent-encoded here for clarity)`);
});
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<title>Set location.protocol to broken schemes</title>
<title>Set location.protocol to schemes that throw</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
Expand Down Expand Up @@ -32,14 +32,13 @@
}
</script>"></iframe>
<script>
// Tests with '\x0A' (i.e., '\n') don't conform to the URL Standard as of the
// time of writing, as according to spec they should be ignored.
// See https://github.com/whatwg/url/issues/609.

let broken = [
const broken = [
'\x00',
'\x01',
'\x0A',
'\x09', // becomes the empty string
'\x0A', // becomes the empty string
'\x0C',
'\x0D',
'\x20',
'\x21',
'\x7F',
Expand All @@ -49,7 +48,6 @@
'†',
'\x00x',
'\x01x',
'\x0Ax',
'\x20x',
'\x21x',
'\x7Fx',
Expand All @@ -59,7 +57,6 @@
'†x',
'\x00X',
'\x01X',
'\x0AX',
'\x20X',
'\x21X',
'\x7FX',
Expand All @@ -69,7 +66,6 @@
'†X',
'x\x00',
'x\x01',
'x\x0A',
'x\x20',
'x\x21',
'x\x7F',
Expand All @@ -78,20 +74,18 @@
'x†',
'X\x00',
'X\x01',
'X\x0A',
'X\x20',
'X\x21',
'X\x7F',
'X\x80',
'X\xFF',
'X†',
'a\x0A',
'a+-.\x0A'
]
;broken.forEach((val) => {
];

broken.forEach(val => {
test(() => {
assert_throws_dom("SyntaxError", () => { location.protocol = val })
}, encodeURI(val) + " (percent-encoded) is not a scheme")
}, `${encodeURI(val)} (percent-encoded here for clarity) is not a scheme`)
})
let c = 0
async_test((t) => {
Expand Down
43 changes: 43 additions & 0 deletions testing/web-platform/tests/url/resources/setters_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,49 @@
"protocol": "https:",
"port": ""
}
},
{
"comment": "Tab and newline are stripped",
"href": "http://test/",
"new_value": "h\u000A\u000Att\u0009ps",
"expected": {
"href": "https://test/",
"protocol": "https:",
"port": ""
}
},
{
"comment": "Non-tab/newline C0 controls result in no-op",
"href": "http://test/",
"new_value": "https\u0000",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u000C",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u000D",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u0020",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
}
],
"username": [
Expand Down

0 comments on commit cadebbb

Please sign in to comment.