Web Inspector: document.open removes the documentElement, but does not clear the...
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Apr 2012 08:49:28 +0000 (08:49 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Apr 2012 08:49:28 +0000 (08:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84179

Reviewed by Yury Semikhatsky.

Source/WebCore:

Perform total update upon modifications of the document node.

Test: inspector/elements/delete-from-document.html

* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::didRemoveDOMNode):
* inspector/front-end/ElementsTreeOutline.js:

LayoutTests:

* http/tests/inspector/elements-test.js:
(initialize_ElementTest.InspectorTest.dumpElementsTree.print):
(initialize_ElementTest.InspectorTest.dumpElementsTree):
* inspector/elements/delete-from-document-expected.txt: Added.
* inspector/elements/delete-from-document.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@114494 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/elements-test.js
LayoutTests/inspector/elements/delete-from-document-expected.txt [new file with mode: 0644]
LayoutTests/inspector/elements/delete-from-document.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/front-end/ElementsTreeOutline.js

index b0aa3e3..9bccf44 100644 (file)
@@ -1,3 +1,16 @@
+2012-04-17  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: document.open removes the documentElement, but does not clear the elements panel.
+        https://bugs.webkit.org/show_bug.cgi?id=84179
+
+        Reviewed by Yury Semikhatsky.
+
+        * http/tests/inspector/elements-test.js:
+        (initialize_ElementTest.InspectorTest.dumpElementsTree.print):
+        (initialize_ElementTest.InspectorTest.dumpElementsTree):
+        * inspector/elements/delete-from-document-expected.txt: Added.
+        * inspector/elements/delete-from-document.html: Added.
+
 2012-04-18  Max Feil  <mfeil@rim.com>
 
         [BlackBerry] Tab awareness for HTML5 concurrent audio
index 8893286..a0dd546 100644 (file)
@@ -311,14 +311,14 @@ InspectorTest.dumpStyleTreeItem = function(treeItem, prefix, depth)
     }
 };
 
-InspectorTest.dumpElementsTree = function(rootNode)
+InspectorTest.dumpElementsTree = function(rootNode, depth)
 {
     function beautify(element)
     {
         return element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").trim();
     }
 
-    function print(treeItem, prefix)
+    function print(treeItem, prefix, depth)
     {
         if (treeItem.listItemElement) {
             var expander;
@@ -332,23 +332,22 @@ InspectorTest.dumpElementsTree = function(rootNode)
 
             InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
         }
-        
 
         if (!treeItem.expanded)
             return;
 
         var children = treeItem.children;
-        for (var i = 0; children && i < children.length - 1; ++i)
-            print(children[i], prefix + "    ");
+        for (var i = 0; depth && children && i < children.length - 1; ++i)
+            print(children[i], prefix + "    ", depth - 1);
 
         // Closing tag.
         if (children && children.length)
-            print(children[children.length - 1], prefix);
+            print(children[children.length - 1], prefix, depth);
     }
 
     WebInspector.panels.elements.treeOutline._updateModifiedNodes();
     var treeOutline = WebInspector.panels.elements.treeOutline;
-    print(rootNode ? treeOutline.findTreeElement(rootNode) : treeOutline, "");
+    print(rootNode ? treeOutline.findTreeElement(rootNode) : treeOutline, "", depth || 10000);
 };
 
 InspectorTest.expandElementsTree = function(callback)
diff --git a/LayoutTests/inspector/elements/delete-from-document-expected.txt b/LayoutTests/inspector/elements/delete-from-document-expected.txt
new file mode 100644 (file)
index 0000000..cdd04af
--- /dev/null
@@ -0,0 +1,16 @@
+Tests that removing child from the document is handled properly in the elements panel.
+
+      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+- <html>
+    - <head>
+      </head>
+    - <body onload="runTest()">
+      </body>
+  </html>
+- <html>
+    - <head>
+      </head>
+    - <body onload="runTest()">
+      </body>
+  </html>
+
diff --git a/LayoutTests/inspector/elements/delete-from-document.html b/LayoutTests/inspector/elements/delete-from-document.html
new file mode 100644 (file)
index 0000000..a17b6fd
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/elements-test.js"></script>
+<script>
+
+function removeDoctype()
+{
+    document.removeChild(document.firstChild);
+}
+
+function test()
+{
+    InspectorTest.expandElementsTree(step1);
+
+    function step1()
+    {
+        InspectorTest.dumpElementsTree(null, 1);
+        InspectorTest.evaluateInPage("removeDoctype()", step2);
+    }
+
+    function step2()
+    {
+        InspectorTest.dumpElementsTree(null, 1);
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Tests that removing child from the document is handled properly in the elements panel.
+</p>
+
+</body>
+</html>
index f910a19..0d94732 100644 (file)
@@ -1,3 +1,18 @@
+2012-04-17  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: document.open removes the documentElement, but does not clear the elements panel.
+        https://bugs.webkit.org/show_bug.cgi?id=84179
+
+        Reviewed by Yury Semikhatsky.
+
+        Perform total update upon modifications of the document node.
+
+        Test: inspector/elements/delete-from-document.html
+
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::didRemoveDOMNode):
+        * inspector/front-end/ElementsTreeOutline.js:
+
 2012-04-18  Max Feil  <mfeil@rim.com>
 
         [BlackBerry] Tab awareness for HTML5 concurrent audio
index e5372cb..5f0aafe 100644 (file)
@@ -1421,11 +1421,13 @@ void InspectorDOMAgent::didRemoveDOMNode(Node* node)
         return;
 
     ContainerNode* parent = node->parentNode();
-    int parentId = m_documentNodeToIdMap.get(parent);
+
     // If parent is not mapped yet -> ignore the event.
-    if (!parentId)
+    if (!m_documentNodeToIdMap.contains(parent))
         return;
 
+    int parentId = m_documentNodeToIdMap.get(parent);
+
     if (m_domListener)
         m_domListener->didRemoveDOMNode(node);
 
index 20d978b..2de7fd9 100644 (file)
@@ -1846,6 +1846,13 @@ WebInspector.ElementsTreeUpdater.prototype = {
 
         for (var i = 0; i < this._recentlyModifiedNodes.length; ++i) {
             var parent = this._recentlyModifiedNodes[i].parent;
+
+            if (parent === this._treeOutline._rootDOMNode) {
+                // Document's children have changed, perform total update.
+                this._treeOutline.update();
+                return;
+            }
+
             var node = this._recentlyModifiedNodes[i].node;
 
             if (this._recentlyModifiedNodes[i].updated) {