Title: [107242] trunk
Revision
107242
Author
[email protected]
Date
2012-02-09 07:26:58 -0800 (Thu, 09 Feb 2012)

Log Message

Web Inspector: fix setOuterHTML for the case that adds / removes duplicate.
https://bugs.webkit.org/show_bug.cgi?id=78235

Reviewed by Yury Semikhatsky.

Source/WebCore:

* inspector/DOMEditor.cpp:
(WebCore::DOMEditor::diff):
(WebCore::DOMEditor::innerPatchChildren):
(WebCore):
(WebCore::nodeName):
(WebCore::DOMEditor::dumpMap):
* inspector/DOMEditor.h:
(DOMEditor):

LayoutTests:

* inspector/elements/set-outer-html-2-expected.txt:
* inspector/elements/set-outer-html-2.html:
* inspector/elements/set-outer-html-expected.txt:
* inspector/elements/set-outer-html.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (107241 => 107242)


--- trunk/LayoutTests/ChangeLog	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/LayoutTests/ChangeLog	2012-02-09 15:26:58 UTC (rev 107242)
@@ -1,3 +1,15 @@
+2012-02-09  Pavel Feldman  <[email protected]>
+
+        Web Inspector: fix setOuterHTML for the case that adds / removes duplicate.
+        https://bugs.webkit.org/show_bug.cgi?id=78235
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/elements/set-outer-html-2-expected.txt:
+        * inspector/elements/set-outer-html-2.html:
+        * inspector/elements/set-outer-html-expected.txt:
+        * inspector/elements/set-outer-html.html:
+
 2012-02-09  Pavel Podivilov  <[email protected]>
 
         Unreviewed, update chromium svg expectations after r107207.

Modified: trunk/LayoutTests/inspector/elements/set-outer-html-2-expected.txt (107241 => 107242)


--- trunk/LayoutTests/inspector/elements/set-outer-html-2-expected.txt	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/LayoutTests/inspector/elements/set-outer-html-2-expected.txt	2012-02-09 15:26:58 UTC (rev 107242)
@@ -12,11 +12,8 @@
 Event NodeRemoved: UL
 ==========8<==========
 <div id="container" style="display:none">
-<h2 foo="bar" bar="baz">Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
-<h2>Getting involved</h2>
-<a href=""
+<h2 foo="bar" bar="baz">Getting involved</h2>
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    
@@ -35,11 +32,8 @@
 Event ChildNodeCountUpdated: UL
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>
@@ -60,11 +54,8 @@
 Event NodeRemoved: UL
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <div><ul>
    <li></li>
@@ -82,11 +73,8 @@
 Event NodeRemoved: DIV
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>
@@ -107,11 +95,8 @@
 Event NodeRemoved: H2
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
 
-
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>
@@ -125,17 +110,14 @@
 Bringing things back
 
 Wrapper identity: identity
-Event NodeInserted: A
 Event NodeInserted: H2
-Event NodeRemoved: A
+Event NodeInserted: P
 Event NodeRemoved: H2
+Event NodeRemoved: P
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>
@@ -155,11 +137,25 @@
 Event NodeInserted: DIV
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
+<h2>Getting involved</h2>
+<p id="identity">There are many ways to get involved. You can:</p>
+<ul>
+   <li></li>
+</ul>
+<ul>
+   <li></li>
+</ul>
+</div>
+==========>8==========
 
+Bringing things back
+
+Wrapper identity: identity
+==========8<==========
+<div id="container" style="display:none">
+<p>WebKit is used by <a href="" Dashboard, etc..</p>
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>
@@ -170,16 +166,37 @@
 </div>
 ==========>8==========
 
