2150 |
mathias |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
2 |
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
3 |
<!--
|
|
|
4 |
we use a strict-mode DTD to ensure that the box model is the same for these
|
|
|
5 |
basic tests
|
|
|
6 |
-->
|
|
|
7 |
<html>
|
|
|
8 |
<head>
|
|
|
9 |
<title>testing Core HTML/DOM/CSS/Style utils</title>
|
|
|
10 |
<style type="text/css">
|
|
|
11 |
@import "../../resources/dojo.css";
|
|
|
12 |
</style>
|
|
|
13 |
<script type="text/javascript"
|
|
|
14 |
src="../../dojo.js"
|
|
|
15 |
djConfig="isDebug: true"></script>
|
|
|
16 |
<script type="text/javascript">
|
|
|
17 |
dojo.require("doh.runner");
|
|
|
18 |
|
|
|
19 |
function getIframeDocument(/*DOMNode*/iframeNode){
|
|
|
20 |
//summary: Returns the document object associated with the iframe DOM Node argument.
|
|
|
21 |
var doc = iframeNode.contentDocument || // W3
|
|
|
22 |
(
|
|
|
23 |
(iframeNode.contentWindow)&&(iframeNode.contentWindow.document)
|
|
|
24 |
) || // IE
|
|
|
25 |
(
|
|
|
26 |
(iframeNode.name)&&(document.frames[iframeNode.name])&&
|
|
|
27 |
(document.frames[iframeNode.name].document)
|
|
|
28 |
) || null;
|
|
|
29 |
return doc;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
dojo.addOnLoad(function(){
|
|
|
33 |
doh.register("t",
|
|
|
34 |
[
|
|
|
35 |
"t.is(100, dojo.marginBox('sq100').w);",
|
|
|
36 |
"t.is(100, dojo.marginBox('sq100').h);",
|
|
|
37 |
|
|
|
38 |
"t.is(120, dojo.marginBox('sq100margin10').w);",
|
|
|
39 |
"t.is(120, dojo.marginBox('sq100margin10').h);",
|
|
|
40 |
"t.is(100, dojo.contentBox('sq100margin10').w);",
|
|
|
41 |
"t.is(100, dojo.contentBox('sq100margin10').h);",
|
|
|
42 |
|
|
|
43 |
"t.is(140, dojo.marginBox('sq100margin10pad10').w);",
|
|
|
44 |
"t.is(140, dojo.marginBox('sq100margin10pad10').h);",
|
|
|
45 |
|
|
|
46 |
"t.is(120, dojo.marginBox('sq100pad10').w);",
|
|
|
47 |
"t.is(120, dojo.marginBox('sq100pad10').h);",
|
|
|
48 |
|
|
|
49 |
"t.is(110, dojo.marginBox('sq100ltpad10').w);",
|
|
|
50 |
"t.is(110, dojo.marginBox('sq100ltpad10').h);",
|
|
|
51 |
"t.is(100, dojo.contentBox('sq100ltpad10').w);",
|
|
|
52 |
"t.is(100, dojo.contentBox('sq100ltpad10').h);",
|
|
|
53 |
|
|
|
54 |
"t.is(120, dojo.marginBox('sq100ltpad10rbmargin10').w);",
|
|
|
55 |
"t.is(120, dojo.marginBox('sq100ltpad10rbmargin10').h);",
|
|
|
56 |
|
|
|
57 |
"t.is(120, dojo.marginBox('sq100border10').w);",
|
|
|
58 |
"t.is(120, dojo.marginBox('sq100border10').h);",
|
|
|
59 |
"t.is(100, dojo.contentBox('sq100border10').w);",
|
|
|
60 |
"t.is(100, dojo.contentBox('sq100border10').h);",
|
|
|
61 |
|
|
|
62 |
"t.is(140, dojo.marginBox('sq100border10margin10').w);",
|
|
|
63 |
"t.is(140, dojo.marginBox('sq100border10margin10').h);",
|
|
|
64 |
"t.is(100, dojo.contentBox('sq100border10margin10').w);",
|
|
|
65 |
"t.is(100, dojo.contentBox('sq100border10margin10').h);",
|
|
|
66 |
|
|
|
67 |
"t.is(160, dojo.marginBox('sq100border10margin10pad10').w);",
|
|
|
68 |
"t.is(160, dojo.marginBox('sq100border10margin10pad10').h);",
|
|
|
69 |
"t.is(100, dojo.contentBox('sq100border10margin10pad10').w);",
|
|
|
70 |
"t.is(100, dojo.contentBox('sq100border10margin10pad10').h);",
|
|
|
71 |
|
|
|
72 |
// FIXME: the 'correct' w is not 100 on Safari WebKit (2.0.4 [419.3]), the right-margin extends to the document edge
|
|
|
73 |
// "t.is(100, dojo.marginBox('sq100nopos').w);",
|
|
|
74 |
"t.is(100, dojo.marginBox('sq100nopos').h);",
|
|
|
75 |
|
|
|
76 |
"t.is(10, dojo._getPadExtents(dojo.byId('sq100ltpad10rbmargin10')).l);",
|
|
|
77 |
"t.is(10, dojo._getPadExtents(dojo.byId('sq100ltpad10rbmargin10')).t);",
|
|
|
78 |
"t.is(10, dojo._getPadExtents(dojo.byId('sq100ltpad10rbmargin10')).w);",
|
|
|
79 |
"t.is(10, dojo._getPadExtents(dojo.byId('sq100ltpad10rbmargin10')).h);",
|
|
|
80 |
|
|
|
81 |
"t.is(0, dojo._getMarginExtents(dojo.byId('sq100ltpad10rbmargin10')).l);",
|
|
|
82 |
"t.is(0, dojo._getMarginExtents(dojo.byId('sq100ltpad10rbmargin10')).t);",
|
|
|
83 |
"t.is(10, dojo._getMarginExtents(dojo.byId('sq100ltpad10rbmargin10')).w);",
|
|
|
84 |
"t.is(10, dojo._getMarginExtents(dojo.byId('sq100ltpad10rbmargin10')).h);",
|
|
|
85 |
|
|
|
86 |
"t.is(10, dojo._getBorderExtents(dojo.byId('sq100border10margin10pad10')).l);",
|
|
|
87 |
"t.is(10, dojo._getBorderExtents(dojo.byId('sq100border10margin10pad10')).t);",
|
|
|
88 |
"t.is(20, dojo._getBorderExtents(dojo.byId('sq100border10margin10pad10')).w);",
|
|
|
89 |
"t.is(20, dojo._getBorderExtents(dojo.byId('sq100border10margin10pad10')).h);",
|
|
|
90 |
|
|
|
91 |
"t.is(20, dojo._getPadBorderExtents(dojo.byId('sq100border10margin10pad10')).l);",
|
|
|
92 |
"t.is(20, dojo._getPadBorderExtents(dojo.byId('sq100border10margin10pad10')).t);",
|
|
|
93 |
"t.is(40, dojo._getPadBorderExtents(dojo.byId('sq100border10margin10pad10')).w);",
|
|
|
94 |
"t.is(40, dojo._getPadBorderExtents(dojo.byId('sq100border10margin10pad10')).h);",
|
|
|
95 |
|
|
|
96 |
function coordsBasic(t){
|
|
|
97 |
var pos = dojo.coords("sq100", false);
|
|
|
98 |
// console.debug(pos);
|
|
|
99 |
t.is(100, pos.x);
|
|
|
100 |
t.is(100, pos.y);
|
|
|
101 |
t.is(100, pos.w);
|
|
|
102 |
t.is(100, pos.h);
|
|
|
103 |
},
|
|
|
104 |
function coordsMargin(t){
|
|
|
105 |
// coords is getting us the margin-box location, is
|
|
|
106 |
// this right?
|
|
|
107 |
var pos = dojo.coords("sq100margin10", false);
|
|
|
108 |
t.is(260, pos.x);
|
|
|
109 |
t.is(110, pos.y);
|
|
|
110 |
t.is(120, pos.w);
|
|
|
111 |
t.is(120, pos.h);
|
|
|
112 |
},
|
|
|
113 |
function sq100nopos(t){
|
|
|
114 |
var pos = dojo.coords("sq100nopos", false);
|
|
|
115 |
// console.debug(pos);
|
|
|
116 |
t.is(0, pos.x);
|
|
|
117 |
t.t(pos.y > 0);
|
|
|
118 |
// FIXME: the 'correct' w is not 100 on Safari WebKit (2.0.4 [419.3]), the right-margin extends to the document edge
|
|
|
119 |
// t.is(100, pos.w);
|
|
|
120 |
t.is(100, pos.h);
|
|
|
121 |
},
|
|
|
122 |
function coordsScrolled(t) {
|
|
|
123 |
var s = document.createElement('div');
|
|
|
124 |
var c = document.createElement('div');
|
|
|
125 |
document.body.appendChild(s);
|
|
|
126 |
s.appendChild(c);
|
|
|
127 |
var x=257, y= 285;
|
|
|
128 |
with (s.style) {
|
|
|
129 |
position = 'absolute';
|
|
|
130 |
overflow = 'scroll';
|
|
|
131 |
}
|
|
|
132 |
dojo._setMarginBox(s, x, y, 100, 100);
|
|
|
133 |
dojo._setMarginBox(c, 0, 0, 500, 500);
|
|
|
134 |
s.scrollTop = 200;
|
|
|
135 |
var pos = dojo.coords(s, true);
|
|
|
136 |
t.is(x, pos.x);
|
|
|
137 |
t.is(y, pos.y);
|
|
|
138 |
},
|
|
|
139 |
"t.is(1, dojo.style('sq100nopos', 'opacity'));",
|
|
|
140 |
"t.is(0.1, dojo.style('sq100nopos', 'opacity', 0.1));",
|
|
|
141 |
"t.is(0.8, dojo.style('sq100nopos', 'opacity', 0.8));",
|
|
|
142 |
"t.is('static', dojo.style('sq100nopos', 'position'));",
|
|
|
143 |
function getBgcolor(t){
|
|
|
144 |
var bgc = dojo.style('sq100nopos', 'backgroundColor');
|
|
|
145 |
t.t((bgc == "rgb(0, 0, 0)")||(bgc == "black")||(bgc == "#000000"));
|
|
|
146 |
},
|
|
|
147 |
function isDescendant(t){
|
|
|
148 |
t.t(dojo.isDescendant("sq100", dojo.body()));
|
|
|
149 |
t.t(dojo.isDescendant("sq100", dojo.doc));
|
|
|
150 |
t.t(dojo.isDescendant("sq100", "sq100"));
|
|
|
151 |
t.t(dojo.isDescendant(dojo.byId("sq100"), "sq100"));
|
|
|
152 |
t.f(dojo.isDescendant("sq100", dojo.byId("sq100").firstChild));
|
|
|
153 |
t.t(dojo.isDescendant(dojo.byId("sq100").firstChild, "sq100"));
|
|
|
154 |
},
|
|
|
155 |
function isDescendantIframe(t){
|
|
|
156 |
var bif = dojo.byId("blah");
|
|
|
157 |
getIframeDocument(bif).write("<html><body><div id='subDiv'></div></body></html>");
|
|
|
158 |
getIframeDocument(bif).close();
|
|
|
159 |
// this test barely makes sense. disabling it for now.
|
|
|
160 |
// t.t(dojo.isDescendant(bif.contentDocument.getElementById("subDiv"), bif.parentNode));
|
|
|
161 |
var subDiv = getIframeDocument(bif).getElementById("subDiv");
|
|
|
162 |
t.t(dojo.isDescendant(subDiv, subDiv));
|
|
|
163 |
t.t(dojo.isDescendant(subDiv, subDiv.parentNode));
|
|
|
164 |
t.f(dojo.isDescendant(subDiv.parentNode, subDiv));
|
|
|
165 |
|
|
|
166 |
},
|
|
|
167 |
function testClassFunctions(t){
|
|
|
168 |
var node = dojo.byId("sq100");
|
|
|
169 |
dojo.addClass(node, "a");
|
|
|
170 |
t.is("a", node.className);
|
|
|
171 |
dojo.removeClass(node, "c");
|
|
|
172 |
t.is("a", node.className);
|
|
|
173 |
t.assertTrue(dojo.hasClass(node, "a"));
|
|
|
174 |
t.assertFalse(dojo.hasClass(node, "b"));
|
|
|
175 |
dojo.addClass(node, "b");
|
|
|
176 |
t.is("a b", node.className);
|
|
|
177 |
t.assertTrue(dojo.hasClass(node, "a"));
|
|
|
178 |
t.assertTrue(dojo.hasClass(node, "b"));
|
|
|
179 |
dojo.removeClass(node, "a");
|
|
|
180 |
t.is("b", node.className);
|
|
|
181 |
t.assertFalse(dojo.hasClass(node, "a"));
|
|
|
182 |
t.assertTrue(dojo.hasClass(node, "b"));
|
|
|
183 |
dojo.toggleClass(node, "a");
|
|
|
184 |
t.is("b a", node.className);
|
|
|
185 |
t.assertTrue(dojo.hasClass(node, "a"));
|
|
|
186 |
t.assertTrue(dojo.hasClass(node, "b"));
|
|
|
187 |
dojo.toggleClass(node, "a");
|
|
|
188 |
t.is("b", node.className);
|
|
|
189 |
t.assertFalse(dojo.hasClass(node, "a"));
|
|
|
190 |
t.assertTrue(dojo.hasClass(node, "b"));
|
|
|
191 |
dojo.toggleClass(node, "b");
|
|
|
192 |
t.is("", node.className);
|
|
|
193 |
t.assertFalse(dojo.hasClass(node, "a"));
|
|
|
194 |
t.assertFalse(dojo.hasClass(node, "b"));
|
|
|
195 |
dojo.removeClass(node, "c");
|
|
|
196 |
t.assertTrue(!node.className);
|
|
|
197 |
}
|
|
|
198 |
]
|
|
|
199 |
);
|
|
|
200 |
doh.run();
|
|
|
201 |
});
|
|
|
202 |
</script>
|
|
|
203 |
<style type="text/css">
|
|
|
204 |
html, body {
|
|
|
205 |
padding: 0px;
|
|
|
206 |
margin: 0px;
|
|
|
207 |
border: 0px;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
#sq100 {
|
|
|
211 |
background-color: black;
|
|
|
212 |
color: white;
|
|
|
213 |
position: absolute;
|
|
|
214 |
left: 100px;
|
|
|
215 |
top: 100px;
|
|
|
216 |
width: 100px;
|
|
|
217 |
height: 100px;
|
|
|
218 |
border: 0px;
|
|
|
219 |
padding: 0px;
|
|
|
220 |
margin: 0px;
|
|
|
221 |
overflow: hidden;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
#sq100margin10 {
|
|
|
225 |
background-color: black;
|
|
|
226 |
color: white;
|
|
|
227 |
position: absolute;
|
|
|
228 |
left: 250px;
|
|
|
229 |
top: 100px;
|
|
|
230 |
width: 100px;
|
|
|
231 |
height: 100px;
|
|
|
232 |
border: 0px;
|
|
|
233 |
padding: 0px;
|
|
|
234 |
margin: 10px;
|
|
|
235 |
overflow: hidden;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
#sq100margin10pad10 {
|
|
|
239 |
background-color: black;
|
|
|
240 |
color: white;
|
|
|
241 |
position: absolute;
|
|
|
242 |
left: 400px;
|
|
|
243 |
top: 100px;
|
|
|
244 |
width: 100px;
|
|
|
245 |
height: 100px;
|
|
|
246 |
border: 0px;
|
|
|
247 |
padding: 10px;
|
|
|
248 |
margin: 10px;
|
|
|
249 |
overflow: hidden;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
#sq100pad10 {
|
|
|
253 |
background-color: black;
|
|
|
254 |
color: white;
|
|
|
255 |
position: absolute;
|
|
|
256 |
left: 100px;
|
|
|
257 |
top: 250px;
|
|
|
258 |
width: 100px;
|
|
|
259 |
height: 100px;
|
|
|
260 |
border: 0px;
|
|
|
261 |
padding: 10px;
|
|
|
262 |
margin: 0px;
|
|
|
263 |
overflow: hidden;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
#sq100ltpad10 {
|
|
|
267 |
background-color: black;
|
|
|
268 |
color: white;
|
|
|
269 |
position: absolute;
|
|
|
270 |
left: 250px;
|
|
|
271 |
top: 250px;
|
|
|
272 |
width: 100px;
|
|
|
273 |
height: 100px;
|
|
|
274 |
border: 0px;
|
|
|
275 |
padding-left: 10px;
|
|
|
276 |
padding-top: 10px;
|
|
|
277 |
padding-right: 0px;
|
|
|
278 |
padding-bottom: 0px;
|
|
|
279 |
margin: 0px;
|
|
|
280 |
overflow: hidden;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
#sq100ltpad10rbmargin10 {
|
|
|
284 |
background-color: black;
|
|
|
285 |
color: white;
|
|
|
286 |
position: absolute;
|
|
|
287 |
left: 400px;
|
|
|
288 |
top: 250px;
|
|
|
289 |
width: 100px;
|
|
|
290 |
height: 100px;
|
|
|
291 |
border: 0px;
|
|
|
292 |
padding-left: 10px;
|
|
|
293 |
padding-top: 10px;
|
|
|
294 |
padding-right: 0px;
|
|
|
295 |
padding-bottom: 0px;
|
|
|
296 |
margin-left: 0px;
|
|
|
297 |
margin-top: 0px;
|
|
|
298 |
margin-right: 10px;
|
|
|
299 |
margin-bottom: 10px;
|
|
|
300 |
overflow: hidden;
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
#sq100border10 {
|
|
|
304 |
background-color: black;
|
|
|
305 |
color: white;
|
|
|
306 |
position: absolute;
|
|
|
307 |
left: 100px;
|
|
|
308 |
top: 400px;
|
|
|
309 |
width: 100px;
|
|
|
310 |
height: 100px;
|
|
|
311 |
border: 10px solid yellow;
|
|
|
312 |
padding: 0px;
|
|
|
313 |
margin: 0px;
|
|
|
314 |
overflow: hidden;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
#sq100border10margin10 {
|
|
|
318 |
background-color: black;
|
|
|
319 |
color: white;
|
|
|
320 |
position: absolute;
|
|
|
321 |
left: 250px;
|
|
|
322 |
top: 400px;
|
|
|
323 |
width: 100px;
|
|
|
324 |
height: 100px;
|
|
|
325 |
border: 10px solid yellow;
|
|
|
326 |
padding: 0px;
|
|
|
327 |
margin: 10px;
|
|
|
328 |
overflow: hidden;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
#sq100border10margin10pad10 {
|
|
|
332 |
background-color: black;
|
|
|
333 |
color: white;
|
|
|
334 |
position: absolute;
|
|
|
335 |
left: 400px;
|
|
|
336 |
top: 400px;
|
|
|
337 |
width: 100px;
|
|
|
338 |
height: 100px;
|
|
|
339 |
border: 10px solid yellow;
|
|
|
340 |
padding: 10px;
|
|
|
341 |
margin: 10px;
|
|
|
342 |
overflow: hidden;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
#sq100nopos {
|
|
|
346 |
background-color: black;
|
|
|
347 |
color: white;
|
|
|
348 |
width: 100px;
|
|
|
349 |
height: 100px;
|
|
|
350 |
padding: 0px;
|
|
|
351 |
margin: 0px;
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
</style>
|
|
|
355 |
</head>
|
|
|
356 |
<body>
|
|
|
357 |
<h1>testing Core HTML/DOM/CSS/Style utils</h1>
|
|
|
358 |
<div id="sq100">
|
|
|
359 |
100px square, abs
|
|
|
360 |
</div>
|
|
|
361 |
<div id="sq100margin10">
|
|
|
362 |
100px square, abs, 10px margin
|
|
|
363 |
</div>
|
|
|
364 |
<div id="sq100margin10pad10">
|
|
|
365 |
100px square, abs, 10px margin, 10px padding
|
|
|
366 |
</div>
|
|
|
367 |
<div id="sq100pad10">
|
|
|
368 |
100px square, abs, 10px padding
|
|
|
369 |
</div>
|
|
|
370 |
<div id="sq100ltpad10">
|
|
|
371 |
100px square, abs, 10px left and top padding
|
|
|
372 |
</div>
|
|
|
373 |
<div id="sq100ltpad10rbmargin10">
|
|
|
374 |
100px square, abs, 10px left and top padding, 10px bottom and right margin
|
|
|
375 |
</div>
|
|
|
376 |
<div id="sq100border10">
|
|
|
377 |
100px square, abs, 10px yellow border
|
|
|
378 |
</div>
|
|
|
379 |
<div id="sq100border10margin10">
|
|
|
380 |
100px square, abs, 10px yellow border, 10px margin
|
|
|
381 |
</div>
|
|
|
382 |
<div id="sq100border10margin10pad10">
|
|
|
383 |
100px square, abs, 10px yellow border, 10px margin, 10px padding
|
|
|
384 |
</div>
|
|
|
385 |
<div id="sq100nopos">
|
|
|
386 |
100px square, no positioning
|
|
|
387 |
</div>
|
|
|
388 |
<iframe id="blah"></iframe>
|
|
|
389 |
</body>
|
|
|
390 |
</html>
|
|
|
391 |
|