Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subset URL tests by file/javascript/mailto schemes #37372

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions url/a-element-xhtml.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>URL Test</title>
<meta name="variant" content="?include=file"/>
<meta name="variant" content="?include=javascript"/>
<meta name="variant" content="?include=mailto"/>
<meta name="variant" content="?exclude=(file|javascript|mailto)"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/subset-tests-by-key.js"></script>
<base id="base"/>
</head>
<body>
Expand Down
5 changes: 5 additions & 0 deletions url/a-element.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<!doctype html>
<meta charset=utf-8>
<meta name="variant" content="?include=file">
<meta name="variant" content="?include=javascript">
<meta name="variant" content="?include=mailto">
<meta name="variant" content="?exclude=(file|javascript|mailto)">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/subset-tests-by-key.js"></script>
<base id=base>
<div id=log></div>
<script src=resources/a-element.js></script>
Expand Down
13 changes: 12 additions & 1 deletion url/resources/a-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ function runURLTests(urltests) {
// skip without base because you cannot unset the baseURL of a document
if (expected.base === null) continue;

test(function() {
function getKey(expected) {
if (expected.protocol) {
return expected.protocol.replace(":", "");
}
if (expected.failure) {
var key = expected.input.split(":")[0];
return key;
}
return "other";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that the key isn't falsey, otherwise it'll be included in all test variants.

}

subsetTestByKey(getKey(expected), test, function() {
var url = bURL(expected.input, expected.base)
if(expected.failure) {
if(url.protocol !== ':') {
Expand Down
18 changes: 17 additions & 1 deletion url/url-constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: timeout=long
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)

function bURL(url, base) {
return base ? new URL(url, base) : new URL(url)
Expand All @@ -9,7 +14,18 @@ function runURLTests(urltests) {
var expected = urltests[i]
if (typeof expected === "string") continue // skip comments

test(function() {
function getKey(expected) {
if (expected.protocol) {
return expected.protocol.replace(":", "");
}
if (expected.failure) {
var key = expected.input.split(":")[0];
return key;
}
return "other";
}

subsetTestByKey(getKey(expected), test, function() {
if (expected.failure) {
assert_throws_js(TypeError, function() {
bURL(expected.input, expected.base)
Expand Down
11 changes: 9 additions & 2 deletions url/url-setters-a-area.window.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)

// Keep this file in sync with url-setters.any.js.

promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
Expand All @@ -15,15 +21,16 @@ function runURLSettersTests(all_test_cases) {
if ("comment" in test_case) {
name += " " + test_case.comment;
}
test(function() {
var key = test_case.href.split(":")[0];
subsetTestByKey(key, test, function() {
var url = document.createElement("a");
url.href = test_case.href;
url[attribute_to_be_set] = test_case.new_value;
for (var attribute in test_case.expected) {
assert_equals(url[attribute], test_case.expected[attribute])
}
}, "<a>: " + name)
test(function() {
subsetTestByKey(key, test, function() {
var url = document.createElement("area");
url.href = test_case.href;
url[attribute_to_be_set] = test_case.new_value;
Expand Down
9 changes: 8 additions & 1 deletion url/url-setters.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)

// Keep this file in sync with url-setters-a-area.window.js.

promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
Expand All @@ -15,7 +21,8 @@ function runURLSettersTests(all_test_cases) {
if ("comment" in test_case) {
name += " " + test_case.comment;
}
test(function() {
var key = test_case.href.split(":")[0];
subsetTestByKey(key, test, function() {
var url = new URL(test_case.href);
url[attribute_to_be_set] = test_case.new_value;
for (var attribute in test_case.expected) {
Expand Down