From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../test/browser_layoutHelpers-getBoxQuads.js | 219 +++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 devtools/client/shared/test/browser_layoutHelpers-getBoxQuads.js (limited to 'devtools/client/shared/test/browser_layoutHelpers-getBoxQuads.js') diff --git a/devtools/client/shared/test/browser_layoutHelpers-getBoxQuads.js b/devtools/client/shared/test/browser_layoutHelpers-getBoxQuads.js new file mode 100644 index 000000000..221127a11 --- /dev/null +++ b/devtools/client/shared/test/browser_layoutHelpers-getBoxQuads.js @@ -0,0 +1,219 @@ +/* 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 {getAdjustedQuads} = require("devtools/shared/layout/utils"); + +const TEST_URI = TEST_URI_ROOT + "browser_layoutHelpers-getBoxQuads.html"; + +add_task(function* () { + let tab = yield addTab(TEST_URI); + let doc = tab.linkedBrowser.contentDocument; + + ok(typeof getAdjustedQuads === "function", "getAdjustedQuads is defined"); + + info("Running tests"); + + returnsTheRightDataStructure(doc); + isEmptyForMissingNode(doc); + isEmptyForHiddenNodes(doc); + defaultsToBorderBoxIfNoneProvided(doc); + returnsLikeGetBoxQuadsInSimpleCase(doc); + takesIframesOffsetsIntoAccount(doc); + takesScrollingIntoAccount(doc); + yield takesZoomIntoAccount(doc); + returnsMultipleItemsForWrappingInlineElements(doc); + + gBrowser.removeCurrentTab(); +}); + +function returnsTheRightDataStructure(doc) { + info("Checks that the returned data contains bounds and 4 points"); + + let node = doc.querySelector("body"); + let [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 (let boundProp of + ["bottom", "top", "right", "left", "width", "height", "x", "y"]) { + ok(boundProp in res.bounds, "The bounds has a " + boundProp + " property"); + } + + for (let point of ["p1", "p2", "p3", "p4"]) { + for (let pointProp of ["x", "y", "z", "w"]) { + ok(pointProp in res[point], point + " has a " + pointProp + " property"); + } + } +} + +function isEmptyForMissingNode(doc) { + info("Checks that null is returned for invalid nodes"); + + for (let input of [null, undefined, "", 0]) { + is(getAdjustedQuads(doc.defaultView, input).length, 0, + "A 0-length array is returned for input " + input); + } +} + +function isEmptyForHiddenNodes(doc) { + info("Checks that null is returned for nodes that aren't rendered"); + + let style = doc.querySelector("#styles"); + is(getAdjustedQuads(doc.defaultView, style).length, 0, + "null is returned for a