diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/css/cssom-view/resources | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/cssom-view/resources')
4 files changed, 149 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/cssom-view/resources/elementsFromPoint.js b/testing/web-platform/tests/css/cssom-view/resources/elementsFromPoint.js new file mode 100644 index 0000000000..ba986ef3f5 --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/resources/elementsFromPoint.js @@ -0,0 +1,48 @@ +function nodeToString(node) { + var str = ''; + if (node.nodeType == Node.ELEMENT_NODE) { + str += node.nodeName; + if (node.id) + str += '#' + node.id; + else if (node.class) + str += '.' + node.class; + } else if (node.nodeType == Node.TEXT_NODE) { + str += '\'' + node.data + '\''; + } else if (node.nodeType == Node.DOCUMENT_NODE) { + str += '#document'; + } + return str; +} + +function nodeListToString(nodes) { + var nodeString = ''; + + for (var i = 0; i < nodes.length; i++) { + var str = nodeToString(nodes[i]); + if (!str) + continue; + nodeString += str; + if (i + 1 < nodes.length) + nodeString += ', '; + } + return nodeString; +} + +function assertElementsFromPoint(doc, x, y, expected) { + var query = doc + '.elementsFromPoint(' + x + ',' + y + ')'; + var sequence = eval(query); + assert_equals(nodeListToString(sequence), nodeListToString(expected), query); +} + +function checkElementsFromPointFourCorners(doc, element, expectedTopLeft, expectedTopRight, expectedBottomLeft, expectedBottomRight) { + var rect = eval(doc + '.getElementById(\'' + element + '\')').getBoundingClientRect(); + var topLeft = {x: rect.left + 1, y: rect.top + 1}; + var topRight = {x: rect.right - 1, y: rect.top + 1}; + var bottomLeft = {x: rect.left + 1, y: rect.bottom - 1}; + var bottomRight = {x: rect.right - 1, y: rect.bottom - 1}; + + assertElementsFromPoint(doc, topLeft.x, topLeft.y, expectedTopLeft); + assertElementsFromPoint(doc, topRight.x, topRight.y, expectedTopRight); + assertElementsFromPoint(doc, bottomLeft.x, bottomLeft.y, expectedBottomLeft); + assertElementsFromPoint(doc, bottomRight.x, bottomRight.y, expectedBottomRight); +} diff --git a/testing/web-platform/tests/css/cssom-view/resources/iframe1.html b/testing/web-platform/tests/css/cssom-view/resources/iframe1.html new file mode 100644 index 0000000000..ec4699465d --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/resources/iframe1.html @@ -0,0 +1,16 @@ +<!DOCTYPE HTML> +<style> +html, body { + margin: 0; + padding: 0; +} +#div { + width: 100px; + height: 100px; + background: red; +} +</style> +<div id='div'></div> +<script> +window.onload = window.parent.onFrameLoaded(); +</script> diff --git a/testing/web-platform/tests/css/cssom-view/resources/iframe2.html b/testing/web-platform/tests/css/cssom-view/resources/iframe2.html new file mode 100644 index 0000000000..7bb944c9d5 --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/resources/iframe2.html @@ -0,0 +1,25 @@ +<!DOCTYPE HTML> +<style> +html, body { + margin: 0; + padding: 0; +} +#big { + width: 125px; + height: 500px; + background: blue; +} +#small { + position: absolute; + top: 0; + left: 0; + width: 100px; + height: 100px; + background: green; +} +</style> +<div id='big'></div> +<div id='small'></div> +<script> +window.onload = window.parent.onFrameLoaded(); +</script> diff --git a/testing/web-platform/tests/css/cssom-view/resources/matchMedia.js b/testing/web-platform/tests/css/cssom-view/resources/matchMedia.js new file mode 100644 index 0000000000..f8947e0472 --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/resources/matchMedia.js @@ -0,0 +1,60 @@ +"use strict"; + +{ +// private variables are defined with `const` so they don't leak outside this block statement +const IFRAME_DEFAULT_SIZE = "200"; +const iframes = new WeakMap(); + +// helpers are defined with `var` so they are globally accessible +var createMQL = async t => { + const iframe = await createIFrame(t); + const mql = iframe.contentWindow.matchMedia(`(max-width: ${IFRAME_DEFAULT_SIZE}px)`); + assert_true(mql.matches, "MQL should match on newly created <iframe>"); + iframes.set(mql, iframe); + return mql; +}; + +var createIFrame = (t, width = IFRAME_DEFAULT_SIZE, height = width) => { + assert_not_equals(document.body, null, "<body> element is missing"); + + const iframe = document.createElement("iframe"); + iframe.srcdoc = ""; + iframe.width = String(width); + iframe.height = String(height); + iframe.style.border = "none"; + + t.add_cleanup(() => { + document.body.removeChild(iframe); + }); + + return new Promise(resolve => { + iframe.addEventListener("load", () => { + iframe.contentDocument.body.offsetWidth; // reflow + resolve(iframe); + }); + + document.body.appendChild(iframe); + }); +}; + +var triggerMQLEvent = mql => { + const iframe = iframes.get(mql); + assert_not_equals(iframe, undefined, "Passed MQL instance was not created with createMQL"); + iframe.width = iframe.width === IFRAME_DEFAULT_SIZE ? "250" : IFRAME_DEFAULT_SIZE; +}; + +var getWindow = mql => { + const iframe = iframes.get(mql); + assert_not_equals(iframe, undefined, "Passed MQL instance was not created with createMQL"); + return iframe.contentWindow; +}; + +var waitForChangesReported = () => { + return new Promise(resolve => { + requestAnimationFrame(() => { + requestAnimationFrame(resolve); + }); + }); +}; + +} |