|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|
4 <head> |
|
5 <title>script.aculo.us Unit test file</title> |
|
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|
7 <script src="../../lib/prototype.js" type="text/javascript"></script> |
|
8 <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
|
9 <script src="../../src/unittest.js" type="text/javascript"></script> |
|
10 <link rel="stylesheet" href="../test.css" type="text/css" /> |
|
11 </head> |
|
12 <body> |
|
13 <h1>script.aculo.us Unit test file</h1> |
|
14 <p> |
|
15 Tests for Postion.clone (to be moved to Prototype) |
|
16 </p> |
|
17 |
|
18 <!-- Log output --> |
|
19 <div id="testlog"> </div> |
|
20 |
|
21 <!-- Tests follow --> |
|
22 <script type="text/javascript" language="javascript" charset="utf-8"> |
|
23 // <![CDATA[ |
|
24 |
|
25 function prepareTarget(contained, position1, position2) { |
|
26 var target; |
|
27 if($('target_div')) Element.remove('target_div'); |
|
28 if($('container_div')) Element.remove('container_div'); |
|
29 if(contained) { |
|
30 target = Builder.node('div', |
|
31 {id: 'container_div', style: 'position:' + position1}, |
|
32 [Builder.node('div', {id: 'target_div', style: 'position: ' +position2})]); |
|
33 } else { |
|
34 target = Builder.node('div', |
|
35 {id: 'target_div', style: 'position:' + position1}, '456'); |
|
36 } |
|
37 document.body.appendChild(target); |
|
38 Position.clone($('source_div'),$('target_div')); |
|
39 } |
|
40 |
|
41 function prepareTargetHidden(contained, position1, position2) { |
|
42 var target; |
|
43 if($('target_div')) Element.remove('target_div'); |
|
44 if($('container_div')) Element.remove('container_div'); |
|
45 if(contained) { |
|
46 target = Builder.node('div', |
|
47 {id: 'container_div', style: 'position:' + position1}, |
|
48 [Builder.node('div', {id: 'target_div', style: 'display:none; position: ' +position2})]); |
|
49 } else { |
|
50 target = Builder.node('div', |
|
51 {id: 'target_div', style: 'display:none; position:' + position1}, '456'); |
|
52 } |
|
53 document.body.appendChild(target); |
|
54 Position.clone($('source_div'),$('target_div')); |
|
55 Element.show($('target_div')); |
|
56 } |
|
57 |
|
58 new Test.Unit.Runner({ |
|
59 |
|
60 teardown: function() { |
|
61 Element.remove($('source_div')); |
|
62 }, |
|
63 |
|
64 testPositionCloneFromAbsolute: function() { with(this) { |
|
65 var source = Builder.node('div', |
|
66 {id: 'source_div', style: 'position:absolute; top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
67 document.body.appendChild(source); |
|
68 var expected = Object.inspect([120, 20]); |
|
69 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
70 |
|
71 prepareTarget(false, 'absolute'); |
|
72 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
73 "Clone to absolute BODY child"); |
|
74 |
|
75 prepareTarget(false, 'fixed'); |
|
76 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
77 "Clone to fixed BODY child"); |
|
78 |
|
79 prepareTarget(true, 'absolute', 'absolute'); |
|
80 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
81 "Clone to absolute child of absolute BODY child"); |
|
82 |
|
83 prepareTarget(true, 'absolute', 'fixed'); |
|
84 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
85 "Clone to fixed child of absolute BODY child"); |
|
86 |
|
87 prepareTarget(true, 'relative', 'absolute'); |
|
88 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
89 "Clone to absolute child of relative BODY child"); |
|
90 |
|
91 prepareTarget(true, 'relative', 'fixed'); |
|
92 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
93 "Clone to fixed child of relative BODY child"); |
|
94 |
|
95 prepareTarget(true, 'static', 'absolute'); |
|
96 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
97 "Clone to absolute child of static BODY child"); |
|
98 |
|
99 prepareTarget(true, 'static', 'fixed'); |
|
100 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
101 "Clone to fixed child of static BODY child"); |
|
102 }}, |
|
103 |
|
104 testPositionCloneFromRelative: function() { with(this) { |
|
105 var source = Builder.node('div', |
|
106 {id: 'source_div', style: 'position:relative; top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
107 document.body.appendChild(source); |
|
108 var expected = Object.inspect(Position.page($('source_div'))); |
|
109 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
110 |
|
111 prepareTarget(false, 'absolute'); |
|
112 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
113 "Clone to absolute BODY child"); |
|
114 |
|
115 prepareTarget(false, 'fixed'); |
|
116 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
117 "Clone to fixed BODY child"); |
|
118 |
|
119 prepareTarget(true, 'absolute', 'absolute'); |
|
120 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
121 "Clone to absolute child of absolute BODY child"); |
|
122 |
|
123 prepareTarget(true, 'absolute', 'fixed'); |
|
124 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
125 "Clone to fixed child of absolute BODY child"); |
|
126 |
|
127 prepareTarget(true, 'relative', 'absolute'); |
|
128 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
129 "Clone to absolute child of relative BODY child"); |
|
130 |
|
131 prepareTarget(true, 'relative', 'fixed'); |
|
132 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
133 "Clone to fixed child of relative BODY child"); |
|
134 |
|
135 prepareTarget(true, 'static', 'absolute'); |
|
136 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
137 "Clone to absolute child of static BODY child"); |
|
138 |
|
139 prepareTarget(true, 'static', 'fixed'); |
|
140 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
141 "Clone to fixed child of static BODY child"); |
|
142 }}, |
|
143 |
|
144 testPositionCloneFromStatic: function() { with(this) { |
|
145 var source = Builder.node('div', |
|
146 {id: 'source_div', style: 'top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
147 document.body.appendChild(source); |
|
148 var expected = Object.inspect(Position.page($('source_div'))); |
|
149 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
150 |
|
151 prepareTarget(false, 'absolute'); |
|
152 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
153 "Clone to absolute BODY child"); |
|
154 |
|
155 prepareTarget(false, 'fixed'); |
|
156 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
157 "Clone to fixed BODY child"); |
|
158 |
|
159 prepareTarget(true, 'absolute', 'absolute'); |
|
160 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
161 "Clone to absolute child of absolute BODY child"); |
|
162 |
|
163 prepareTarget(true, 'absolute', 'fixed'); |
|
164 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
165 "Clone to fixed child of absolute BODY child"); |
|
166 |
|
167 prepareTarget(true, 'relative', 'absolute'); |
|
168 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
169 "Clone to absolute child of relative BODY child"); |
|
170 |
|
171 prepareTarget(true, 'relative', 'fixed'); |
|
172 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
173 "Clone to fixed child of relative BODY child"); |
|
174 |
|
175 prepareTarget(true, 'static', 'absolute'); |
|
176 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
177 "Clone to absolute child of static BODY child"); |
|
178 |
|
179 prepareTarget(true, 'static', 'fixed'); |
|
180 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
181 "Clone to fixed child of static BODY child"); |
|
182 }}, |
|
183 |
|
184 testPositionCloneFromAbsoluteWithHiddenTarget: function() { with(this) { |
|
185 var source = Builder.node('div', |
|
186 {id: 'source_div', style: 'position:absolute; top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
187 document.body.appendChild(source); |
|
188 var expected = Object.inspect([120, 20]); |
|
189 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
190 |
|
191 prepareTargetHidden(false, 'absolute'); |
|
192 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
193 "Clone to absolute BODY child"); |
|
194 |
|
195 prepareTargetHidden(false, 'fixed'); |
|
196 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
197 "Clone to fixed BODY child"); |
|
198 |
|
199 prepareTargetHidden(true, 'absolute', 'absolute'); |
|
200 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
201 "Clone to absolute child of absolute BODY child"); |
|
202 |
|
203 prepareTargetHidden(true, 'absolute', 'fixed'); |
|
204 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
205 "Clone to fixed child of absolute BODY child"); |
|
206 |
|
207 prepareTargetHidden(true, 'relative', 'absolute'); |
|
208 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
209 "Clone to absolute child of relative BODY child"); |
|
210 |
|
211 prepareTargetHidden(true, 'relative', 'fixed'); |
|
212 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
213 "Clone to fixed child of relative BODY child"); |
|
214 |
|
215 prepareTargetHidden(true, 'static', 'absolute'); |
|
216 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
217 "Clone to absolute child of static BODY child"); |
|
218 |
|
219 prepareTargetHidden(true, 'static', 'fixed'); |
|
220 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
221 "Clone to fixed child of static BODY child"); |
|
222 }}, |
|
223 |
|
224 testPositionCloneFromRelativeWithHiddenTarget: function() { with(this) { |
|
225 var source = Builder.node('div', |
|
226 {id: 'source_div', style: 'position:relative; top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
227 document.body.appendChild(source); |
|
228 var expected = Object.inspect(Position.page($('source_div'))); |
|
229 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
230 |
|
231 prepareTargetHidden(false, 'absolute'); |
|
232 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
233 "Clone to absolute BODY child"); |
|
234 |
|
235 prepareTargetHidden(false, 'fixed'); |
|
236 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
237 "Clone to fixed BODY child"); |
|
238 |
|
239 prepareTargetHidden(true, 'absolute', 'absolute'); |
|
240 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
241 "Clone to absolute child of absolute BODY child"); |
|
242 |
|
243 prepareTargetHidden(true, 'absolute', 'fixed'); |
|
244 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
245 "Clone to fixed child of absolute BODY child"); |
|
246 |
|
247 prepareTargetHidden(true, 'relative', 'absolute'); |
|
248 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
249 "Clone to absolute child of relative BODY child"); |
|
250 |
|
251 prepareTargetHidden(true, 'relative', 'fixed'); |
|
252 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
253 "Clone to fixed child of relative BODY child"); |
|
254 |
|
255 prepareTargetHidden(true, 'static', 'absolute'); |
|
256 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
257 "Clone to absolute child of static BODY child"); |
|
258 |
|
259 prepareTargetHidden(true, 'static', 'fixed'); |
|
260 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
261 "Clone to fixed child of static BODY child"); |
|
262 }}, |
|
263 |
|
264 testPositionCloneFromStaticWithHiddenTarget: function() { with(this) { |
|
265 var source = Builder.node('div', |
|
266 {id: 'source_div', style: 'top:20px; left:120px; width:100px; height:50px;'}, '123'); |
|
267 document.body.appendChild(source); |
|
268 var expected = Object.inspect(Position.page($('source_div'))); |
|
269 assertEqual(expected, Object.inspect(Position.page($('source_div')))); |
|
270 |
|
271 prepareTargetHidden(false, 'absolute'); |
|
272 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
273 "Clone to absolute BODY child"); |
|
274 |
|
275 prepareTargetHidden(false, 'fixed'); |
|
276 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
277 "Clone to fixed BODY child"); |
|
278 |
|
279 prepareTargetHidden(true, 'absolute', 'absolute'); |
|
280 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
281 "Clone to absolute child of absolute BODY child"); |
|
282 |
|
283 prepareTargetHidden(true, 'absolute', 'fixed'); |
|
284 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
285 "Clone to fixed child of absolute BODY child"); |
|
286 |
|
287 prepareTargetHidden(true, 'relative', 'absolute'); |
|
288 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
289 "Clone to absolute child of relative BODY child"); |
|
290 |
|
291 prepareTargetHidden(true, 'relative', 'fixed'); |
|
292 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
293 "Clone to fixed child of relative BODY child"); |
|
294 |
|
295 prepareTargetHidden(true, 'static', 'absolute'); |
|
296 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
297 "Clone to absolute child of static BODY child"); |
|
298 |
|
299 prepareTargetHidden(true, 'static', 'fixed'); |
|
300 assertEqual(expected, Object.inspect(Position.page($('target_div'))), |
|
301 "Clone to fixed child of static BODY child"); |
|
302 }} |
|
303 |
|
304 }); |
|
305 |
|
306 // ]]> |
|
307 </script> |
|
308 |
|
309 <!-- Test elements will be inserted after this --> |
|
310 |
|
311 </body> |
|
312 </html> |