Web Inspector: clean up initialization of managers and observers in InspectorTest
[WebKit-https.git] / LayoutTests / inspector-protocol / model / content-flow-content-removal.html
1 <!doctype html>
2 <html>
3 <head>
4 <style>
5 .content
6 {
7     -webkit-flow-into: flow;
8 }
9 </style>
10 <script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
11 <script>
12 function changeFlowContent()
13 {
14     document.getElementById("contentRemoved").remove();
15 }
16
17 function test()
18 {
19     InspectorTest.initializeInspectorModels();
20
21     var contentFlow;
22
23     WebInspector.frameResourceManager.addEventListener(WebInspector.FrameResourceManager.Event.MainFrameDidChange, function(event) {
24         var domTree = WebInspector.frameResourceManager.mainFrame.domTree;
25         domTree.addEventListener(WebInspector.DOMTree.Event.RootDOMNodeInvalidated, onRootDOMNodeInvalidated, null);
26         domTree.addEventListener(WebInspector.DOMTree.Event.ContentFlowWasAdded, onContentFlowWasAdded, null);
27         domTree.requestContentFlowList();
28     });
29
30     function onRootDOMNodeInvalidated()
31     {
32         WebInspector.frameResourceManager.mainFrame.domTree.requestContentFlowList();
33     }
34
35     function onContentFlowWasAdded(event)
36     {
37         contentFlow = event.data.flow;
38         InspectorTest.assert(contentFlow.name === "flow", "ContentFlow was added.");
39         InspectorTest.assert(contentFlow.contentNodes.length === 2, "ContentFlow.contentNodes has a length of 2.");
40         InspectorTest.assert(contentFlow.contentNodes[0].getAttribute("id") === "contentStatic", "ContentFlow.contentNodes[0].id is \"#contentStatic\".");
41         InspectorTest.assert(contentFlow.contentNodes[1].getAttribute("id") === "contentRemoved", "ContentFlow.contentNodes[1].id is \"#contentRemoved\".");
42
43         contentFlow.addEventListener(WebInspector.ContentFlow.Event.ContentNodeWasRemoved, onContentNodeWasRemoved, null);
44
45         InspectorTest.sendCommand("Runtime.evaluate", {expression: "changeFlowContent()"});
46     }
47
48     function onContentNodeWasRemoved(event)
49     {
50         InspectorTest.assert(event.data.node.getAttribute("id") === "contentRemoved", "\"#contentRemoved\" was removed.");
51         InspectorTest.assert(contentFlow.contentNodes.indexOf(event.data.node) === -1, "\"#contentRemoved\" cannot be found in the contentNodes list.");
52         InspectorTest.completeTest();
53     }
54 }
55 </script>
56 </head>
57 <body onload="runTest()">
58     <p>Testing that the ContentFlows events are correctly dispatched when content nodes are detached from the DOM.</p>
59
60     <div id="contentStatic" class="content"></div>
61     <div id="contentRemoved" class="content"></div>
62
63 </body>
64 </html>