Truly independent web browser
LibWeb: Import stylesheet error event tests
Andreas Klingb801f971ad88
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 063976b0393..72ce7d71220 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -40,6 +40,11 @@ Text/input/wpt-import/html/semantics/scripting-1/the-script-element/module/dynamText/input/wpt-import/html/semantics/scripting-1/the-script-element/module/dynamic-import/propagate-nonce-inline-classic.htmlText/input/wpt-import/html/semantics/scripting-1/the-script-element/module/dynamic-import/propagate-nonce-inline-module.html+; Resource loading tests use WPT Python handlers, substitutions, or .headers files.+Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.html+Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.html+Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.html+; Performs cross-origin Worker fetchText/input/wpt-import/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.htmlText/input/wpt-import/workers/constructors/Worker/same-origin.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txtnew file mode 100644index 00000000000..99d65cf32fa--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.txt@@ -0,0 +1,32 @@+Harness status: OK++Found 26 tests++18 Pass+8 Fail+Pass Should get an error event for a 404 error.+Pass Should get an error event for an unsupported URL.+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txtnew file mode 100644index 00000000000..c2628512d40--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.txt@@ -0,0 +1,30 @@+Harness status: OK++Found 24 tests++16 Pass+8 Fail+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txtnew file mode 100644index 00000000000..44d657a96e4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.txt@@ -0,0 +1,30 @@+Harness status: OK++Found 24 tests++16 Pass+8 Fail+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, same-origin, and nosniff+Fail Stylesheet loading using <link> with wrong Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with no Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and no nosniff+Pass Stylesheet loading using <link> with broken Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with wrong Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, same-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, same-origin, and nosniff+Pass Stylesheet loading using @import with no Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with no Content-Type, cross-origin, and nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with wrong Content-Type, cross-origin, and nosniff+Pass Stylesheet loading using @import with broken Content-Type, cross-origin, and no nosniff+Fail Stylesheet loading using @import with broken Content-Type, cross-origin, and nosniff\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.htmlnew file mode 100644index 00000000000..dd96504ac09--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<title>link: error events</title>+<link rel="author" title="Ms2ger" href="mailto:[email protected]">+<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-link-element">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src=../../../../common/get-host-info.sub.js></script>+<div id="log"></div>+<div id="test">+<script>+var t404 = async_test("Should get an error event for a 404 error.")+t404.step(function() {+ var elt = document.createElement("link");+ elt.onerror = t404.step_func(function() {+ assert_true(true, "Got error event for 404 error.")+ t404.step_timeout(function() { t404.done() }, 0);+ })+ elt.onload = t404.unreached_func("load event should not be fired");+ elt.rel = "stylesheet";+ elt.href = "nonexistent_stylesheet.css";+ document.getElementsByTagName("head")[0].appendChild(elt);+})++var tUnsupported = async_test("Should get an error event for an unsupported URL.")+tUnsupported.step(function() {+ var elt = document.createElement("link");+ elt.onerror = tUnsupported.step_func(function() {+ assert_true(true, "Got error event for unsupported URL.")+ tUnsupported.step_timeout(function() { tUnsupported.done() }, 0);+ })+ elt.onload = tUnsupported.unreached_func("load event should not be fired");+ elt.rel = "stylesheet";+ elt.href = "nonexistent:stylesheet.css";+ document.getElementsByTagName("head")[0].appendChild(elt);+});+</script>+<script src=resources/link-style-error.js></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.htmlnew file mode 100644index 00000000000..ebb383431f4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.html@@ -0,0 +1,7 @@+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">+<title>link: error events in limited quirks mode</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src=../../../../common/get-host-info.sub.js></script>+<div id="log"></div>+<script src=resources/link-style-error.js></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.htmlnew file mode 100644index 00000000000..508d6e9a5a4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.html@@ -0,0 +1,7 @@+<!DOCTYPE HTML PUBLIC "-//Sun Microsystems Corp.//DTD HotJava Strict HTML//" "">+<title>link: error events in quirks mode</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src=../../../../common/get-host-info.sub.js></script>+<div id="log"></div>+<script src=resources/link-style-error.js></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/css.py b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/css.pynew file mode 100644index 00000000000..5874c1b39f8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/css.py@@ -0,0 +1,9 @@+def main(request, response):+ response.add_required_headers = False+ if b"content_type" in request.GET:+ response.writer.write_header(b"Content-Type", request.GET.first(b"content_type"))+ if b"nosniff" in request.GET:+ response.writer.write_header(b"x-content-type-options", b"nosniff")+ if b"cors" in request.GET:+ response.writer.write_header(b"Access-Control-Allow-Origin", b"*")+ response.writer.write_content(u"body { background:red }")diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/link-style-error.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/link-style-error.jsnew file mode 100644index 00000000000..d1fa5ac2d6f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/document-metadata/the-link-element/resources/link-style-error.js@@ -0,0 +1,47 @@+["<link>", "@import"].forEach(linkType => {+ [+ ["same-origin", "resources/css.py"],+ ["cross-origin", get_host_info().HTTP_REMOTE_ORIGIN + "/html/semantics/document-metadata/the-link-element/resources/css.py"]+ ].forEach(originType => {+ ["no Content-Type", "wrong Content-Type", "broken Content-Type"].forEach(contentType => {+ ["no nosniff", "nosniff"].forEach(nosniff => {+ async_test(t => {+ const l = document.createElement("link");+ t.add_cleanup(() => l.remove());+ if (nosniff === "nosniff" || contentType === "wrong Content-Type" && (document.compatMode === "CSS1Compat" || originType[0] === "cross-origin")) {+ l.onerror = t.step_func_done();+ l.onload = t.unreached_func("error event should have fired");+ } else {+ l.onload = t.step_func_done();+ l.onerror = t.unreached_func("load event should have fired");+ }+ l.rel = "stylesheet";+ let query = [];+ if (contentType === "broken Content-Type") {+ query.push("content_type=oops");+ } else if (contentType === "wrong Content-Type") {+ query.push("content_type=text/plain")+ }+ if (nosniff === "nosniff") {+ query.push("nosniff");+ }+ let stringQuery = "";+ query.forEach(val => {+ if (stringQuery === "") {+ stringQuery += "?" + val;+ } else {+ stringQuery += "&" + val;+ }+ });+ const link = new URL(originType[1] + stringQuery, location).href;+ if (linkType === "<link>") {+ l.href = link;+ } else {+ l.href = "data:text/css,@import url(" + link + ");";+ }+ document.head.appendChild(l);+ }, "Stylesheet loading using " + linkType + " with " + contentType + ", " + originType[0] + ", and " + nosniff);+ });+ });+ });+});