+
+
+
+
+Running: testDupeNode
+Replacing '<h2>Getting involved</h2>' with '<h2>Getting involved</h2><h2>Getting involved</h2>'
+
+Wrapper identity: identity
+Event NodeInserted: H2
+==========8<==========
+<div id="container" style="display:none">
+<p>WebKit is used by <a href="" Dashboard, etc..</p>
+<h2>Getting involved</h2><h2>Getting involved</h2>
+<p id="identity">There are many ways to get involved. You can:</p>
+<ul>
+   <li></li>
+</ul>
+<ul>
+   <li></li>
+</ul>
+</div>
+==========>8==========
+
 Bringing things back
 
 Wrapper identity: identity
+Event NodeRemoved: H2
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>

Modified: trunk/LayoutTests/inspector/elements/set-outer-html-2.html (107241 => 107242)


--- trunk/LayoutTests/inspector/elements/set-outer-html-2.html	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/LayoutTests/inspector/elements/set-outer-html-2.html	2012-02-09 15:26:58 UTC (rev 107242)
@@ -45,6 +45,11 @@
         {
             var text = InspectorTest.containerText + "<div>Additional node</div>";
             InspectorTest.setOuterHTML(text, next);
+        },
+
+        function testDupeNode(next)
+        {
+            InspectorTest.patchOuterHTML("<h2>Getting involved</h2>", "<h2>Getting involved</h2><h2>Getting involved</h2>", next);
         }
     ]);
 }
@@ -57,11 +62,8 @@
 </p>
 
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
-<p>WebKit is used by <a href="" Dashboard, etc.</a>.</p>
-
+<p>WebKit is used by <a href="" Dashboard, etc..</p>
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
 <ul>
    <li></li>

Modified: trunk/LayoutTests/inspector/elements/set-outer-html-expected.txt (107241 => 107242)


--- trunk/LayoutTests/inspector/elements/set-outer-html-expected.txt	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/LayoutTests/inspector/elements/set-outer-html-expected.txt	2012-02-09 15:26:58 UTC (rev 107242)
@@ -10,18 +10,9 @@
 Event CharacterDataModified: 
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting not involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -31,18 +22,9 @@
 Event CharacterDataModified: 
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -59,18 +41,9 @@
 Event AttrRemoved: A
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a foo="bar" href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -82,18 +55,9 @@
 Event AttrRemoved: A
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -108,18 +72,9 @@
 Event NodeRemoved: 
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2></h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -129,18 +84,9 @@
 Event NodeInserted: 
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -157,18 +103,9 @@
 Event NodeRemoved: H2
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting</h2><h2>involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -180,18 +117,9 @@
 Event NodeRemoved: H2
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -207,18 +135,9 @@
 Event NodeRemoved: H2
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h3>Getting involved</h3>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 
@@ -229,18 +148,9 @@
 Event NodeRemoved: H3
 ==========8<==========
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc..</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 ==========>8==========
 

Modified: trunk/LayoutTests/inspector/elements/set-outer-html.html (107241 => 107242)


--- trunk/LayoutTests/inspector/elements/set-outer-html.html	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/LayoutTests/inspector/elements/set-outer-html.html	2012-02-09 15:26:58 UTC (rev 107242)
@@ -55,18 +55,9 @@
 </p>
 
 <div id="container" style="display:none">
-<h2>Welcome to the website for the WebKit Open Source Project!</h2>
 <p>WebKit is used by <a href="" Dashboard, etc.</a>.</p>
-
 <h2>Getting involved</h2>
-<a href=""
 <p id="identity">There are many ways to get involved. You can:</p>
-<ul>
-   <li></li>
-</ul>
-<ul>
-   <li></li>
-</ul>
 </div>
 
 </body>

Modified: trunk/Source/WebCore/ChangeLog (107241 => 107242)


