OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../http/tests/inspector/inspector-test.js"></script> | |
4 <script> | |
5 | |
6 function test() | |
7 { | |
8 function TestView(viewName) | |
9 { | |
10 WebInspector.View.call(this); | |
11 | |
12 this._viewName = viewName; | |
13 this._processWillShowCount = 0; | |
14 this._processWasHiddenCount = 0; | |
15 InspectorTest.addResult(this._viewName + "()"); | |
16 } | |
17 | |
18 TestView.prototype = { | |
19 _processWillShow: function() | |
20 { | |
21 InspectorTest.assertEquals(this._processWillShowCount, this._process
WasHiddenCount); | |
22 WebInspector.View.prototype._processWillShow.call(this); | |
23 ++this._processWillShowCount; | |
24 }, | |
25 | |
26 _processWasHidden: function() | |
27 { | |
28 WebInspector.View.prototype._processWasHidden.call(this); | |
29 ++this._processWasHiddenCount; | |
30 InspectorTest.assertEquals(this._processWillShowCount, this._process
WasHiddenCount); | |
31 }, | |
32 | |
33 show: function(parentElement) | |
34 { | |
35 InspectorTest.addResult(this._viewName + ".show()"); | |
36 WebInspector.View.prototype.show.call(this, parentElement); | |
37 }, | |
38 | |
39 detach: function() | |
40 { | |
41 InspectorTest.addResult(this._viewName + ".detach()"); | |
42 WebInspector.View.prototype.detach.call(this); | |
43 }, | |
44 | |
45 doResize: function() | |
46 { | |
47 InspectorTest.addResult(this._viewName + ".doResize()"); | |
48 WebInspector.View.prototype.doResize.call(this); | |
49 }, | |
50 | |
51 wasShown: function() | |
52 { | |
53 InspectorTest.addResult(" " + this._viewName + ".wasShown()"); | |
54 if (this.showOnWasShown) | |
55 this.showOnWasShown.show(this.showRoot || this.element); | |
56 if (this.detachOnWasShown) | |
57 this.detachOnWasShown.detach(); | |
58 if (this.resizeOnWasShown) | |
59 this.resizeOnWasShown.doResize(); | |
60 }, | |
61 | |
62 willHide: function() | |
63 { | |
64 InspectorTest.addResult(" " + this._viewName + ".willHide()"); | |
65 if (this.showOnWillHide) | |
66 this.showOnWillHide.show(this.element); | |
67 if (this.detachOnWillHide) | |
68 this.detachOnWillHide.detach(); | |
69 }, | |
70 | |
71 onResize: function() | |
72 { | |
73 InspectorTest.addResult(" " + this._viewName + ".onResize()"); | |
74 } | |
75 }; | |
76 | |
77 TestView.prototype.__proto__ = WebInspector.View.prototype; | |
78 | |
79 InspectorTest.runTestSuite([ | |
80 function testShowView(next) | |
81 { | |
82 var view = new TestView("View"); | |
83 view.show(WebInspector.inspectorView.element); | |
84 view.detach(); | |
85 next(); | |
86 }, | |
87 | |
88 function testAppendViaDOM(next) | |
89 { | |
90 try { | |
91 var view = new TestView("View"); | |
92 document.body.appendChild(view.element); | |
93 } catch (e) { | |
94 InspectorTest.addResult(e); | |
95 } | |
96 next(); | |
97 }, | |
98 | |
99 function testInsertViaDOM(next) | |
100 { | |
101 try { | |
102 var view = new TestView("View"); | |
103 document.body.insertBefore(view.element, null); | |
104 } catch (e) { | |
105 InspectorTest.addResult(e); | |
106 } | |
107 next(); | |
108 }, | |
109 | |
110 function testAttachToOrphanNode(next) | |
111 { | |
112 try { | |
113 var view = new TestView("View"); | |
114 var div = document.createElement("div"); | |
115 view.show(div); | |
116 } catch (e) { | |
117 InspectorTest.addResult(e); | |
118 } | |
119 next(); | |
120 }, | |
121 | |
122 function testImmediateParent(next) | |
123 { | |
124 var parentView = new TestView("Parent"); | |
125 var childView = new TestView("Child"); | |
126 childView.show(parentView.element); | |
127 if (childView._parentView === parentView) | |
128 InspectorTest.addResult("OK"); | |
129 else | |
130 InspectorTest.addResult("FAILED"); | |
131 next(); | |
132 }, | |
133 | |
134 function testDistantParent(next) | |
135 { | |
136 var parentView = new TestView("Parent"); | |
137 var div = document.createElement("div"); | |
138 parentView.element.appendChild(div); | |
139 var childView = new TestView("Child"); | |
140 childView.show(div); | |
141 | |
142 if (childView._parentView === parentView) | |
143 InspectorTest.addResult("OK"); | |
144 else | |
145 InspectorTest.addResult("FAILED"); | |
146 next(); | |
147 }, | |
148 | |
149 function testEvents(next) | |
150 { | |
151 var parentView = new TestView("Parent"); | |
152 parentView.markAsRoot(); | |
153 var childView = new TestView("Child"); | |
154 parentView.show(WebInspector.inspectorView.element); | |
155 | |
156 parentView.doResize(); | |
157 childView.show(parentView.element); | |
158 parentView.doResize(); | |
159 parentView.detach(); | |
160 parentView.show(WebInspector.inspectorView.element); | |
161 childView.detach(); | |
162 parentView.detach(); | |
163 next(); | |
164 }, | |
165 | |
166 function testEventsHideOnDetach(next) | |
167 { | |
168 var parentView = new TestView("Parent"); | |
169 var childView = new TestView("Child"); | |
170 childView.setHideOnDetach(); | |
171 parentView.show(WebInspector.inspectorView.element); | |
172 | |
173 parentView.doResize(); | |
174 childView.show(parentView.element); | |
175 parentView.doResize(); | |
176 parentView.detach(); | |
177 parentView.show(WebInspector.inspectorView.element); | |
178 childView.detach(); | |
179 parentView.detach(); | |
180 next(); | |
181 }, | |
182 | |
183 function testViewCounter(next) | |
184 { | |
185 var parentView = new TestView("Parent"); | |
186 parentView.show(WebInspector.inspectorView.element); | |
187 | |
188 var childView = new TestView("Child"); | |
189 childView.show(parentView.element); | |
190 InspectorTest.addResult(" view counter: " + parentView.element.__vi
ewCounter); | |
191 | |
192 var childView2 = new TestView("Child 2"); | |
193 childView2.show(parentView.element); | |
194 InspectorTest.addResult(" view counter: " + parentView.element.__vi
ewCounter); | |
195 | |
196 childView.detach(); | |
197 InspectorTest.addResult(" view counter: " + parentView.element.__vi
ewCounter); | |
198 | |
199 childView2.detach(); | |
200 InspectorTest.addResult(" view counter: " + parentView.element.__vi
ewCounter); | |
201 | |
202 next(); | |
203 }, | |
204 | |
205 function testRemoveChild(next) | |
206 { | |
207 var parentView = new TestView("Parent"); | |
208 parentView.show(WebInspector.inspectorView.element); | |
209 | |
210 var childView = new TestView("Child"); | |
211 childView.show(parentView.element); | |
212 try { | |
213 parentView.element.removeChild(childView.element); | |
214 } catch (e) { | |
215 InspectorTest.addResult(e); | |
216 } | |
217 next(); | |
218 }, | |
219 | |
220 function testImplicitRemoveChild(next) | |
221 { | |
222 var parentView = new TestView("Parent"); | |
223 var div = document.createElement("div"); | |
224 parentView.element.appendChild(div); | |
225 | |
226 var childView = new TestView("Child"); | |
227 childView.show(div); | |
228 | |
229 try { | |
230 parentView.element.removeChild(div); | |
231 } catch (e) { | |
232 InspectorTest.addResult(e); | |
233 } | |
234 next(); | |
235 }, | |
236 | |
237 function testRemoveChildren(next) | |
238 { | |
239 var parentView = new TestView("Parent"); | |
240 var childView = new TestView("Child"); | |
241 childView.show(parentView.element); | |
242 parentView.element.appendChild(document.createElement("div")); | |
243 try { | |
244 parentView.element.removeChildren(); | |
245 } catch (e) { | |
246 InspectorTest.addResult(e); | |
247 } | |
248 next(); | |
249 }, | |
250 | |
251 function testImplicitRemoveChildren(next) | |
252 { | |
253 var parentView = new TestView("Parent"); | |
254 var div = document.createElement("div"); | |
255 parentView.element.appendChild(div); | |
256 | |
257 var childView = new TestView("Child"); | |
258 childView.show(div); | |
259 | |
260 try { | |
261 parentView.element.removeChildren(); | |
262 } catch (e) { | |
263 InspectorTest.addResult(e); | |
264 } | |
265 next(); | |
266 }, | |
267 | |
268 function testShowOnWasShown(next) | |
269 { | |
270 var parentView = new TestView("Parent"); | |
271 parentView.showOnWasShown = new TestView("Child"); | |
272 parentView.show(WebInspector.inspectorView.element); | |
273 parentView.detach(); | |
274 next(); | |
275 }, | |
276 | |
277 function testShowNestedOnWasShown(next) | |
278 { | |
279 var topView = new TestView("Top"); | |
280 var middleView = new TestView("Middle"); | |
281 var bottomView = new TestView("Bottom"); | |
282 middleView.show(topView.element); | |
283 topView.showOnWasShown = bottomView; | |
284 topView.showRoot = middleView.element; | |
285 topView.show(WebInspector.inspectorView.element); | |
286 topView.detach(); | |
287 next(); | |
288 }, | |
289 | |
290 function testDetachOnWasShown(next) | |
291 { | |
292 var parentView = new TestView("Parent"); | |
293 var childView = new TestView("Child"); | |
294 childView.show(parentView.element); | |
295 parentView.detachOnWasShown = childView; | |
296 parentView.show(WebInspector.inspectorView.element); | |
297 parentView.detach(); | |
298 next(); | |
299 }, | |
300 | |
301 function testShowOnWillHide(next) | |
302 { | |
303 var parentView = new TestView("Parent"); | |
304 var childView = new TestView("Child"); | |
305 parentView.show(WebInspector.inspectorView.element); | |
306 childView.show(parentView.element); | |
307 parentView.showOnWillHide = childView; | |
308 parentView.detach(); | |
309 next(); | |
310 }, | |
311 | |
312 function testDetachOnWillHide(next) | |
313 { | |
314 var parentView = new TestView("Parent"); | |
315 var childView = new TestView("Child"); | |
316 parentView.show(WebInspector.inspectorView.element); | |
317 childView.show(parentView.element); | |
318 parentView.detachOnWillHide = childView; | |
319 parentView.detach(); | |
320 next(); | |
321 }, | |
322 | |
323 function testShowDetachesFromPrevious(next) | |
324 { | |
325 var parentView1 = new TestView("Parent1"); | |
326 var parentView2 = new TestView("Parent2"); | |
327 var childView = new TestView("Child"); | |
328 parentView1.show(WebInspector.inspectorView.element); | |
329 parentView2.show(WebInspector.inspectorView.element); | |
330 childView.show(parentView1.element); | |
331 childView.show(parentView2.element); | |
332 next(); | |
333 }, | |
334 | |
335 function testResizeOnWasShown(next) | |
336 { | |
337 var parentView = new TestView("Parent"); | |
338 var childView = new TestView("Child"); | |
339 childView.show(parentView.element); | |
340 parentView.resizeOnWasShown = childView; | |
341 parentView.show(WebInspector.inspectorView.element); | |
342 parentView.detach(); | |
343 next(); | |
344 } | |
345 ]); | |
346 } | |
347 | |
348 </script> | |
349 </head> | |
350 | |
351 <body onload="runTest()"> | |
352 <p> | |
353 This tests that events are properly propagated through View hierarchy. | |
354 </p> | |
355 | |
356 </body> | |
357 </html> | |
OLD | NEW |