Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | "use strict"; |
michael@0 | 4 | |
michael@0 | 5 | const STACK_THICKNESS = 15; |
michael@0 | 6 | |
michael@0 | 7 | function init(callback) { |
michael@0 | 8 | let iframe = gBrowser.ownerDocument.createElement("iframe"); |
michael@0 | 9 | |
michael@0 | 10 | iframe.addEventListener("load", function onLoad() { |
michael@0 | 11 | iframe.removeEventListener("load", onLoad, true); |
michael@0 | 12 | callback(iframe); |
michael@0 | 13 | |
michael@0 | 14 | gBrowser.parentNode.removeChild(iframe); |
michael@0 | 15 | finish(); |
michael@0 | 16 | }, true); |
michael@0 | 17 | |
michael@0 | 18 | iframe.setAttribute("src", ["data:text/html,", |
michael@0 | 19 | "<!DOCTYPE html>", |
michael@0 | 20 | "<html>", |
michael@0 | 21 | "<body style='margin: 0;'>", |
michael@0 | 22 | "<div>", |
michael@0 | 23 | "<p>Foo</p>", |
michael@0 | 24 | "<div>", |
michael@0 | 25 | "<span>Bar</span>", |
michael@0 | 26 | "</div>", |
michael@0 | 27 | "<div></div>", |
michael@0 | 28 | "</div>", |
michael@0 | 29 | "</body>", |
michael@0 | 30 | "</html>" |
michael@0 | 31 | ].join("")); |
michael@0 | 32 | |
michael@0 | 33 | gBrowser.parentNode.appendChild(iframe); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function nodeCallback(aContentWindow, aNode, aParentPosition) { |
michael@0 | 37 | let coord = TiltUtils.DOM.getNodePosition(aContentWindow, aNode, aParentPosition); |
michael@0 | 38 | |
michael@0 | 39 | if (aNode.localName != "div") |
michael@0 | 40 | coord.thickness = 0; |
michael@0 | 41 | |
michael@0 | 42 | if (aNode.localName == "span") |
michael@0 | 43 | coord.depth += STACK_THICKNESS; |
michael@0 | 44 | |
michael@0 | 45 | return coord; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function test() { |
michael@0 | 49 | waitForExplicitFinish(); |
michael@0 | 50 | ok(TiltUtils, "The TiltUtils object doesn't exist."); |
michael@0 | 51 | |
michael@0 | 52 | let dom = TiltUtils.DOM; |
michael@0 | 53 | ok(dom, "The TiltUtils.DOM wasn't found."); |
michael@0 | 54 | |
michael@0 | 55 | init(function(iframe) { |
michael@0 | 56 | let store = dom.traverse(iframe.contentWindow, { |
michael@0 | 57 | nodeCallback: nodeCallback |
michael@0 | 58 | }); |
michael@0 | 59 | |
michael@0 | 60 | let expected = [ |
michael@0 | 61 | { name: "html", depth: 0 * STACK_THICKNESS, thickness: 0 }, |
michael@0 | 62 | { name: "head", depth: 0 * STACK_THICKNESS, thickness: 0 }, |
michael@0 | 63 | { name: "body", depth: 0 * STACK_THICKNESS, thickness: 0 }, |
michael@0 | 64 | { name: "div", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS }, |
michael@0 | 65 | { name: "p", depth: 1 * STACK_THICKNESS, thickness: 0 }, |
michael@0 | 66 | { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, |
michael@0 | 67 | { name: "div", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, |
michael@0 | 68 | { name: "span", depth: 3 * STACK_THICKNESS, thickness: 0 }, |
michael@0 | 69 | ]; |
michael@0 | 70 | |
michael@0 | 71 | is(store.nodes.length, expected.length, |
michael@0 | 72 | "The traverse() function didn't walk the correct number of nodes."); |
michael@0 | 73 | is(store.info.length, expected.length, |
michael@0 | 74 | "The traverse() function didn't examine the correct number of nodes."); |
michael@0 | 75 | |
michael@0 | 76 | for (let i = 0; i < expected.length; i++) { |
michael@0 | 77 | is(store.info[i].name, expected[i].name, |
michael@0 | 78 | "traversed node " + (i + 1) + " isn't the expected one."); |
michael@0 | 79 | is(store.info[i].coord.depth, expected[i].depth, |
michael@0 | 80 | "traversed node " + (i + 1) + " doesn't have the expected depth."); |
michael@0 | 81 | is(store.info[i].coord.thickness, expected[i].thickness, |
michael@0 | 82 | "traversed node " + (i + 1) + " doesn't have the expected thickness."); |
michael@0 | 83 | } |
michael@0 | 84 | }); |
michael@0 | 85 | } |