3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
8 function TestWidget(widgetName
)
10 WebInspector
.Widget
.call(this);
12 this._widgetName
= widgetName
;
13 this._processWillShowCount
= 0;
14 this._processWasHiddenCount
= 0;
15 InspectorTest
.addResult(this._widgetName
+ "()");
18 TestWidget
.prototype = {
19 _processWillShow: function()
21 InspectorTest
.assertEquals(this._processWillShowCount
, this._processWasHiddenCount
);
22 WebInspector
.Widget
.prototype._processWillShow
.call(this);
23 ++this._processWillShowCount
;
26 _processWasHidden: function()
28 WebInspector
.Widget
.prototype._processWasHidden
.call(this);
29 ++this._processWasHiddenCount
;
30 InspectorTest
.assertEquals(this._processWillShowCount
, this._processWasHiddenCount
);
33 show: function(parentElement
)
35 InspectorTest
.addResult(this._widgetName
+ ".show()");
36 WebInspector
.Widget
.prototype.show
.call(this, parentElement
);
41 InspectorTest
.addResult(this._widgetName
+ ".detach()");
42 WebInspector
.Widget
.prototype.detach
.call(this);
47 InspectorTest
.addResult(this._widgetName
+ ".doResize()");
48 WebInspector
.Widget
.prototype.doResize
.call(this);
53 InspectorTest
.addResult(" " + this._widgetName
+ ".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();
64 InspectorTest
.addResult(" " + this._widgetName
+ ".willHide()");
65 if (this.showOnWillHide
)
66 this.showOnWillHide
.show(this.element
);
67 if (this.detachOnWillHide
)
68 this.detachOnWillHide
.detach();
73 InspectorTest
.addResult(" " + this._widgetName
+ ".onResize()");
77 TestWidget
.prototype.__proto__
= WebInspector
.Widget
.prototype;
79 InspectorTest
.runTestSuite([
80 function testShowWidget(next
)
82 var widget
= new TestWidget("Widget");
83 widget
.show(WebInspector
.inspectorView
.element
);
88 function testAppendViaDOM(next
)
91 var widget
= new TestWidget("Widget");
92 document
.body
.appendChild(widget
.element
);
94 InspectorTest
.addResult(e
);
99 function testInsertViaDOM(next
)
102 var widget
= new TestWidget("Widget");
103 document
.body
.insertBefore(widget
.element
, null);
105 InspectorTest
.addResult(e
);
110 function testAttachToOrphanNode(next
)
113 var widget
= new TestWidget("Widget");
114 var div
= document
.createElement("div");
117 InspectorTest
.addResult(e
);
122 function testImmediateParent(next
)
124 var parentWidget
= new TestWidget("Parent");
125 var childWidget
= new TestWidget("Child");
126 childWidget
.show(parentWidget
.element
);
127 if (childWidget
._parentWidget
=== parentWidget
)
128 InspectorTest
.addResult("OK");
130 InspectorTest
.addResult("FAILED");
134 function testDistantParent(next
)
136 var parentWidget
= new TestWidget("Parent");
137 var div
= document
.createElement("div");
138 parentWidget
.element
.appendChild(div
);
139 var childWidget
= new TestWidget("Child");
140 childWidget
.show(div
);
142 if (childWidget
._parentWidget
=== parentWidget
)
143 InspectorTest
.addResult("OK");
145 InspectorTest
.addResult("FAILED");
149 function testEvents(next
)
151 var parentWidget
= new TestWidget("Parent");
152 parentWidget
.markAsRoot();
153 var childWidget
= new TestWidget("Child");
154 parentWidget
.show(WebInspector
.inspectorView
.element
);
156 parentWidget
.doResize();
157 childWidget
.show(parentWidget
.element
);
158 parentWidget
.doResize();
159 parentWidget
.detach();
160 parentWidget
.show(WebInspector
.inspectorView
.element
);
161 childWidget
.detach();
162 parentWidget
.detach();
166 function testEventsHideOnDetach(next
)
168 var parentWidget
= new TestWidget("Parent");
169 var childWidget
= new TestWidget("Child");
170 childWidget
.setHideOnDetach();
171 parentWidget
.show(WebInspector
.inspectorView
.element
);
173 parentWidget
.doResize();
174 childWidget
.show(parentWidget
.element
);
175 parentWidget
.doResize();
176 parentWidget
.detach();
177 parentWidget
.show(WebInspector
.inspectorView
.element
);
178 childWidget
.detach();
179 parentWidget
.detach();
183 function testWidgetCounter(next
)
185 var parentWidget
= new TestWidget("Parent");
186 parentWidget
.show(WebInspector
.inspectorView
.element
);
188 var childWidget
= new TestWidget("Child");
189 childWidget
.show(parentWidget
.element
);
190 InspectorTest
.addResult(" widget counter: " + parentWidget
.element
.__widgetCounter
);
192 var childWidget2
= new TestWidget("Child 2");
193 childWidget2
.show(parentWidget
.element
);
194 InspectorTest
.addResult(" widget counter: " + parentWidget
.element
.__widgetCounter
);
196 childWidget
.detach();
197 InspectorTest
.addResult(" widget counter: " + parentWidget
.element
.__widgetCounter
);
199 childWidget2
.detach();
200 InspectorTest
.addResult(" widget counter: " + parentWidget
.element
.__widgetCounter
);
205 function testRemoveChild(next
)
207 var parentWidget
= new TestWidget("Parent");
208 parentWidget
.show(WebInspector
.inspectorView
.element
);
210 var childWidget
= new TestWidget("Child");
211 childWidget
.show(parentWidget
.element
);
213 parentWidget
.element
.removeChild(childWidget
.element
);
215 InspectorTest
.addResult(e
);
220 function testImplicitRemoveChild(next
)
222 var parentWidget
= new TestWidget("Parent");
223 var div
= document
.createElement("div");
224 parentWidget
.element
.appendChild(div
);
226 var childWidget
= new TestWidget("Child");
227 childWidget
.show(div
);
230 parentWidget
.element
.removeChild(div
);
232 InspectorTest
.addResult(e
);
237 function testRemoveChildren(next
)
239 var parentWidget
= new TestWidget("Parent");
240 var childWidget
= new TestWidget("Child");
241 childWidget
.show(parentWidget
.element
);
242 parentWidget
.element
.appendChild(document
.createElement("div"));
244 parentWidget
.element
.removeChildren();
246 InspectorTest
.addResult(e
);
251 function testImplicitRemoveChildren(next
)
253 var parentWidget
= new TestWidget("Parent");
254 var div
= document
.createElement("div");
255 parentWidget
.element
.appendChild(div
);
257 var childWidget
= new TestWidget("Child");
258 childWidget
.show(div
);
261 parentWidget
.element
.removeChildren();
263 InspectorTest
.addResult(e
);
268 function testShowOnWasShown(next
)
270 var parentWidget
= new TestWidget("Parent");
271 parentWidget
.showOnWasShown
= new TestWidget("Child");
272 parentWidget
.show(WebInspector
.inspectorView
.element
);
273 parentWidget
.detach();
277 function testShowNestedOnWasShown(next
)
279 var topWidget
= new TestWidget("Top");
280 var middleWidget
= new TestWidget("Middle");
281 var bottomWidget
= new TestWidget("Bottom");
282 middleWidget
.show(topWidget
.element
);
283 topWidget
.showOnWasShown
= bottomWidget
;
284 topWidget
.showRoot
= middleWidget
.element
;
285 topWidget
.show(WebInspector
.inspectorView
.element
);
290 function testDetachOnWasShown(next
)
292 var parentWidget
= new TestWidget("Parent");
293 var childWidget
= new TestWidget("Child");
294 childWidget
.show(parentWidget
.element
);
295 parentWidget
.detachOnWasShown
= childWidget
;
296 parentWidget
.show(WebInspector
.inspectorView
.element
);
297 parentWidget
.detach();
301 function testShowOnWillHide(next
)
303 var parentWidget
= new TestWidget("Parent");
304 var childWidget
= new TestWidget("Child");
305 parentWidget
.show(WebInspector
.inspectorView
.element
);
306 childWidget
.show(parentWidget
.element
);
307 parentWidget
.showOnWillHide
= childWidget
;
308 parentWidget
.detach();
312 function testDetachOnWillHide(next
)
314 var parentWidget
= new TestWidget("Parent");
315 var childWidget
= new TestWidget("Child");
316 parentWidget
.show(WebInspector
.inspectorView
.element
);
317 childWidget
.show(parentWidget
.element
);
318 parentWidget
.detachOnWillHide
= childWidget
;
319 parentWidget
.detach();
323 function testShowDetachesFromPrevious(next
)
325 var parentWidget1
= new TestWidget("Parent1");
326 var parentWidget2
= new TestWidget("Parent2");
327 var childWidget
= new TestWidget("Child");
328 parentWidget1
.show(WebInspector
.inspectorView
.element
);
329 parentWidget2
.show(WebInspector
.inspectorView
.element
);
330 childWidget
.show(parentWidget1
.element
);
331 childWidget
.show(parentWidget2
.element
);
335 function testResizeOnWasShown(next
)
337 var parentWidget
= new TestWidget("Parent");
338 var childWidget
= new TestWidget("Child");
339 childWidget
.show(parentWidget
.element
);
340 parentWidget
.resizeOnWasShown
= childWidget
;
341 parentWidget
.show(WebInspector
.inspectorView
.element
);
342 parentWidget
.detach();
351 <body onload=
"runTest()">
353 This tests that events are properly propagated through Widget hierarchy.