From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../domparsing/resources/domparser-url-tests.js | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 testing/web-platform/tests/domparsing/resources/domparser-url-tests.js (limited to 'testing/web-platform/tests/domparsing/resources/domparser-url-tests.js') diff --git a/testing/web-platform/tests/domparsing/resources/domparser-url-tests.js b/testing/web-platform/tests/domparsing/resources/domparser-url-tests.js new file mode 100644 index 0000000000..7b02fab1c3 --- /dev/null +++ b/testing/web-platform/tests/domparsing/resources/domparser-url-tests.js @@ -0,0 +1,72 @@ +const loadPromise = new Promise(resolve => { window.resolveLoadPromise = resolve; }); + +function assertURL(doc, expectedURL) { + assert_equals(doc.URL, expectedURL, "document.URL"); + assert_equals(doc.documentURI, expectedURL, "document.documentURI"); + assert_equals(doc.baseURI, expectedURL, "document.baseURI"); +} + +const supportedTypes = [ + "text/html", + "text/xml", + "application/xml", + "application/xhtml+xml", + "image/svg+xml", +]; + +const invalidXML = `1`; +const inputs = { + valid: "", + "invalid XML": invalidXML +}; + +for (const mimeType of supportedTypes) { + for (const [inputName, input] of Object.entries(inputs)) { + if (mimeType === "text/html" && input === invalidXML) { + continue; + } + + test(() => { + const parser = new DOMParser(); + const doc = parser.parseFromString(input, mimeType); + + assertURL(doc, document.URL); + }, `${mimeType} ${inputName}: created normally`); + + promise_test(async () => { + await loadPromise; + + const parser = new frames[0].DOMParser(); + const doc = parser.parseFromString(input, mimeType); + + assertURL(doc, frames[0].document.URL); + }, `${mimeType} ${inputName}: created using another iframe's DOMParser from this frame`); + + promise_test(async () => { + await loadPromise; + + const parser = new frames[0].DOMParser(); + const doc = frames[0].doParse(input, mimeType); + + assertURL(doc, frames[0].document.URL); + }, `${mimeType} ${inputName}: created using another iframe's DOMParser from that frame`); + + promise_test(async () => { + await loadPromise; + + const parser = new DOMParser(); + const doc = frames[0].DOMParser.prototype.parseFromString.call(parser, input, mimeType); + + assertURL(doc, document.URL); + }, `${mimeType} ${inputName}: created using a parser from this frame and the method from the iframe`); + + promise_test(async () => { + await loadPromise; + + const parser = new frames[0].DOMParser(); + const doc = DOMParser.prototype.parseFromString.call(parser, input, mimeType); + + assertURL(doc, frames[0].document.URL); + }, `${mimeType} ${inputName}: created using a parser from the iframe and the method from this frame`); + } +} -- cgit v1.2.3