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: "

Foo

", michael@0: "
", michael@0: "Bar", 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 nodeCallback(aContentWindow, aNode, aParentPosition) { michael@0: let coord = TiltUtils.DOM.getNodePosition(aContentWindow, aNode, aParentPosition); michael@0: michael@0: if (aNode.localName != "div") michael@0: coord.thickness = 0; michael@0: michael@0: if (aNode.localName == "span") michael@0: coord.depth += STACK_THICKNESS; michael@0: michael@0: return coord; 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 store = dom.traverse(iframe.contentWindow, { michael@0: nodeCallback: nodeCallback michael@0: }); michael@0: michael@0: let expected = [ michael@0: { name: "html", depth: 0 * STACK_THICKNESS, thickness: 0 }, michael@0: { name: "head", depth: 0 * STACK_THICKNESS, thickness: 0 }, michael@0: { name: "body", depth: 0 * STACK_THICKNESS, thickness: 0 }, michael@0: { name: "div", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS }, michael@0: { name: "p", depth: 1 * STACK_THICKNESS, thickness: 0 }, michael@0: { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, michael@0: { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, michael@0: { name: "span", depth: 3 * STACK_THICKNESS, thickness: 0 }, 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: }