Skip to content

Truly independent web browser

LibWeb: Import origin extraction tests for hyperlink elements

Andreas Klingdeb215b8181a
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.txt
new file mode 100644
index 00000000000..97bcf3fa719
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.txt
@@ -0,0 +1,135 @@
+Harness status: OK
+
+Found 129 tests
+
+54 Pass
+75 Fail
+Pass Origin.from(<a>) throws.
+Pass Origin.from(<area>) throws.
+Pass Origin.from(SVG <a>) throws.
+Pass Origin.from(MathML <a>) throws.
+Pass Origin.from(<a href="about:blank">) returns an opaque origin.
+Pass Origin.from(<area href="about:blank">) returns an opaque origin.
+Fail Origin.from(SVG <a href="about:blank">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="about:blank">) returns an opaque origin.
+Fail Origin.from(MathML <a href="about:blank">) returns an opaque origin.
+Pass Origin.from(<a href="data:text/plain,opaque">) returns an opaque origin.
+Pass Origin.from(<area href="data:text/plain,opaque">) returns an opaque origin.
+Fail Origin.from(SVG <a href="data:text/plain,opaque">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="data:text/plain,opaque">) returns an opaque origin.
+Fail Origin.from(MathML <a href="data:text/plain,opaque">) returns an opaque origin.
+Pass Origin.from(<a href="weird-protocol:whatever">) returns an opaque origin.
+Pass Origin.from(<area href="weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(SVG <a href="weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(MathML <a href="weird-protocol:whatever">) returns an opaque origin.
+Pass Origin.from(<a href="weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Pass Origin.from(<area href="weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(SVG <a href="weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(MathML <a href="weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Pass Origin.from(<a href="blob:weird-protocol:whatever">) returns an opaque origin.
+Pass Origin.from(<area href="blob:weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(SVG <a href="blob:weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="blob:weird-protocol:whatever">) returns an opaque origin.
+Fail Origin.from(MathML <a href="blob:weird-protocol:whatever">) returns an opaque origin.
+Pass Origin.from(<a href="blob:weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Pass Origin.from(<area href="blob:weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(SVG <a href="blob:weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(SVG <a xlink:href="blob:weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Fail Origin.from(MathML <a href="blob:weird-hierarchical-protocol://host/path?etc">) returns an opaque origin.
+Pass Origin.from(<a href="http://site.example">) returns a tuple origin.
+Pass Origin.from(<area href="http://site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="http://site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="http://site.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="http://site.example">) returns a tuple origin.
+Pass Origin.from(<a href="https://site.example">) returns a tuple origin.
+Pass Origin.from(<area href="https://site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://site.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://site.example">) returns a tuple origin.
+Pass Origin.from(<a href="https://site.example:123">) returns a tuple origin.
+Pass Origin.from(<area href="https://site.example:123">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://site.example:123">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://site.example:123">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://site.example:123">) returns a tuple origin.
+Pass Origin.from(<a href="http://sub.site.example">) returns a tuple origin.
+Pass Origin.from(<area href="http://sub.site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="http://sub.site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="http://sub.site.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="http://sub.site.example">) returns a tuple origin.
+Pass Origin.from(<a href="https://sub.site.example">) returns a tuple origin.
+Pass Origin.from(<area href="https://sub.site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://sub.site.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://sub.site.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://sub.site.example">) returns a tuple origin.
+Pass Origin.from(<a href="https://sub.site.example:123">) returns a tuple origin.
+Pass Origin.from(<area href="https://sub.site.example:123">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://sub.site.example:123">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://sub.site.example:123">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://sub.site.example:123">) returns a tuple origin.
+Pass Origin.from(<a href="https://xn--mlauted-m2a.example">) returns a tuple origin.
+Pass Origin.from(<area href="https://xn--mlauted-m2a.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://xn--mlauted-m2a.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://xn--mlauted-m2a.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://xn--mlauted-m2a.example">) returns a tuple origin.
+Pass Origin.from(<a href="ftp://ftp.example">) returns a tuple origin.
+Pass Origin.from(<area href="ftp://ftp.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="ftp://ftp.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="ftp://ftp.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="ftp://ftp.example">) returns a tuple origin.
+Pass Origin.from(<a href="ws://ws.example">) returns a tuple origin.
+Pass Origin.from(<area href="ws://ws.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="ws://ws.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="ws://ws.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="ws://ws.example">) returns a tuple origin.
+Pass Origin.from(<a href="wss://wss.example">) returns a tuple origin.
+Pass Origin.from(<area href="wss://wss.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="wss://wss.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="wss://wss.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="wss://wss.example">) returns a tuple origin.
+Pass Origin.from(<a href="https://trailing.slash/">) returns a tuple origin.
+Pass Origin.from(<area href="https://trailing.slash/">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://trailing.slash/">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://trailing.slash/">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://trailing.slash/">) returns a tuple origin.
+Pass Origin.from(<a href="https://user:[email protected]">) returns a tuple origin.
+Pass Origin.from(<area href="https://user:[email protected]">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://user:[email protected]">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://user:[email protected]">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://user:[email protected]">) returns a tuple origin.
+Pass Origin.from(<a href="https://has.a.port:1234/and/path">) returns a tuple origin.
+Pass Origin.from(<area href="https://has.a.port:1234/and/path">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://has.a.port:1234/and/path">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://has.a.port:1234/and/path">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://has.a.port:1234/and/path">) returns a tuple origin.
+Pass Origin.from(<a href="https://ümlauted.example">) returns a tuple origin.
+Pass Origin.from(<area href="https://ümlauted.example">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://ümlauted.example">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://ümlauted.example">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://ümlauted.example">) returns a tuple origin.
+Pass Origin.from(<a href="blob:https://example.com/some-guid">) returns a tuple origin.
+Pass Origin.from(<area href="blob:https://example.com/some-guid">) returns a tuple origin.
+Fail Origin.from(SVG <a href="blob:https://example.com/some-guid">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="blob:https://example.com/some-guid">) returns a tuple origin.
+Fail Origin.from(MathML <a href="blob:https://example.com/some-guid">) returns a tuple origin.
+Pass Origin.from(<a href="ftp://example.com/">) returns a tuple origin.
+Pass Origin.from(<area href="ftp://example.com/">) returns a tuple origin.
+Fail Origin.from(SVG <a href="ftp://example.com/">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="ftp://example.com/">) returns a tuple origin.
+Fail Origin.from(MathML <a href="ftp://example.com/">) returns a tuple origin.
+Pass Origin.from(<a href="https://example.com/path?query#fragment">) returns a tuple origin.
+Pass Origin.from(<area href="https://example.com/path?query#fragment">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://example.com/path?query#fragment">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://example.com/path?query#fragment">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://example.com/path?query#fragment">) returns a tuple origin.
+Pass Origin.from(<a href="https://127.0.0.1/">) returns a tuple origin.
+Pass Origin.from(<area href="https://127.0.0.1/">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://127.0.0.1/">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://127.0.0.1/">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://127.0.0.1/">) returns a tuple origin.
+Pass Origin.from(<a href="https://[::1]/">) returns a tuple origin.
+Pass Origin.from(<area href="https://[::1]/">) returns a tuple origin.
+Fail Origin.from(SVG <a href="https://[::1]/">) returns a tuple origin.
+Fail Origin.from(SVG <a xlink:href="https://[::1]/">) returns a tuple origin.
+Fail Origin.from(MathML <a href="https://[::1]/">) returns a tuple origin.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.html
new file mode 100644
index 00000000000..2b4e66fd4d8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>`Origin.from(HyperlinkElementUtils)`</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="resources/serializations.js"></script>
+<div id=log></div>
+<script src="../../../../html/browsers/origin/api/origin-from-hyperlinkelementutils.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.js b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.js
new file mode 100644
index 00000000000..9e847c79644
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/api/origin-from-hyperlinkelementutils.window.js
@@ -0,0 +1,134 @@
+// META: title=`Origin.from(HyperlinkElementUtils)`
+// META: script=resources/serializations.js
+
+test(t => {
+ const invalid = document.createElement("a");
+ assert_throws_js(TypeError, _ => Origin.from(invalid));
+}, `Origin.from(<a>) throws.`);
+
+test(t => {
+ const invalid = document.createElement("area");
+ assert_throws_js(TypeError, _ => Origin.from(invalid));
+}, `Origin.from(<area>) throws.`);
+
+test(t => {
+ const invalid = document.createElementNS('http://www.w3.org/2000/svg', 'a');
+ assert_throws_js(TypeError, _ => Origin.from(invalid));
+}, `Origin.from(SVG <a>) throws.`);
+
+test(t => {
+ const invalid = document.createElementNS('http://www.w3.org/1998/Math/MathML', 'a');
+ assert_throws_js(TypeError, _ => Origin.from(invalid));
+}, `Origin.from(MathML <a>) throws.`);
+
+for (const opaque of urls.opaque) {
+ // <a>
+ test(t => {
+ const a = document.createElement("a");
+ a.href = opaque;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_true(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_false(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(<a href="${opaque}">) returns an opaque origin.`);
+
+ // <area>
+ test(t => {
+ const area = document.createElement("area");
+ area.href = opaque;
+ const origin = Origin.from(area);
+ assert_true(!!origin);
+ assert_true(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_false(origin.isSameOrigin(Origin.from(area)));
+ }, `Origin.from(<area href="${opaque}">) returns an opaque origin.`);
+
+ // SVG <a>
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/2000/svg', 'a');
+ a.href.baseVal = opaque;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_true(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_false(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(SVG <a href="${opaque}">) returns an opaque origin.`);
+
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/2000/svg', 'a');
+ a.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', opaque);
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_true(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_false(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(SVG <a xlink:href="${opaque}">) returns an opaque origin.`);
+
+ // MathML <a>
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/1998/Math/MathML', 'a');
+ a.href = opaque;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_true(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_false(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(MathML <a href="${opaque}">) returns an opaque origin.`);
+}
+
+for (const tuple of urls.tuple) {
+ // <a>
+ test(t => {
+ const a = document.createElement("a");
+ a.href = tuple;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_false(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_true(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(<a href="${tuple}">) returns a tuple origin.`);
+
+ // <area>
+ test(t => {
+ const area = document.createElement("area");
+ area.href = tuple;
+ const origin = Origin.from(area);
+ assert_true(!!origin);
+ assert_false(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_true(origin.isSameOrigin(Origin.from(area)));
+ }, `Origin.from(<area href="${tuple}">) returns a tuple origin.`);
+
+ // SVG <a>
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/2000/svg', 'a');
+ a.href.baseVal = tuple;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_false(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_true(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(SVG <a href="${tuple}">) returns a tuple origin.`);
+
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/2000/svg', 'a');
+ a.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', tuple);
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_false(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_true(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(SVG <a xlink:href="${tuple}">) returns a tuple origin.`);
+
+ // MathML <a>
+ test(t => {
+ const a = document.createElementNS('http://www.w3.org/1998/Math/MathML', 'a');
+ a.href = tuple;
+ const origin = Origin.from(a);
+ assert_true(!!origin);
+ assert_false(origin.opaque);
+ assert_true(origin.isSameOrigin(origin));
+ assert_true(origin.isSameOrigin(Origin.from(a)));
+ }, `Origin.from(MathML <a href="${tuple}">) returns a tuple origin.`);
+}