Skip to content

Commit

Permalink
Move JS-specific URL parser tests into their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker authored Jul 17, 2024
1 parent ca2f4d2 commit 2b9af57
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 28 deletions.
10 changes: 6 additions & 4 deletions url/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## urltestdata.json
## urltestdata.json / urltestdata-javascript-only.json

`resources/urltestdata.json` contains URL parsing tests suitable for any URL parser implementation.
`resources/urltestdata-javascript-only.json` contains URL parsing tests specifically meant
for JavaScript's `URL()` class as well as other languages accepting non-scalar-value strings.

It's used as a source of tests by `a-element.html`, `failure.html`, `url-constructor.any.js`, and
other test files in this directory.
These files are used as a source of tests by `a-element.html`, `failure.html`, `url-constructor.any.js`,
and other test files in this directory.

The format of `resources/urltestdata.json` is a JSON array of comments as strings and test cases as
Both files share the same format. They consist of a JSON array of comments as strings and test cases as
objects. The keys for each test case are:

* `input`: a string to be parsed as URL.
Expand Down
6 changes: 5 additions & 1 deletion url/a-element-origin-xhtml.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<script src="resources/a-element-origin.js"></script>
</body>
</html>
<!-- Other dependencies: resources/urltestdata.json -->
<!--
Other dependencies:
* resources/urltestdata.json,
* resources/urltestdata-javascript-only.json,
-->
6 changes: 5 additions & 1 deletion url/a-element-origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<base id=base>
<div id=log></div>
<script src=resources/a-element-origin.js></script>
<!-- Other dependencies: resources/urltestdata.json -->
<!--
Other dependencies:
* resources/urltestdata.json,
* resources/urltestdata-javascript-only.json,
-->
6 changes: 5 additions & 1 deletion url/a-element-xhtml.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<script src="resources/a-element.js"></script>
</body>
</html>
<!-- Other dependencies: resources/urltestdata.json -->
<!--
Other dependencies:
* resources/urltestdata.json,
* resources/urltestdata-javascript-only.json,
-->
6 changes: 5 additions & 1 deletion url/a-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<base id=base>
<div id=log></div>
<script src=resources/a-element.js></script>
<!-- Other dependencies: resources/urltestdata.json -->
<!--
Other dependencies:
* resources/urltestdata.json,
* resources/urltestdata-javascript-only.json,
-->


<a id="multline-entity" download="multline-entity.txt" href="data:text/plain;charset=utf-8,first%20line&#10;second%20line"> Link with embedded \n is parsed correctly </a>
Expand Down
5 changes: 4 additions & 1 deletion url/failure.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runTests), "Loading data…")
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
]).then((tests) => tests.flat()).then(runTests), "Loading data…");

function runTests(testData) {
for (const test of testData) {
Expand Down
5 changes: 4 additions & 1 deletion url/resources/a-element-origin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");

function setBase(base) {
document.getElementById("base").href = base
Expand Down
5 changes: 4 additions & 1 deletion url/resources/a-element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");

function setBase(base) {
document.getElementById("base").href = base;
Expand Down
18 changes: 18 additions & 0 deletions url/resources/urltestdata-javascript-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
"See ../README.md for a description of the format.",
{
"input": "http://example.com/\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF?\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF",
"base": null,
"href": "http://example.com/%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF?%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"search": "?%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"hash": ""
}
]
15 changes: 0 additions & 15 deletions url/resources/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4849,21 +4849,6 @@
"search": "",
"hash": ""
},
{
"input": "http://example.com/\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF?\uD800\uD801\uDFFE\uDFFF\uFDD0\uFDCF\uFDEF\uFDF0\uFFFE\uFFFF",
"base": null,
"href": "http://example.com/%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF?%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"search": "?%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF",
"hash": ""
},
"Forbidden host code points",
{
"input": "sc://a\u0000b/",
Expand Down
5 changes: 4 additions & 1 deletion url/url-constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ function runURLTests(urlTests) {
}
}

promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");
5 changes: 4 additions & 1 deletion url/url-origin.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");

function runURLTests(urlTests) {
for (const expected of urlTests) {
Expand Down

0 comments on commit 2b9af57

Please sign in to comment.