Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 34 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/browsers/origin/tentative/api/origin-fromURL.any.html - WPT Dashboard Interop Dashboard
- /html/browsers/origin/tentative/api/origin-fromURL.any.worker.html - WPT Dashboard Interop Dashboard
// META: title=`Origin.fromURL()`
//
// URLs with opaque origins:
//
const opaqueURLs = [
"about:blank",
"data:text/plain,opaque",
"weird-protocol:whatever",
"blob:weird-protocol:whatever",
];
for (const opaque of opaqueURLs) {
test(t => {
const origin = Origin.fromURL(opaque);
assert_true(origin.opaque, "Origin should be opaque.");
assert_equals(origin.toJSON(), "null", "toJSON() should return the serialized origin.");
}, `Origin.fromURL for opaque URL as string '${opaque}'.`);
test(t => {
const origin = Origin.fromURL(new URL(opaque));
assert_true(origin.opaque, "Origin should be opaque.");
assert_equals(origin.toJSON(), "null", "toJSON() should return the serialized origin.");
}, `Origin.fromURL for opaque URL as URL '${opaque}'.`);
}
//
// Invalid serializations:
//
const invalidSerializations = [
"",
"invalid",
];
for (const invalid of invalidSerializations) {
test(t => {
assert_equals(null, Origin.fromURL(invalid));
}, `Origin.fromURL returns null for '${invalid}'.`);
}
//
// Tuple origins:
//
const tupleSerializations = [
];
for (const tuple of tupleSerializations) {
test(t => {
const origin = Origin.fromURL(tuple);
assert_false(origin.opaque, "Origin should not be opaque.");
assert_equals(origin.toJSON(), (new URL(tuple)).origin, "toJSON() should return the serialized origin.");
}, `Origin constructed from '${tuple}' is a tuple origin.`);
}