michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0: "use strict";
michael@0:
michael@0: const STACK_THICKNESS = 15;
michael@0:
michael@0: function init(callback) {
michael@0: let iframe = gBrowser.ownerDocument.createElement("iframe");
michael@0:
michael@0: iframe.addEventListener("load", function onLoad() {
michael@0: iframe.removeEventListener("load", onLoad, true);
michael@0: callback(iframe);
michael@0:
michael@0: gBrowser.parentNode.removeChild(iframe);
michael@0: finish();
michael@0: }, true);
michael@0:
michael@0: iframe.setAttribute("src", ["data:text/html,",
michael@0: "",
michael@0: "",
michael@0: "
",
michael@0: "",
michael@0: "",
michael@0: "",
michael@0: "",
michael@0: "",
michael@0: "",
michael@0: "
",
michael@0: "",
michael@0: ""
michael@0: ].join(""));
michael@0:
michael@0: gBrowser.parentNode.appendChild(iframe);
michael@0: }
michael@0:
michael@0: function test() {
michael@0: waitForExplicitFinish();
michael@0: ok(TiltUtils, "The TiltUtils object doesn't exist.");
michael@0:
michael@0: let dom = TiltUtils.DOM;
michael@0: ok(dom, "The TiltUtils.DOM wasn't found.");
michael@0:
michael@0: init(function(iframe) {
michael@0: let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow);
michael@0:
michael@0: is(cwDimensions.width - iframe.contentWindow.scrollMaxX,
michael@0: iframe.contentWindow.innerWidth,
michael@0: "The content window width wasn't calculated correctly.");
michael@0: is(cwDimensions.height - iframe.contentWindow.scrollMaxY,
michael@0: iframe.contentWindow.innerHeight,
michael@0: "The content window height wasn't calculated correctly.");
michael@0:
michael@0: let lh = new LayoutHelpers(gBrowser.contentWindow);
michael@0: let nodeCoordinates = lh.getRect(
michael@0: iframe.contentDocument.getElementById("test-div"), iframe.contentWindow);
michael@0:
michael@0: let frameOffset = lh.getIframeContentOffset(iframe);
michael@0: let frameRect = iframe.getBoundingClientRect();
michael@0:
michael@0: is(nodeCoordinates.top, frameRect.top + frameOffset[0] + 98,
michael@0: "The node coordinates top value wasn't calculated correctly.");
michael@0: is(nodeCoordinates.left, frameRect.left + frameOffset[1] + 76,
michael@0: "The node coordinates left value wasn't calculated correctly.");
michael@0: is(nodeCoordinates.width, 123,
michael@0: "The node coordinates width value wasn't calculated correctly.");
michael@0: is(nodeCoordinates.height, 456,
michael@0: "The node coordinates height value wasn't calculated correctly.");
michael@0:
michael@0:
michael@0: let store = dom.traverse(iframe.contentWindow);
michael@0:
michael@0: let expected = [
michael@0: { name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "style", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "script", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: { name: "span", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0: ];
michael@0:
michael@0: is(store.nodes.length, expected.length,
michael@0: "The traverse() function didn't walk the correct number of nodes.");
michael@0: is(store.info.length, expected.length,
michael@0: "The traverse() function didn't examine the correct number of nodes.");
michael@0:
michael@0: for (let i = 0; i < expected.length; i++) {
michael@0: is(store.info[i].name, expected[i].name,
michael@0: "traversed node " + (i + 1) + " isn't the expected one.");
michael@0: is(store.info[i].coord.depth, expected[i].depth,
michael@0: "traversed node " + (i + 1) + " doesn't have the expected depth.");
michael@0: is(store.info[i].coord.thickness, expected[i].thickness,
michael@0: "traversed node " + (i + 1) + " doesn't have the expected thickness.");
michael@0: }
michael@0: });
michael@0: }