Web Inspector: check undo-redo boundaries based on current action index, not history...
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 16:13:59 +0000 (16:13 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 16:13:59 +0000 (16:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78895

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Tests: inspector/elements/perform-undo-undo.html
       inspector/styles/perform-undo-perform-of-mergable-action.html

* inspector/InspectorHistory.cpp:
(WebCore::InspectorHistory::perform):

LayoutTests:

* inspector/elements/perform-undo-undo-expected.txt: Added.
* inspector/elements/perform-undo-undo.html: Added.
* inspector/styles/perform-undo-perform-of-mergable-action-expected.txt: Added.
* inspector/styles/perform-undo-perform-of-mergable-action.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/elements/perform-undo-undo-expected.txt [new file with mode: 0644]
LayoutTests/inspector/elements/perform-undo-undo.html [new file with mode: 0644]
LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action-expected.txt [new file with mode: 0644]
LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorHistory.cpp

index 1bea75b..be2f266 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-17  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: check undo-redo boundaries based on current action index, not history size.
+        https://bugs.webkit.org/show_bug.cgi?id=78895
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/elements/perform-undo-undo-expected.txt: Added.
+        * inspector/elements/perform-undo-undo.html: Added.
+        * inspector/styles/perform-undo-perform-of-mergable-action-expected.txt: Added.
+        * inspector/styles/perform-undo-perform-of-mergable-action.html: Added.
+
 2012-02-17  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, skipping 2 new test failures on GTK.
diff --git a/LayoutTests/inspector/elements/perform-undo-undo-expected.txt b/LayoutTests/inspector/elements/perform-undo-undo-expected.txt
new file mode 100644 (file)
index 0000000..157c8d9
--- /dev/null
@@ -0,0 +1,11 @@
+Tests that client can call undo multiple times with non-empty history.
+
+========= Original ========
+  <div style="display:none" id="container"></div>
+===== Modified element =====
+  <div style="display:none" id="container" foo="bar"></div>
+===== Undo 1 =====
+  <div style="display:none" id="container"></div>
+===== Undo 2 =====
+  <div style="display:none" id="container"></div>
+
diff --git a/LayoutTests/inspector/elements/perform-undo-undo.html b/LayoutTests/inspector/elements/perform-undo-undo.html
new file mode 100644 (file)
index 0000000..3b701b2
--- /dev/null
@@ -0,0 +1,66 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/elements-test.js"></script>
+<script>
+
+function test()
+{
+    var containerNode;
+    InspectorTest.expandElementsTree(step1);
+
+    function step1(node)
+    {
+        containerNode = InspectorTest.expandedNodeWithId("container");
+        InspectorTest.addResult("========= Original ========");
+        InspectorTest.dumpElementsTree(containerNode);
+        step2();
+    }
+
+    function step2()
+    {
+        function callback()
+        {
+            InspectorTest.addResult("===== Modified element =====");
+            InspectorTest.dumpElementsTree(containerNode);
+            step3();
+        }
+        containerNode.setAttribute("", "foo=\"bar\"", callback);
+    }
+
+    function step3()
+    {
+        function callback()
+        {
+            InspectorTest.addResult("===== Undo 1 =====");
+            InspectorTest.dumpElementsTree(containerNode);
+            step4();
+        }
+        WebInspector.domAgent.undo(callback);
+    }
+
+    function step4()
+    {
+        function callback()
+        {
+            InspectorTest.addResult("===== Undo 2 =====");
+            InspectorTest.dumpElementsTree(containerNode);
+            InspectorTest.completeTest();
+        }
+        WebInspector.domAgent.undo(callback);
+    }
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Tests that client can call undo multiple times with non-empty history.
+</p>
+
+<div style="display:none" id="container">
+</div>
+
+</body>
+</html>
diff --git a/LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action-expected.txt b/LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action-expected.txt
new file mode 100644 (file)
index 0000000..10a826a
--- /dev/null
@@ -0,0 +1,59 @@
+Tests that perform-undo-perform of the mergeable action does not crash.
+
+Initial value
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (perform-undo-perform-of-mergable-action.html:7)
+font-weight: bold;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+After changing property
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (perform-undo-perform-of-mergable-action.html:7)
+font-weight: normal;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+After undo
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (perform-undo-perform-of-mergable-action.html:7)
+font-weight: bold;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+After perform
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (perform-undo-perform-of-mergable-action.html:7)
+font-weight: normal;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+
diff --git a/LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action.html b/LayoutTests/inspector/styles/perform-undo-perform-of-mergable-action.html
new file mode 100644 (file)
index 0000000..05ec199
--- /dev/null
@@ -0,0 +1,66 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/elements-test.js"></script>
+
+<style>
+.container {
+  font-weight: bold
+}
+</style>
+
+<script>
+
+function test()
+{
+    InspectorTest.selectNodeAndWaitForStyles("container", step1);
+
+    function step1()
+    {
+        InspectorTest.addResult("Initial value");
+        InspectorTest.dumpSelectedElementStyles(true);
+
+        var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("font-weight");
+        treeItem.applyStyleText("font-weight: normal", true, false);
+        InspectorTest.waitForStyles("container", step2);
+    }
+
+    function step2()
+    {
+        InspectorTest.addResult("After changing property");
+        InspectorTest.dumpSelectedElementStyles(true);
+
+        WebInspector.domAgent.undo();
+        InspectorTest.waitForStyles("container", step3);
+    }
+
+    function step3()
+    {
+        InspectorTest.addResult("After undo");
+        InspectorTest.dumpSelectedElementStyles(true);
+
+        var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("font-weight");
+        treeItem.applyStyleText("font-weight: normal", true, false);
+        InspectorTest.waitForStyles("container", step4);
+    }
+
+    function step4()
+    {
+        InspectorTest.addResult("After perform");
+        InspectorTest.dumpSelectedElementStyles(true);
+        InspectorTest.completeTest();
+    }
+}
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Tests that perform-undo-perform of the mergeable action does not crash.
+</p>
+
+<div id="container" class="container"></div>
+<div id="other" class="container"></div>
+
+</body>
+</html>
index 50ab684..be7867b 100644 (file)
@@ -1,3 +1,16 @@
+2012-02-17  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: check undo-redo boundaries based on current action index, not history size.
+        https://bugs.webkit.org/show_bug.cgi?id=78895
+
+        Reviewed by Vsevolod Vlasov.
+
+        Tests: inspector/elements/perform-undo-undo.html
+               inspector/styles/perform-undo-perform-of-mergable-action.html
+
+        * inspector/InspectorHistory.cpp:
+        (WebCore::InspectorHistory::perform):
+
 2012-02-17  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Unreviewed, rolling out r108071.
index 393cba5..0511791 100644 (file)
@@ -90,7 +90,7 @@ bool InspectorHistory::perform(PassOwnPtr<Action> action, ExceptionCode& ec)
     if (!action->perform(ec))
         return false;
 
-    if (!m_history.isEmpty() && !action->mergeId().isEmpty() && action->mergeId() == m_history[m_afterLastActionIndex - 1]->mergeId())
+    if (!action->mergeId().isEmpty() && m_afterLastActionIndex > 0 && action->mergeId() == m_history[m_afterLastActionIndex - 1]->mergeId())
         m_history[m_afterLastActionIndex - 1]->merge(action);
     else {
         m_history.resize(m_afterLastActionIndex);