| <html> |
| <head> |
| <script src="../http/tests/inspector/inspector-test.js"></script> |
| <script> |
| |
| function test() |
| { |
| function TestView(viewName) |
| { |
| WebInspector.View.call(this); |
| |
| this._viewName = viewName; |
| InspectorTest.addResult(this._viewName + "()"); |
| } |
| |
| TestView.prototype = { |
| show: function(parentElement) |
| { |
| InspectorTest.addResult(this._viewName + ".show()"); |
| WebInspector.View.prototype.show.call(this, parentElement); |
| }, |
| |
| detach: function() |
| { |
| InspectorTest.addResult(this._viewName + ".detach()"); |
| WebInspector.View.prototype.detach.call(this); |
| }, |
| |
| doResize: function() |
| { |
| InspectorTest.addResult(this._viewName + ".doResize()"); |
| WebInspector.View.prototype.doResize.call(this); |
| }, |
| |
| wasShown: function() |
| { |
| InspectorTest.addResult(" " + this._viewName + ".wasShown()"); |
| if (this.showOnWasShown) |
| this.showOnWasShown.show(this.element); |
| if (this.detachOnWasShown) |
| this.detachOnWasShown.detach(); |
| }, |
| |
| willHide: function() |
| { |
| InspectorTest.addResult(" " + this._viewName + ".willHide()"); |
| if (this.showOnWillHide) |
| this.showOnWillHide.show(this.element); |
| if (this.detachOnWillHide) |
| this.detachOnWillHide.detach(); |
| }, |
| |
| onResize: function() |
| { |
| InspectorTest.addResult(" " + this._viewName + ".onResize()"); |
| } |
| }; |
| |
| TestView.prototype.__proto__ = WebInspector.View.prototype; |
| |
| InspectorTest.runTestSuite([ |
| function testShowView(next) |
| { |
| var view = new TestView("View"); |
| view.show(WebInspector.inspectorView.element); |
| view.detach(); |
| next(); |
| }, |
| |
| function testAppendViaDOM(next) |
| { |
| try { |
| var view = new TestView("View"); |
| document.body.appendChild(view.element); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testInsertViaDOM(next) |
| { |
| try { |
| var view = new TestView("View"); |
| document.body.insertBefore(view.element, null); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testAttachToOrphanNode(next) |
| { |
| try { |
| var view = new TestView("View"); |
| var div = document.createElement("div"); |
| view.show(div); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testImmediateParent(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| childView.show(parentView.element); |
| if (childView._parentView === parentView) |
| InspectorTest.addResult("OK"); |
| else |
| InspectorTest.addResult("FAILED"); |
| next(); |
| }, |
| |
| function testDistantParent(next) |
| { |
| var parentView = new TestView("Parent"); |
| var div = document.createElement("div"); |
| parentView.element.appendChild(div); |
| var childView = new TestView("Child"); |
| childView.show(div); |
| |
| if (childView._parentView === parentView) |
| InspectorTest.addResult("OK"); |
| else |
| InspectorTest.addResult("FAILED"); |
| next(); |
| }, |
| |
| function testEvents(next) |
| { |
| var parentView = new TestView("Parent"); |
| parentView.markAsRoot(); |
| var childView = new TestView("Child"); |
| parentView.show(WebInspector.inspectorView.element); |
| |
| parentView.doResize(); |
| childView.show(parentView.element); |
| parentView.doResize(); |
| parentView.detach(); |
| parentView.show(WebInspector.inspectorView.element); |
| childView.detach(); |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testEventsHideOnDetach(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| childView.setHideOnDetach(); |
| parentView.show(WebInspector.inspectorView.element); |
| |
| parentView.doResize(); |
| childView.show(parentView.element); |
| parentView.doResize(); |
| parentView.detach(); |
| parentView.show(WebInspector.inspectorView.element); |
| childView.detach(); |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testViewCounter(next) |
| { |
| var parentView = new TestView("Parent"); |
| parentView.show(WebInspector.inspectorView.element); |
| |
| var childView = new TestView("Child"); |
| childView.show(parentView.element); |
| InspectorTest.addResult(" view counter: " + parentView.element.__viewCounter); |
| |
| var childView2 = new TestView("Child 2"); |
| childView2.show(parentView.element); |
| InspectorTest.addResult(" view counter: " + parentView.element.__viewCounter); |
| |
| childView.detach(); |
| InspectorTest.addResult(" view counter: " + parentView.element.__viewCounter); |
| |
| childView2.detach(); |
| InspectorTest.addResult(" view counter: " + parentView.element.__viewCounter); |
| |
| next(); |
| }, |
| |
| function testRemoveChild(next) |
| { |
| var parentView = new TestView("Parent"); |
| parentView.show(WebInspector.inspectorView.element); |
| |
| var childView = new TestView("Child"); |
| childView.show(parentView.element); |
| try { |
| parentView.element.removeChild(childView.element); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testImplicitRemoveChild(next) |
| { |
| var parentView = new TestView("Parent"); |
| var div = document.createElement("div"); |
| parentView.element.appendChild(div); |
| |
| var childView = new TestView("Child"); |
| childView.show(div); |
| |
| try { |
| parentView.element.removeChild(div); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testRemoveChildren(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| childView.show(parentView.element); |
| parentView.element.appendChild(document.createElement("div")); |
| try { |
| parentView.element.removeChildren(); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testImplicitRemoveChildren(next) |
| { |
| var parentView = new TestView("Parent"); |
| var div = document.createElement("div"); |
| parentView.element.appendChild(div); |
| |
| var childView = new TestView("Child"); |
| childView.show(div); |
| |
| try { |
| parentView.element.removeChildren(); |
| } catch (e) { |
| InspectorTest.addResult(e); |
| } |
| next(); |
| }, |
| |
| function testShowOnWasShown(next) |
| { |
| var parentView = new TestView("Parent"); |
| parentView.showOnWasShown = new TestView("Child"); |
| parentView.show(WebInspector.inspectorView.element); |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testDetachOnWasShown(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| childView.show(parentView.element); |
| parentView.detachOnWasShown = childView; |
| parentView.show(WebInspector.inspectorView.element); |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testShowOnWillHide(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| parentView.show(WebInspector.inspectorView.element); |
| childView.show(parentView.element); |
| parentView.showOnWillHide = childView; |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testDetachOnWillHide(next) |
| { |
| var parentView = new TestView("Parent"); |
| var childView = new TestView("Child"); |
| parentView.show(WebInspector.inspectorView.element); |
| childView.show(parentView.element); |
| parentView.detachOnWillHide = childView; |
| parentView.detach(); |
| next(); |
| }, |
| |
| function testShowDetachesFromPrevious(next) |
| { |
| var parentView1 = new TestView("Parent1"); |
| var parentView2 = new TestView("Parent2"); |
| var childView = new TestView("Child"); |
| parentView1.show(WebInspector.inspectorView.element); |
| parentView2.show(WebInspector.inspectorView.element); |
| childView.show(parentView1.element); |
| childView.show(parentView2.element); |
| next(); |
| } |
| ]); |
| } |
| |
| </script> |
| </head> |
| |
| <body onload="runTest()"> |
| <p> |
| This tests that events are properly propagated through View hierarchy. |
| </p> |
| |
| </body> |
| </html> |