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 TestWidget(widgetName) |
| 9 { |
| 10 WebInspector.Widget.call(this); |
| 11 |
| 12 this._widgetName = widgetName; |
| 13 this._processWillShowCount = 0; |
| 14 this._processWasHiddenCount = 0; |
| 15 InspectorTest.addResult(this._widgetName + "()"); |
| 16 } |
| 17 |
| 18 TestWidget.prototype = { |
| 19 _processWillShow: function() |
| 20 { |
| 21 InspectorTest.assertEquals(this._processWillShowCount, this._process
WasHiddenCount); |
| 22 WebInspector.Widget.prototype._processWillShow.call(this); |
| 23 ++this._processWillShowCount; |
| 24 }, |
| 25 |
| 26 _processWasHidden: function() |
| 27 { |
| 28 WebInspector.Widget.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._widgetName + ".show()"); |
| 36 WebInspector.Widget.prototype.show.call(this, parentElement); |
| 37 }, |
| 38 |
| 39 detach: function() |
| 40 { |
| 41 InspectorTest.addResult(this._widgetName + ".detach()"); |
| 42 WebInspector.Widget.prototype.detach.call(this); |
| 43 }, |
| 44 |
| 45 doResize: function() |
| 46 { |
| 47 InspectorTest.addResult(this._widgetName + ".doResize()"); |
| 48 WebInspector.Widget.prototype.doResize.call(this); |
| 49 }, |
| 50 |
| 51 wasShown: function() |
| 52 { |
| 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(); |
| 60 }, |
| 61 |
| 62 willHide: function() |
| 63 { |
| 64 InspectorTest.addResult(" " + this._widgetName + ".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._widgetName + ".onResize()"); |
| 74 } |
| 75 }; |
| 76 |
| 77 TestWidget.prototype.__proto__ = WebInspector.Widget.prototype; |
| 78 |
| 79 InspectorTest.runTestSuite([ |
| 80 function testShowWidget(next) |
| 81 { |
| 82 var widget = new TestWidget("Widget"); |
| 83 widget.show(WebInspector.inspectorView.element); |
| 84 widget.detach(); |
| 85 next(); |
| 86 }, |
| 87 |
| 88 function testAppendViaDOM(next) |
| 89 { |
| 90 try { |
| 91 var widget = new TestWidget("Widget"); |
| 92 document.body.appendChild(widget.element); |
| 93 } catch (e) { |
| 94 InspectorTest.addResult(e); |
| 95 } |
| 96 next(); |
| 97 }, |
| 98 |
| 99 function testInsertViaDOM(next) |
| 100 { |
| 101 try { |
| 102 var widget = new TestWidget("Widget"); |
| 103 document.body.insertBefore(widget.element, null); |
| 104 } catch (e) { |
| 105 InspectorTest.addResult(e); |
| 106 } |
| 107 next(); |
| 108 }, |
| 109 |
| 110 function testAttachToOrphanNode(next) |
| 111 { |
| 112 try { |
| 113 var widget = new TestWidget("Widget"); |
| 114 var div = document.createElement("div"); |
| 115 widget.show(div); |
| 116 } catch (e) { |
| 117 InspectorTest.addResult(e); |
| 118 } |
| 119 next(); |
| 120 }, |
| 121 |
| 122 function testImmediateParent(next) |
| 123 { |
| 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"); |
| 129 else |
| 130 InspectorTest.addResult("FAILED"); |
| 131 next(); |
| 132 }, |
| 133 |
| 134 function testDistantParent(next) |
| 135 { |
| 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); |
| 141 |
| 142 if (childWidget._parentWidget === parentWidget) |
| 143 InspectorTest.addResult("OK"); |
| 144 else |
| 145 InspectorTest.addResult("FAILED"); |
| 146 next(); |
| 147 }, |
| 148 |
| 149 function testEvents(next) |
| 150 { |
| 151 var parentWidget = new TestWidget("Parent"); |
| 152 parentWidget.markAsRoot(); |
| 153 var childWidget = new TestWidget("Child"); |
| 154 parentWidget.show(WebInspector.inspectorView.element); |
| 155 |
| 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(); |
| 163 next(); |
| 164 }, |
| 165 |
| 166 function testEventsHideOnDetach(next) |
| 167 { |
| 168 var parentWidget = new TestWidget("Parent"); |
| 169 var childWidget = new TestWidget("Child"); |
| 170 childWidget.setHideOnDetach(); |
| 171 parentWidget.show(WebInspector.inspectorView.element); |
| 172 |
| 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(); |
| 180 next(); |
| 181 }, |
| 182 |
| 183 function testWidgetCounter(next) |
| 184 { |
| 185 var parentWidget = new TestWidget("Parent"); |
| 186 parentWidget.show(WebInspector.inspectorView.element); |
| 187 |
| 188 var childWidget = new TestWidget("Child"); |
| 189 childWidget.show(parentWidget.element); |
| 190 InspectorTest.addResult(" widget counter: " + parentWidget.element.
__widgetCounter); |
| 191 |
| 192 var childWidget2 = new TestWidget("Child 2"); |
| 193 childWidget2.show(parentWidget.element); |
| 194 InspectorTest.addResult(" widget counter: " + parentWidget.element.
__widgetCounter); |
| 195 |
| 196 childWidget.detach(); |
| 197 InspectorTest.addResult(" widget counter: " + parentWidget.element.
__widgetCounter); |
| 198 |
| 199 childWidget2.detach(); |
| 200 InspectorTest.addResult(" widget counter: " + parentWidget.element.
__widgetCounter); |
| 201 |
| 202 next(); |
| 203 }, |
| 204 |
| 205 function testRemoveChild(next) |
| 206 { |
| 207 var parentWidget = new TestWidget("Parent"); |
| 208 parentWidget.show(WebInspector.inspectorView.element); |
| 209 |
| 210 var childWidget = new TestWidget("Child"); |
| 211 childWidget.show(parentWidget.element); |
| 212 try { |
| 213 parentWidget.element.removeChild(childWidget.element); |
| 214 } catch (e) { |
| 215 InspectorTest.addResult(e); |
| 216 } |
| 217 next(); |
| 218 }, |
| 219 |
| 220 function testImplicitRemoveChild(next) |
| 221 { |
| 222 var parentWidget = new TestWidget("Parent"); |
| 223 var div = document.createElement("div"); |
| 224 parentWidget.element.appendChild(div); |
| 225 |
| 226 var childWidget = new TestWidget("Child"); |
| 227 childWidget.show(div); |
| 228 |
| 229 try { |
| 230 parentWidget.element.removeChild(div); |
| 231 } catch (e) { |
| 232 InspectorTest.addResult(e); |
| 233 } |
| 234 next(); |
| 235 }, |
| 236 |
| 237 function testRemoveChildren(next) |
| 238 { |
| 239 var parentWidget = new TestWidget("Parent"); |
| 240 var childWidget = new TestWidget("Child"); |
| 241 childWidget.show(parentWidget.element); |
| 242 parentWidget.element.appendChild(document.createElement("div")); |
| 243 try { |
| 244 parentWidget.element.removeChildren(); |
| 245 } catch (e) { |
| 246 InspectorTest.addResult(e); |
| 247 } |
| 248 next(); |
| 249 }, |
| 250 |
| 251 function testImplicitRemoveChildren(next) |
| 252 { |
| 253 var parentWidget = new TestWidget("Parent"); |
| 254 var div = document.createElement("div"); |
| 255 parentWidget.element.appendChild(div); |
| 256 |
| 257 var childWidget = new TestWidget("Child"); |
| 258 childWidget.show(div); |
| 259 |
| 260 try { |
| 261 parentWidget.element.removeChildren(); |
| 262 } catch (e) { |
| 263 InspectorTest.addResult(e); |
| 264 } |
| 265 next(); |
| 266 }, |
| 267 |
| 268 function testShowOnWasShown(next) |
| 269 { |
| 270 var parentWidget = new TestWidget("Parent"); |
| 271 parentWidget.showOnWasShown = new TestWidget("Child"); |
| 272 parentWidget.show(WebInspector.inspectorView.element); |
| 273 parentWidget.detach(); |
| 274 next(); |
| 275 }, |
| 276 |
| 277 function testShowNestedOnWasShown(next) |
| 278 { |
| 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); |
| 286 topWidget.detach(); |
| 287 next(); |
| 288 }, |
| 289 |
| 290 function testDetachOnWasShown(next) |
| 291 { |
| 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(); |
| 298 next(); |
| 299 }, |
| 300 |
| 301 function testShowOnWillHide(next) |
| 302 { |
| 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(); |
| 309 next(); |
| 310 }, |
| 311 |
| 312 function testDetachOnWillHide(next) |
| 313 { |
| 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(); |
| 320 next(); |
| 321 }, |
| 322 |
| 323 function testShowDetachesFromPrevious(next) |
| 324 { |
| 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); |
| 332 next(); |
| 333 }, |
| 334 |
| 335 function testResizeOnWasShown(next) |
| 336 { |
| 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(); |
| 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 Widget hierarchy. |
| 354 </p> |
| 355 |
| 356 </body> |
| 357 </html> |
OLD | NEW |