1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_utils08.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +const STACK_THICKNESS = 15; 1.9 + 1.10 +function init(callback) { 1.11 + let iframe = gBrowser.ownerDocument.createElement("iframe"); 1.12 + 1.13 + iframe.addEventListener("load", function onLoad() { 1.14 + iframe.removeEventListener("load", onLoad, true); 1.15 + callback(iframe); 1.16 + 1.17 + gBrowser.parentNode.removeChild(iframe); 1.18 + finish(); 1.19 + }, true); 1.20 + 1.21 + iframe.setAttribute("src", ["data:text/html,", 1.22 + "<!DOCTYPE html>", 1.23 + "<html>", 1.24 + "<body style='margin: 0;'>", 1.25 + "<div>", 1.26 + "<p>Foo</p>", 1.27 + "<div>", 1.28 + "<span>Bar</span>", 1.29 + "</div>", 1.30 + "<div></div>", 1.31 + "</div>", 1.32 + "</body>", 1.33 + "</html>" 1.34 + ].join("")); 1.35 + 1.36 + gBrowser.parentNode.appendChild(iframe); 1.37 +} 1.38 + 1.39 +function nodeCallback(aContentWindow, aNode, aParentPosition) { 1.40 + let coord = TiltUtils.DOM.getNodePosition(aContentWindow, aNode, aParentPosition); 1.41 + 1.42 + if (aNode.localName != "div") 1.43 + coord.thickness = 0; 1.44 + 1.45 + if (aNode.localName == "span") 1.46 + coord.depth += STACK_THICKNESS; 1.47 + 1.48 + return coord; 1.49 +} 1.50 + 1.51 +function test() { 1.52 + waitForExplicitFinish(); 1.53 + ok(TiltUtils, "The TiltUtils object doesn't exist."); 1.54 + 1.55 + let dom = TiltUtils.DOM; 1.56 + ok(dom, "The TiltUtils.DOM wasn't found."); 1.57 + 1.58 + init(function(iframe) { 1.59 + let store = dom.traverse(iframe.contentWindow, { 1.60 + nodeCallback: nodeCallback 1.61 + }); 1.62 + 1.63 + let expected = [ 1.64 + { name: "html", depth: 0 * STACK_THICKNESS, thickness: 0 }, 1.65 + { name: "head", depth: 0 * STACK_THICKNESS, thickness: 0 }, 1.66 + { name: "body", depth: 0 * STACK_THICKNESS, thickness: 0 }, 1.67 + { name: "div", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.68 + { name: "p", depth: 1 * STACK_THICKNESS, thickness: 0 }, 1.69 + { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.70 + { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.71 + { name: "span", depth: 3 * STACK_THICKNESS, thickness: 0 }, 1.72 + ]; 1.73 + 1.74 + is(store.nodes.length, expected.length, 1.75 + "The traverse() function didn't walk the correct number of nodes."); 1.76 + is(store.info.length, expected.length, 1.77 + "The traverse() function didn't examine the correct number of nodes."); 1.78 + 1.79 + for (let i = 0; i < expected.length; i++) { 1.80 + is(store.info[i].name, expected[i].name, 1.81 + "traversed node " + (i + 1) + " isn't the expected one."); 1.82 + is(store.info[i].coord.depth, expected[i].depth, 1.83 + "traversed node " + (i + 1) + " doesn't have the expected depth."); 1.84 + is(store.info[i].coord.thickness, expected[i].thickness, 1.85 + "traversed node " + (i + 1) + " doesn't have the expected thickness."); 1.86 + } 1.87 + }); 1.88 +}