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