diff --git a/html/browsers/origin/tentative/api/origin-comparison.any.js b/html/browsers/origin/tentative/api/origin-comparison.any.js index f03532b99b4fd7..06fe9befaf811c 100644 --- a/html/browsers/origin/tentative/api/origin-comparison.any.js +++ b/html/browsers/origin/tentative/api/origin-comparison.any.js @@ -1,8 +1,10 @@ // META: title=`Origin` comparison test(t => { - const opaqueA = new Origin("null"); - const opaqueB = new Origin("null"); + const opaqueA = new Origin(); + const opaqueB = new Origin(); + assert_true(opaqueA.opaque); + assert_true(opaqueB.opaque); assert_true(opaqueA.isSameOrigin(opaqueA), "Opaque origin should be same-origin with itself."); assert_true(opaqueA.isSameSite(opaqueA), "Opaque origin should be same-site with itself."); @@ -11,11 +13,11 @@ test(t => { }, "Comparison of opaque origins."); test(t => { - const a = new Origin("https://a.example"); - const a_a = new Origin("https://a.a.example"); - const b_a = new Origin("https://b.a.example"); - const b = new Origin("https://b.example"); - const b_b = new Origin("https://b.b.example"); + const a = Origin.from("https://a.example"); + const a_a = Origin.from("https://a.a.example"); + const b_a = Origin.from("https://b.a.example"); + const b = Origin.from("https://b.example"); + const b_b = Origin.from("https://b.b.example"); assert_true(a.isSameOrigin(a), "Origin should be same-origin with itself."); assert_false(a.isSameOrigin(a_a), "Origins with different subdomains should not be same-origin."); @@ -37,8 +39,8 @@ test(t => { }, "Comparison of tuple origins."); test(t => { - const http = new Origin("http://a.example"); - const https = new Origin("https://a.example"); + const http = Origin.from("http://a.example"); + const https = Origin.from("https://a.example"); assert_false(http.isSameOrigin(https), "http is not same-site with https"); assert_false(https.isSameOrigin(http), "https is not same-site with http"); diff --git a/html/browsers/origin/tentative/api/origin-fromURL.any.js b/html/browsers/origin/tentative/api/origin-fromURL.any.js deleted file mode 100644 index ff55d00243e6f2..00000000000000 --- a/html/browsers/origin/tentative/api/origin-fromURL.any.js +++ /dev/null @@ -1,71 +0,0 @@ -// META: title=`Origin.fromURL()` - -// -// URLs with opaque origins: -// -const opaqueURLs = [ - "about:blank", - "data:text/plain,opaque", - "weird-protocol:whatever", - "weird-hierarchical-protocol://host/path?etc", - "blob:weird-protocol:whatever", - "blob:weird-hierarchical-protocol://host/path?etc", -]; -for (const opaque of opaqueURLs) { - test(t => { - const origin = Origin.fromURL(opaque); - assert_true(origin.opaque, "Origin should be opaque."); - }, `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."); - }, `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 = [ - "http://site.example", - "https://site.example", - "https://site.example:123", - "http://sub.site.example", - "https://sub.site.example", - "https://sub.site.example:123", - "https://xn--mlauted-m2a.example", - "ftp://ftp.example", - "ws://ws.example", - "wss://wss.example", - "https://trailing.slash/", - "https://user:pass@site.example", - "https://has.a.port:1234/and/path", - "https://ümlauted.example", - "file:///path/to/a/file.txt", - "blob:https://example.com/some-guid", - "ftp://example.com/", - "https://example.com/path?query#fragment", - "https://127.0.0.1/", - "https://[::1]/", -]; - -for (const tuple of tupleSerializations) { - test(t => { - const origin = Origin.fromURL(tuple); - assert_false(origin.opaque, "Origin should not be opaque."); - }, `Origin constructed from '${tuple}' is a tuple origin.`); -} diff --git a/html/browsers/origin/tentative/api/origin.any.js b/html/browsers/origin/tentative/api/origin.any.js deleted file mode 100644 index ec5b56d2572622..00000000000000 --- a/html/browsers/origin/tentative/api/origin.any.js +++ /dev/null @@ -1,80 +0,0 @@ -// META: title=`Origin` Construction and Parsing - -// -// Opaque origins: -// -test(t => { - const origin = new Origin(); - assert_true(origin.opaque, "Origin should be opaque."); -}, "Default-constructed Origin is opaque."); - -test(t => { - const origin = new Origin("null"); - assert_true(origin.opaque, "Origin should be opaque."); -}, "Origin constructed with 'null' is opaque."); - -test(t => { - const origin = Origin.parse("null"); - assert_true(origin.opaque, "Origin should be opaque."); -}, "Origin parsed from 'null' is opaque."); - -// -// Invalid serializations: -// -const invalidSerializations = [ - "", - "invalid", - "about:blank", - "https://trailing.slash/", - "https://user:pass@site.example", - "https://has.a.port:1234/and/path", - "https://ümlauted.example", - "https://has.a.fragment/#frag", - "https://invalid.port:123456789", - "blob:https://blob.example/guid-goes-here", -]; - -for (const invalid of invalidSerializations) { - test(t => { - assert_throws_js(TypeError, () => new Origin(invalid), "Constructor should throw TypeError for invalid origin."); - }, `Origin constructor throws for '${invalid}'.`); - - test(t => { - assert_equals(Origin.parse(invalid), null, "parse() should return null for invalid origin."); - }, `Origin.parse returns null for '${invalid}'.`); -} - -// -// Tuple origins: -// -const tupleSerializations = [ - "http://site.example", - "https://site.example", - "https://site.example:123", - "http://sub.site.example", - "https://sub.site.example", - "https://sub.site.example:123", - "https://xn--mlauted-m2a.example", - "ftp://ftp.example", - "ws://ws.example", - "wss://wss.example", -]; - -for (const tuple of tupleSerializations) { - test(t => { - const origin = new Origin(tuple); - assert_false(origin.opaque, "Origin should not be opaque."); - }, `Origin constructed from '${tuple}' is a tuple origin.`); - - test(t => { - const origin = Origin.parse(tuple); - assert_false(origin.opaque, "Origin should not be opaque."); - }, `Origin parsed from '${tuple}' is a tuple origin.`); - - test(t => { - const a = new Origin(tuple); - const b = Origin.parse(tuple); - assert_true(a.isSameOrigin(b)); - assert_true(b.isSameOrigin(a)); - }, `Origins parsed and constructed from '${tuple}' are equivalent.`); -} diff --git a/interfaces/origin.tentative.idl b/interfaces/origin.tentative.idl index 17af9d3030649a..4adc41f682bafb 100644 --- a/interfaces/origin.tentative.idl +++ b/interfaces/origin.tentative.idl @@ -2,10 +2,8 @@ [Exposed=*] interface Origin { constructor(); - constructor(USVString serializedOrigin); - static Origin? parse(USVString serializedOrigin); - static Origin? fromURL(USVString serializedURL); + static Origin from(any value); readonly attribute boolean opaque;