Skip to content

Commit

Permalink
Subset URL tests by file/javascript/mailto schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip committed Dec 7, 2022
1 parent ed61f37 commit 83f8916
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
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";
}

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

0 comments on commit 83f8916

Please sign in to comment.