Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
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 "<head>",
22 "<style>",
23 "</style>",
24 "<script>",
25 "</script>",
26 "</head>",
27 "<body style='margin: 0;'>",
28 "<div style='margin-top: 98px;" +
29 "margin-left: 76px;" +
30 "width: 123px;" +
31 "height: 456px;' id='test-div'>",
32 "<span></span>",
33 "</div>",
34 "</body>",
35 "</html>"
36 ].join(""));
38 gBrowser.parentNode.appendChild(iframe);
39 }
41 function test() {
42 waitForExplicitFinish();
43 ok(TiltUtils, "The TiltUtils object doesn't exist.");
45 let dom = TiltUtils.DOM;
46 ok(dom, "The TiltUtils.DOM wasn't found.");
48 init(function(iframe) {
49 let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow);
51 is(cwDimensions.width - iframe.contentWindow.scrollMaxX,
52 iframe.contentWindow.innerWidth,
53 "The content window width wasn't calculated correctly.");
54 is(cwDimensions.height - iframe.contentWindow.scrollMaxY,
55 iframe.contentWindow.innerHeight,
56 "The content window height wasn't calculated correctly.");
58 let lh = new LayoutHelpers(gBrowser.contentWindow);
59 let nodeCoordinates = lh.getRect(
60 iframe.contentDocument.getElementById("test-div"), iframe.contentWindow);
62 let frameOffset = lh.getIframeContentOffset(iframe);
63 let frameRect = iframe.getBoundingClientRect();
65 is(nodeCoordinates.top, frameRect.top + frameOffset[0] + 98,
66 "The node coordinates top value wasn't calculated correctly.");
67 is(nodeCoordinates.left, frameRect.left + frameOffset[1] + 76,
68 "The node coordinates left value wasn't calculated correctly.");
69 is(nodeCoordinates.width, 123,
70 "The node coordinates width value wasn't calculated correctly.");
71 is(nodeCoordinates.height, 456,
72 "The node coordinates height value wasn't calculated correctly.");
75 let store = dom.traverse(iframe.contentWindow);
77 let expected = [
78 { name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
79 { name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
80 { name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
81 { name: "style", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
82 { name: "script", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
83 { name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
84 { name: "span", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
85 ];
87 is(store.nodes.length, expected.length,
88 "The traverse() function didn't walk the correct number of nodes.");
89 is(store.info.length, expected.length,
90 "The traverse() function didn't examine the correct number of nodes.");
92 for (let i = 0; i < expected.length; i++) {
93 is(store.info[i].name, expected[i].name,
94 "traversed node " + (i + 1) + " isn't the expected one.");
95 is(store.info[i].coord.depth, expected[i].depth,
96 "traversed node " + (i + 1) + " doesn't have the expected depth.");
97 is(store.info[i].coord.thickness, expected[i].thickness,
98 "traversed node " + (i + 1) + " doesn't have the expected thickness.");
99 }
100 });
101 }