/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ // Tests that LayoutHelpers.getAdjustedQuads works properly in a variety of use // cases including iframes, scroll and zoom const {utils: Cu} = Components; const LayoutHelpers = require("devtools/toolkit/layout-helpers"); const TEST_URI = TEST_URI_ROOT + "browser_layoutHelpers-getBoxQuads.html"; function test() { addTab(TEST_URI, function(browser, tab) { let doc = browser.contentDocument; let win = doc.defaultView; info("Creating a new LayoutHelpers instance for the test window"); let helper = new LayoutHelpers(win); ok(helper.getAdjustedQuads, "getAdjustedQuads is defined"); info("Running tests"); returnsTheRightDataStructure(doc, helper); isEmptyForMissingNode(doc, helper); isEmptyForHiddenNodes(doc, helper); defaultsToBorderBoxIfNoneProvided(doc, helper); returnsLikeGetBoxQuadsInSimpleCase(doc, helper); takesIframesOffsetsIntoAccount(doc, helper); takesScrollingIntoAccount(doc, helper); takesZoomIntoAccount(doc, helper); returnsMultipleItemsForWrappingInlineElements(doc, helper); gBrowser.removeCurrentTab(); finish(); }); } function returnsTheRightDataStructure(doc, helper) { info("Checks that the returned data contains bounds and 4 points"); let node = doc.querySelector("body"); let [res] = helper.getAdjustedQuads(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, helper) { info("Checks that null is returned for invalid nodes"); for (let input of [null, undefined, "", 0]) { is(helper.getAdjustedQuads(input).length, 0, "A 0-length array is returned" + "for input " + input); } } function isEmptyForHiddenNodes(doc, helper) { info("Checks that null is returned for nodes that aren't rendered"); let style = doc.querySelector("#styles"); is(helper.getAdjustedQuads(style).length, 0, "null is returned for a