--- trunk/Source/WebCore/ChangeLog	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/Source/WebCore/ChangeLog	2012-02-09 15:26:58 UTC (rev 107242)
@@ -1,3 +1,19 @@
+2012-02-09  Pavel Feldman  <[email protected]>
+
+        Web Inspector: fix setOuterHTML for the case that adds / removes duplicate.
+        https://bugs.webkit.org/show_bug.cgi?id=78235
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/DOMEditor.cpp:
+        (WebCore::DOMEditor::diff):
+        (WebCore::DOMEditor::innerPatchChildren):
+        (WebCore):
+        (WebCore::nodeName):
+        (WebCore::DOMEditor::dumpMap):
+        * inspector/DOMEditor.h:
+        (DOMEditor):
+
 2012-02-09  Allan Sandfeld Jensen  <[email protected]>
 
         Ensure timers and other active DOM objects do not fire in suspended documents.

Modified: trunk/Source/WebCore/inspector/DOMEditor.cpp (107241 => 107242)


--- trunk/Source/WebCore/inspector/DOMEditor.cpp	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/Source/WebCore/inspector/DOMEditor.cpp	2012-02-09 15:26:58 UTC (rev 107242)
@@ -260,6 +260,11 @@
         }
     }
 
+#ifdef DEBUG_DOM_EDITOR
+    dumpMap(oldMap, "OLD");
+    dumpMap(newMap, "NEW");
+#endif
+
     return make_pair(oldMap, newMap);
 }
 
@@ -274,9 +279,16 @@
 
     // 1. First strip everything except for the nodes that retain. Collect pending merges.
     HashMap<Digest*, Digest*> merges;
+    HashSet<size_t> usedNewOrdinals;
     for (size_t i = 0; i < oldList.size(); ++i) {
-        if (oldMap[i].first)
-            continue;
+        if (oldMap[i].first) {
+            if (!usedNewOrdinals.contains(oldMap[i].second)) {
+                usedNewOrdinals.add(oldMap[i].second);
+                continue;
+            }
+            oldMap[i].first = 0;
+            oldMap[i].second = 0;
+        }
 
         // Always match <head> and <body> tags with each other - we can't remove them from the DOM
         // upon patching.
@@ -307,10 +319,20 @@
         }
     }
 
-    // Mark retained nodes as used.
+    // Mark retained nodes as used, do not reuse node more than once.
+    HashSet<size_t> usedOldOrdinals;
     for (size_t i = 0; i < newList.size(); ++i) {
-        if (newMap[i].first)
-            markNodeAsUsed(newMap[i].first);
+        if (!newMap[i].first)
+            continue;
+        size_t oldOrdinal = newMap[i].second;
+        if (usedOldOrdinals.contains(oldOrdinal)) {
+            // Do not map node more than once
+            newMap[i].first = 0;
+            newMap[i].second = 0;
+            continue;
+        }
+        usedOldOrdinals.add(oldOrdinal);
+        markNodeAsUsed(newMap[i].first);
     }
 
     // Mark <head> and <body> nodes for merge.
@@ -451,6 +473,22 @@
     }
 }
 
+#ifdef DEBUG_DOM_EDITOR
+static String nodeName(Node* node)
+{
+    if (node->document()->isXHTMLDocument())
+         return node->nodeName();
+    return node->nodeName().lower();
+}
+
+void DOMEditor::dumpMap(const ResultMap& map, const String& name)
+{
+    fprintf(stderr, "\n\n");
+    for (size_t i = 0; i < map.size(); ++i)
+        fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map[i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map[i].second);
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)

Modified: trunk/Source/WebCore/inspector/DOMEditor.h (107241 => 107242)


--- trunk/Source/WebCore/inspector/DOMEditor.h	2012-02-09 15:23:16 UTC (rev 107241)
+++ trunk/Source/WebCore/inspector/DOMEditor.h	2012-02-09 15:26:58 UTC (rev 107242)
@@ -68,6 +68,9 @@
     void insertBefore(ContainerNode*, Digest*, Node* anchor, ExceptionCode&);
     void removeChild(Digest*, ExceptionCode&);
     void markNodeAsUsed(Digest*);
+#ifdef DEBUG_DOM_EDITOR
+    void dumpMap(const ResultMap&, const String& name);
+#endif
 
     Document* m_document;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to