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 --- .../test/browser_layoutHelpers_getBoxQuads1.js | 353 +++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 devtools/client/shared/test/browser_layoutHelpers_getBoxQuads1.js (limited to 'devtools/client/shared/test/browser_layoutHelpers_getBoxQuads1.js') diff --git a/devtools/client/shared/test/browser_layoutHelpers_getBoxQuads1.js b/devtools/client/shared/test/browser_layoutHelpers_getBoxQuads1.js new file mode 100644 index 0000000000..a8119df3fd --- /dev/null +++ b/devtools/client/shared/test/browser_layoutHelpers_getBoxQuads1.js @@ -0,0 +1,353 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests getAdjustedQuads works properly in a variety of use cases including +// iframes, scroll and zoom + +"use strict"; + +const TEST_URI = TEST_URI_ROOT + "doc_layoutHelpers_getBoxQuads1.html"; + +add_task(async function () { + const tab = await addTab(TEST_URI); + + info("Running tests"); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + // This function allows the Content Task to easily call `FullZoom` API in + // the parent process. + function sendCommand(cmd) { + return SpecialPowers.spawnChrome([cmd], async data => { + const window = this.browsingContext.topChromeWindow; + switch (data) { + case "zoom-enlarge": + window.FullZoom.enlarge(); + break; + case "zoom-reset": + await window.FullZoom.reset(); + break; + case "zoom-reduce": + window.FullZoom.reduce(); + break; + } + }); + } + + const doc = content.document; + + const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" + ); + const { + getAdjustedQuads, + } = require("resource://devtools/shared/layout/utils.js"); + + Assert.strictEqual( + typeof getAdjustedQuads, + "function", + "getAdjustedQuads is defined" + ); + + returnsTheRightDataStructure(); + isEmptyForMissingNode(); + isEmptyForHiddenNodes(); + defaultsToBorderBoxIfNoneProvided(); + returnsLikeGetBoxQuadsInSimpleCase(); + takesIframesOffsetsIntoAccount(); + takesScrollingIntoAccount(); + await takesZoomIntoAccount(); + returnsMultipleItemsForWrappingInlineElements(); + + function returnsTheRightDataStructure() { + info("Checks that the returned data contains bounds and 4 points"); + + const node = doc.querySelector("body"); + const [res] = getAdjustedQuads(doc.defaultView, node, "content"); + + ok("bounds" in res, "The returned data has a bounds property"); + ok("p1" in res, "The returned data has a p1 property"); + ok("p2" in res, "The returned data has a p2 property"); + ok("p3" in res, "The returned data has a p3 property"); + ok("p4" in res, "The returned data has a p4 property"); + + for (const boundProp of [ + "bottom", + "top", + "right", + "left", + "width", + "height", + "x", + "y", + ]) { + ok( + boundProp in res.bounds, + "The bounds has a " + boundProp + " property" + ); + } + + for (const point of ["p1", "p2", "p3", "p4"]) { + for (const pointProp of ["x", "y", "z", "w"]) { + ok( + pointProp in res[point], + point + " has a " + pointProp + " property" + ); + } + } + } + + function isEmptyForMissingNode() { + info("Checks that null is returned for invalid nodes"); + + for (const input of [null, undefined, "", 0]) { + is( + getAdjustedQuads(doc.defaultView, input).length, + 0, + "A 0-length array is returned for input " + input + ); + } + } + + function isEmptyForHiddenNodes() { + info("Checks that null is returned for nodes that aren't rendered"); + + const style = doc.querySelector("#styles"); + is( + getAdjustedQuads(doc.defaultView, style).length, + 0, + "null is returned for a