browser/devtools/tilt/test/browser_tilt_utils07.js

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:0da8a8640fbd
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3 "use strict";
4
5 const STACK_THICKNESS = 15;
6
7 function init(callback) {
8 let iframe = gBrowser.ownerDocument.createElement("iframe");
9
10 iframe.addEventListener("load", function onLoad() {
11 iframe.removeEventListener("load", onLoad, true);
12 callback(iframe);
13
14 gBrowser.parentNode.removeChild(iframe);
15 finish();
16 }, true);
17
18 iframe.setAttribute("src", ["data:text/html,",
19 "<!DOCTYPE html>",
20 "<html>",
21 "<body style='margin: 0;'>",
22 "<frameset cols='50%,50%'>",
23 "<frame src='",
24 ["data:text/html,",
25 "<!DOCTYPE html>",
26 "<html>",
27 "<body style='margin: 0;'>",
28 "<div id='test-div' style='width: 123px; height: 456px;'></div>",
29 "</body>",
30 "</html>"
31 ].join(""),
32 "' />",
33 "<frame src='",
34 ["data:text/html,",
35 "<!DOCTYPE html>",
36 "<html>",
37 "<body style='margin: 0;'>",
38 "<span></span>",
39 "</body>",
40 "</html>"
41 ].join(""),
42 "' />",
43 "</frameset>",
44 "<iframe src='",
45 ["data:text/html,",
46 "<!DOCTYPE html>",
47 "<html>",
48 "<body>",
49 "<span></span>",
50 "</body>",
51 "</html>"
52 ].join(""),
53 "'></iframe>",
54 "<frame src='",
55 ["data:text/html,",
56 "<!DOCTYPE html>",
57 "<html>",
58 "<body style='margin: 0;'>",
59 "<span></span>",
60 "</body>",
61 "</html>"
62 ].join(""),
63 "' />",
64 "<frame src='",
65 ["data:text/html,",
66 "<!DOCTYPE html>",
67 "<html>",
68 "<body style='margin: 0;'>",
69 "<iframe src='",
70 ["data:text/html,",
71 "<!DOCTYPE html>",
72 "<html>",
73 "<body>",
74 "<div></div>",
75 "</body>",
76 "</html>"
77 ].join(""),
78 "'></iframe>",
79 "</body>",
80 "</html>"
81 ].join(""),
82 "' />",
83 "</body>",
84 "</html>"
85 ].join(""));
86
87 gBrowser.parentNode.appendChild(iframe);
88 }
89
90 function test() {
91 waitForExplicitFinish();
92 ok(TiltUtils, "The TiltUtils object doesn't exist.");
93
94 let dom = TiltUtils.DOM;
95 ok(dom, "The TiltUtils.DOM wasn't found.");
96
97 init(function(iframe) {
98 let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow);
99
100 is(cwDimensions.width - iframe.contentWindow.scrollMaxX,
101 iframe.contentWindow.innerWidth,
102 "The content window width wasn't calculated correctly.");
103 is(cwDimensions.height - iframe.contentWindow.scrollMaxY,
104 iframe.contentWindow.innerHeight,
105 "The content window height wasn't calculated correctly.");
106
107 let lh = new LayoutHelpers(gBrowser.contentWindow);
108 let nodeCoordinates = lh.getRect(
109 iframe.contentDocument.getElementById("test-div"), iframe.contentWindow);
110
111 let frameOffset = lh.getIframeContentOffset(iframe);
112 let frameRect = iframe.getBoundingClientRect();
113
114 is(nodeCoordinates.top, frameRect.top + frameOffset[0],
115 "The node coordinates top value wasn't calculated correctly.");
116 is(nodeCoordinates.left, frameRect.left + frameOffset[1],
117 "The node coordinates left value wasn't calculated correctly.");
118 is(nodeCoordinates.width, 123,
119 "The node coordinates width value wasn't calculated correctly.");
120 is(nodeCoordinates.height, 456,
121 "The node coordinates height value wasn't calculated correctly.");
122
123
124 let store = dom.traverse(iframe.contentWindow);
125
126 let expected = [
127 { name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
128 { name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
129 { name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
130 { name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
131 { name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
132 { name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
133 { name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
134 { name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
135 { name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
136 { name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
137 { name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
138 { name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
139 { name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
140 { name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS },
141 { name: "span", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS },
142 { name: "div", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS },
143 ];
144
145 is(store.nodes.length, expected.length,
146 "The traverse() function didn't walk the correct number of nodes.");
147 is(store.info.length, expected.length,
148 "The traverse() function didn't examine the correct number of nodes.");
149
150 for (let i = 0; i < expected.length; i++) {
151 is(store.info[i].name, expected[i].name,
152 "traversed node " + (i + 1) + " isn't the expected one.");
153 is(store.info[i].coord.depth, expected[i].depth,
154 "traversed node " + (i + 1) + " doesn't have the expected depth.");
155 is(store.info[i].coord.thickness, expected[i].thickness,
156 "traversed node " + (i + 1) + " doesn't have the expected thickness.");
157 }
158 });
159 }

mercurial