-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test, url: synchronize WPT url tests
* attributon of WPT in url-setter-tests * add WPT test utilities * synchronize WPT URLSearchParams tests * synchronize WPT url tests * split whatwg-url-inspect test * port historical url tests from WPT * protocol setter and special URLs Refs: web-platform-tests/wpt#4413 Refs: whatwg/url#104 Backport-of: #11079
- Loading branch information
1 parent
570c5e1
commit 7aaa960
Showing
25 changed files
with
1,194 additions
and
703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module.exports = [ | ||
{ | ||
'url': 'tftp://foobar.com/someconfig;mode=netascii', | ||
'protocol': 'tftp:', | ||
'hostname': 'foobar.com', | ||
'pathname': '/someconfig;mode=netascii' | ||
}, | ||
{ | ||
'url': 'telnet://user:pass@foobar.com:23/', | ||
'protocol': 'telnet:', | ||
'username': 'user', | ||
'password': 'pass', | ||
'hostname': 'foobar.com', | ||
'port': '23', | ||
'pathname': '/' | ||
}, | ||
{ | ||
'url': 'ut2004://10.10.10.10:7777/Index.ut2', | ||
'protocol': 'ut2004:', | ||
'hostname': '10.10.10.10', | ||
'port': '7777', | ||
'pathname': '/Index.ut2' | ||
}, | ||
{ | ||
'url': 'redis://foo:bar@somehost:6379/0?baz=bam&qux=baz', | ||
'protocol': 'redis:', | ||
'username': 'foo', | ||
'password': 'bar', | ||
'hostname': 'somehost', | ||
'port': '6379', | ||
'pathname': '/0', | ||
'search': '?baz=bam&qux=baz' | ||
}, | ||
{ | ||
'url': 'rsync://foo@host:911/sup', | ||
'protocol': 'rsync:', | ||
'username': 'foo', | ||
'hostname': 'host', | ||
'port': '911', | ||
'pathname': '/sup' | ||
}, | ||
{ | ||
'url': 'git://github.com/foo/bar.git', | ||
'protocol': 'git:', | ||
'hostname': 'github.com', | ||
'pathname': '/foo/bar.git' | ||
}, | ||
{ | ||
'url': 'irc://myserver.com:6999/channel?passwd', | ||
'protocol': 'irc:', | ||
'hostname': 'myserver.com', | ||
'port': '6999', | ||
'pathname': '/channel', | ||
'search': '?passwd' | ||
}, | ||
{ | ||
'url': 'dns://fw.example.org:9999/foo.bar.org?type=TXT', | ||
'protocol': 'dns:', | ||
'hostname': 'fw.example.org', | ||
'port': '9999', | ||
'pathname': '/foo.bar.org', | ||
'search': '?type=TXT' | ||
}, | ||
{ | ||
'url': 'ldap://localhost:389/ou=People,o=JNDITutorial', | ||
'protocol': 'ldap:', | ||
'hostname': 'localhost', | ||
'port': '389', | ||
'pathname': '/ou=People,o=JNDITutorial' | ||
}, | ||
{ | ||
'url': 'git+https://github.com/foo/bar', | ||
'protocol': 'git+https:', | ||
'hostname': 'github.com', | ||
'pathname': '/foo/bar' | ||
}, | ||
{ | ||
'url': 'urn:ietf:rfc:2648', | ||
'protocol': 'urn:', | ||
'pathname': 'ietf:rfc:2648' | ||
}, | ||
{ | ||
'url': 'tag:joe@example.org,2001:foo/bar', | ||
'protocol': 'tag:', | ||
'pathname': 'joe@example.org,2001:foo/bar' | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const path = require('path'); | ||
const { URL, URLSearchParams } = require('url'); | ||
const { test, assert_equals, assert_true, assert_throws } = common.WPT; | ||
|
||
if (!common.hasIntl) { | ||
// A handful of the tests fail when ICU is not included. | ||
common.skip('missing Intl'); | ||
return; | ||
} | ||
|
||
const request = { | ||
response: require(path.join(common.fixturesDir, 'url-tests.json')) | ||
}; | ||
|
||
/* eslint-disable */ | ||
/* WPT Refs: | ||
https://github.com/w3c/web-platform-tests/blob/8791bed/url/url-constructor.html | ||
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html | ||
*/ | ||
function runURLConstructorTests() { | ||
// var setup = async_test("Loading data…") | ||
// setup.step(function() { | ||
// var request = new XMLHttpRequest() | ||
// request.open("GET", "urltestdata.json") | ||
// request.send() | ||
// request.responseType = "json" | ||
// request.onload = setup.step_func(function() { | ||
runURLTests(request.response) | ||
// setup.done() | ||
// }) | ||
// }) | ||
} | ||
|
||
function bURL(url, base) { | ||
return new URL(url, base || "about:blank") | ||
} | ||
|
||
|
||
function runURLTests(urltests) { | ||
for(var i = 0, l = urltests.length; i < l; i++) { | ||
var expected = urltests[i] | ||
if (typeof expected === "string") continue // skip comments | ||
|
||
test(function() { | ||
if (expected.failure) { | ||
assert_throws(new TypeError(), function() { | ||
bURL(expected.input, expected.base) | ||
}) | ||
return | ||
} | ||
|
||
var url = bURL(expected.input, expected.base) | ||
assert_equals(url.href, expected.href, "href") | ||
assert_equals(url.protocol, expected.protocol, "protocol") | ||
assert_equals(url.username, expected.username, "username") | ||
assert_equals(url.password, expected.password, "password") | ||
assert_equals(url.host, expected.host, "host") | ||
assert_equals(url.hostname, expected.hostname, "hostname") | ||
assert_equals(url.port, expected.port, "port") | ||
assert_equals(url.pathname, expected.pathname, "pathname") | ||
assert_equals(url.search, expected.search, "search") | ||
if ("searchParams" in expected) { | ||
assert_true("searchParams" in url) | ||
// assert_equals(url.searchParams.toString(), expected.searchParams, "searchParams") | ||
} | ||
assert_equals(url.hash, expected.hash, "hash") | ||
}, "Parsing: <" + expected.input + "> against <" + expected.base + ">") | ||
} | ||
} | ||
|
||
function runURLSearchParamTests() { | ||
test(function() { | ||
var url = bURL('http://example.org/?a=b') | ||
assert_true("searchParams" in url) | ||
var searchParams = url.searchParams | ||
assert_true(url.searchParams === searchParams, 'Object identity should hold.') | ||
}, 'URL.searchParams getter') | ||
|
||
test(function() { | ||
var url = bURL('http://example.org/?a=b') | ||
assert_true("searchParams" in url) | ||
var searchParams = url.searchParams | ||
assert_equals(searchParams.toString(), 'a=b') | ||
|
||
searchParams.set('a', 'b') | ||
assert_equals(url.searchParams.toString(), 'a=b') | ||
assert_equals(url.search, '?a=b') | ||
url.search = '' | ||
assert_equals(url.searchParams.toString(), '') | ||
assert_equals(url.search, '') | ||
assert_equals(searchParams.toString(), '') | ||
}, 'URL.searchParams updating, clearing') | ||
|
||
test(function() { | ||
'use strict' | ||
var urlString = 'http://example.org' | ||
var url = bURL(urlString) | ||
assert_throws(TypeError(), function() { url.searchParams = new URLSearchParams(urlString) }) | ||
}, 'URL.searchParams setter, invalid values') | ||
|
||
test(function() { | ||
var url = bURL('http://example.org/file?a=b&c=d') | ||
assert_true("searchParams" in url) | ||
var searchParams = url.searchParams | ||
assert_equals(url.search, '?a=b&c=d') | ||
assert_equals(searchParams.toString(), 'a=b&c=d') | ||
|
||
// Test that setting 'search' propagates to the URL object's query object. | ||
url.search = 'e=f&g=h' | ||
assert_equals(url.search, '?e=f&g=h') | ||
assert_equals(searchParams.toString(), 'e=f&g=h') | ||
|
||
// ..and same but with a leading '?'. | ||
url.search = '?e=f&g=h' | ||
assert_equals(url.search, '?e=f&g=h') | ||
assert_equals(searchParams.toString(), 'e=f&g=h') | ||
|
||
// And in the other direction, altering searchParams propagates | ||
// back to 'search'. | ||
// searchParams.append('i', ' j ') | ||
// assert_equals(url.search, '?e=f&g=h&i=+j+') | ||
// assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+') | ||
// assert_equals(searchParams.get('i'), ' j ') | ||
|
||
// searchParams.set('e', 'updated') | ||
// assert_equals(url.search, '?e=updated&g=h&i=+j+') | ||
// assert_equals(searchParams.get('e'), 'updated') | ||
|
||
// var url2 = bURL('http://example.org/file??a=b&c=d') | ||
// assert_equals(url2.search, '??a=b&c=d') | ||
// assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d') | ||
|
||
// url2.href = 'http://example.org/file??a=b' | ||
// assert_equals(url2.search, '??a=b') | ||
// assert_equals(url2.searchParams.toString(), '%3Fa=b') | ||
}, 'URL.searchParams and URL.search setters, update propagation') | ||
} | ||
runURLSearchParamTests() | ||
runURLConstructorTests() | ||
/* eslint-enable */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const URL = require('url').URL; | ||
const { test, assert_equals, assert_throws } = common.WPT; | ||
|
||
if (!common.hasIntl) { | ||
// A handful of the tests fail when ICU is not included. | ||
common.skip('missing Intl'); | ||
return; | ||
} | ||
|
||
/* eslint-disable */ | ||
/* WPT Refs: | ||
https://github.com/w3c/web-platform-tests/blob/8791bed/url/historical.html | ||
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html | ||
*/ | ||
// var objects = [ | ||
// [function() { return window.location }, "location object"], | ||
// [function() { return document.createElement("a") }, "a element"], | ||
// [function() { return document.createElement("area") }, "area element"], | ||
// ]; | ||
|
||
// objects.forEach(function(o) { | ||
// test(function() { | ||
// var object = o[0](); | ||
// assert_false("searchParams" in object, | ||
// o[1] + " should not have a searchParams attribute"); | ||
// }, "searchParams on " + o[1]); | ||
// }); | ||
|
||
test(function() { | ||
var url = new URL("./foo", "http://www.example.org"); | ||
assert_equals(url.href, "http://www.example.org/foo"); | ||
assert_throws(new TypeError(), function() { | ||
url.href = "./bar"; | ||
}); | ||
}, "Setting URL's href attribute and base URLs"); | ||
|
||
test(function() { | ||
assert_equals(URL.domainToASCII, undefined); | ||
}, "URL.domainToASCII should be undefined"); | ||
|
||
test(function() { | ||
assert_equals(URL.domainToUnicode, undefined); | ||
}, "URL.domainToUnicode should be undefined"); | ||
/* eslint-enable */ |
Oops, something went wrong.
7aaa960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not land with the appropriate meta data
7aaa960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung Did you think the metadata wasn't needed because it was a backport?
7aaa960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam-github I believe this is committed by @italoacasas, isn't this?
7aaa960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right, sorry, I always get confused about the two sides of the with. Mostly, I'm wondering if the docs on the backport process are unclear, or whether its a "mistakes happen to us all" situation.