var error = false; var url;
try {
if (test.base) {
url = new URL(test.url, test.base);
} else {
url = new URL(test.url);
}
} catch (e) {
error = true;
}
is(test.error, error, "Error creating URL");
if (test.error) {
continue;
}
if ("href" in test) is(url.href, test.href, "href");
if ("origin" in test) is(url.origin, test.origin, "origin");
if ("protocol" in test) is(url.protocol, test.protocol, "protocol");
if ("username" in test) is(url.username, test.username, "username");
if ("password" in test) is(url.password, test.password, "password");
if ("host" in test) is(url.host, test.host, "host");
if ("hostname" in test) is(url.hostname, test.hostname, "hostname");
if ("port" in test) is(url.port, test.port, "port");
if ("pathname" in test) is(url.pathname, test.pathname, "pathname");
if ("search" in test) is(url.search, test.search, "search");
if ("hash" in test) is(url.hash, test.hash, "hash");
{
let uri = SpecialPowers.wrap(url).URI;
is(url.href, uri.spec, "Conversion to nsIURI");
is(SpecialPowers.wrap(URL).fromURI(uri).href, uri.spec, "Conversion from nsIURI");
}
if ("skip_setters" in test && test.skip_setters === false) {
info("Skip setter methods for URL: " + test);
continue;
}
if ("href" in test) url.href = test.href;
if ("protocol" in test) url.protocol = test.protocol;
if ("username" in test && test.username) url.username = test.username;
if ("password" in test && test.password) url.password = test.password;
if ("host" in test) url.host = test.host;
if ("hostname" in test) url.hostname = test.hostname;
if ("port" in test) url.port = test.port;
if ("pathname" in test) url.pathname = test.pathname;
if ("search" in test) url.search = test.search;
if ("hash" in test) url.hash = test.hash;
if ("href" in test) is(url.href, test.href, "href");
if ("origin" in test) is(url.origin, test.origin, "origin");
if ("expectedChangedProtocol" in test) is(url.protocol, test.expectedChangedProtocol, "protocol");
else if ("protocol" in test) is(url.protocol, test.protocol, "protocol");
if ("username" in test) is(url.username, test.username, "username");
if ("password" in test) is(url.password, test.password, "password");
if ("host" in test) is(url.host, test.host, "host");
if ("hostname" in test) is(test.hostname, url.hostname, "hostname");
if ("port" in test) is(test.port, url.port, "port");
if ("pathname" in test) is(test.pathname, url.pathname, "pathname");
if ("search" in test) is(test.search, url.search, "search");
if ("hash" in test) is(test.hash, url.hash, "hash");
if ("href" in test) is(test.href, url + "", "stringify works");
}
</script>
<script>
/** Test for Bug 991471 **/ var url = new URL("http://localhost/");
url.hostname = "";
url.username = "tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
url.hostname = "www.mozilla.org";
url.username = "";
url.hostname = "www.mozilla.org";
is(url.href, "http://www.mozilla.org/", "No parsing error with empty host");
</script>
<script>
/** Test for Bug 996055 **/ var url = new URL("http://localhost/");
url.hostname = "";
is(url.href, "http://localhost/", "Empty hostname is ignored");
</script>
<script>
/** Test for Bug 960014 **/ var url = new URL("http://localhost/");
url.hostname = "[2001::1]";
is(url.hostname, "[2001::1]", "IPv6 hostname");
is(url.href, "http://[2001::1]/");
url = new URL("http://localhost/");
// This should silently fail since it's missing the brackets
url.hostname = "2001::1";
is(url.hostname, "localhost", "Setting bad hostname fails");
</script>
<script> var blob = new Blob(["a"]); var url = URL.createObjectURL(blob);
var u = new URL(url);
is(u.origin, location.origin, "The URL generated from a blob URI has an origin");
</script>
<script> var blob = new Blob(["a"]); var url = URL.createObjectURL(blob);
var a = document.createElement("A");
a.href = url;
is(a.origin, location.origin, "The 'a' element has the correct origin");
</script>
<script> var blob = new Blob(["a"]); var url = URL.createObjectURL(blob);
URL.revokeObjectURL(url);
URL.revokeObjectURL(url);
ok(true, "Calling revokeObjectURL twice should be ok");
</script>
<script>
URL.revokeObjectURL("blob:something");
ok(true, "This should not throw.");
</script>
url = new URL("ftp://tmp/test", base);
is(url.href, "ftp://tmp/test");
url = new URL("ftp:\\\\tmp\\test", base);
is(url.href, "ftp://tmp/test");
</script>
<script>
/** Test for Bug 1275746 **/
SimpleTest.doesThrow(() => { new URL("http:"); }, "http: is not a valid URL");
SimpleTest.doesThrow(() => { new URL("http:///"); }, "http: is not a valid URL");
var url = new URL("file:");
is(url.href, "file:///", "Parsing file: should work.");
url = new URL("file:///");
is(url.href, "file:///", "Parsing file:/// should work.");
</script>
var url = new URL("scheme:path/to/file?query#hash");
is(url.href, "scheme:path/to/file?query#hash");
is(url.pathname, "path/to/file");
is(url.search, "?query");
is(url.hash, "#hash");
// pathname cannot be overwritten.
url.pathname = "new/path?newquery#newhash";
is(url.href, "scheme:path/to/file?query#hash");
// don't escape '#' until we implement a spec-compliant parser.
url.search = "?newquery#newhash";
is(url.href, "scheme:path/to/file?newquery%23newhash#hash");
// nulls get encoded, whitespace gets stripped
url = new URL("scheme:pa\0\nth/to/fi\0\nle?qu\0\nery#ha\0\nsh");
is(url.href, "scheme:pa%00th/to/fi%00le?qu%00ery#ha%00sh");
// we don't implement a spec-compliant parser yet.
// make sure we are bug compatible with existing implementations.
url = new URL("data:text/html,http://example.org/?q\">Link");
is(url.href, "data:text/html,http://example.org/?q\">Link");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.