-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
url, test: synchronize web-platform-test url tests #11079
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e16be38
test: attributon of WPT in url-setter-tests
joyeecheung 0e98bbc
test: add WPT test utilities
joyeecheung 971f8b9
url, test: synchronize WPT URLSearchParams tests
joyeecheung 57a2937
url, test: synchronize WPT url tests
joyeecheung f4d972d
test: split whatwg-url-inspect test
joyeecheung 38511c4
test: port historical url tests from WPT
joyeecheung ff0fccc
test: protocol setter and special URLs
joyeecheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"comment": [ | ||
"License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html", | ||
"## Tests for setters of https://url.spec.whatwg.org/#urlutils-members", | ||
"", | ||
"This file contains a JSON object.", | ||
|
@@ -19,8 +20,7 @@ | |
" get the attribute `key` (invoke its getter).", | ||
" The returned string must be equal to `value`.", | ||
"", | ||
"Note: the 'href' setter is already covered by urltestdata.json.", | ||
"Source: https://github.com/w3c/web-platform-tests/tree/master/url" | ||
"Note: the 'href' setter is already covered by urltestdata.json." | ||
], | ||
"protocol": [ | ||
{ | ||
|
@@ -103,14 +103,30 @@ | |
} | ||
}, | ||
{ | ||
"comment": "Can’t switch from special scheme to non-special. Note: this may change, see https://github.com/whatwg/url/issues/104", | ||
"comment": "Can’t switch from special scheme to non-special", | ||
"href": "http://example.net", | ||
"new_value": "b", | ||
"expected": { | ||
"href": "http://example.net/", | ||
"protocol": "http:" | ||
} | ||
}, | ||
{ | ||
"href": "https://example.net", | ||
"new_value": "s", | ||
"expected": { | ||
"href": "https://example.net/", | ||
"protocol": "https:" | ||
} | ||
}, | ||
{ | ||
"href": "ftp://example.net", | ||
"new_value": "test", | ||
"expected": { | ||
"href": "ftp://example.net/", | ||
"protocol": "ftp:" | ||
} | ||
}, | ||
{ | ||
"comment": "Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.", | ||
"href": "mailto:[email protected]", | ||
|
@@ -121,14 +137,38 @@ | |
} | ||
}, | ||
{ | ||
"comment": "Can’t switch from non-special scheme to special. Note: this may change, see https://github.com/whatwg/url/issues/104", | ||
"comment": "Can’t switch from non-special scheme to special", | ||
"href": "ssh://[email protected]", | ||
"new_value": "http", | ||
"expected": { | ||
"href": "ssh://[email protected]/", | ||
"protocol": "ssh:" | ||
} | ||
}, | ||
{ | ||
"href": "ssh://[email protected]", | ||
"new_value": "gopher", | ||
"expected": { | ||
"href": "ssh://[email protected]/", | ||
"protocol": "ssh:" | ||
} | ||
}, | ||
{ | ||
"href": "ssh://[email protected]", | ||
"new_value": "file", | ||
"expected": { | ||
"href": "ssh://[email protected]/", | ||
"protocol": "ssh:" | ||
} | ||
}, | ||
{ | ||
"href": "nonsense:///test", | ||
"new_value": "https", | ||
"expected": { | ||
"href": "nonsense:///test", | ||
"protocol": "nonsense:" | ||
} | ||
}, | ||
{ | ||
"comment": "Stuff after the first ':' is ignored", | ||
"href": "http://example.net", | ||
|
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:[email protected]: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:[email protected],2001:foo/bar', | ||
'protocol': 'tag:', | ||
'pathname': '[email protected],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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we upstream these to web-platform-tests? I can do it if that'd be easier.
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 can give it a try first :D. These test cases don't have
base
so isurltestdata.json
the right place to go?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.
Yeah. No base is just a base of about:blank, so just add that.
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.
Cool, thanks!