Web Inspector: [Crash] Clear cached stylesheet rules in InspectorStyleSheet::deleteRule()
authorapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2012 15:01:31 +0000 (15:01 +0000)
committerapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2012 15:01:31 +0000 (15:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=104806

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Cached rules (m_flatRules) should get cleared whenever a rule is deleted.

Test: inspector/styles/undo-add-rule-crash.html

* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::deleteRule):

LayoutTests:

* inspector/styles/undo-add-rule-crash-expected.txt: Added.
* inspector/styles/undo-add-rule-crash.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/styles/undo-add-rule-crash-expected.txt [new file with mode: 0644]
LayoutTests/inspector/styles/undo-add-rule-crash.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorStyleSheet.cpp

index 98fddf5..1065afa 100644 (file)
@@ -1,3 +1,13 @@
+2012-12-12  Alexander Pavlov  <apavlov@chromium.org>
+
+        Web Inspector: [Crash] Clear cached stylesheet rules in InspectorStyleSheet::deleteRule()
+        https://bugs.webkit.org/show_bug.cgi?id=104806
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/styles/undo-add-rule-crash-expected.txt: Added.
+        * inspector/styles/undo-add-rule-crash.html: Added.
+
 2012-12-12  Stephen White  <senorblanco@chromium.org>
 
         Unreviewed, rolling out r136975.
diff --git a/LayoutTests/inspector/styles/undo-add-rule-crash-expected.txt b/LayoutTests/inspector/styles/undo-add-rule-crash-expected.txt
new file mode 100644 (file)
index 0000000..cbe08c3
--- /dev/null
@@ -0,0 +1,4 @@
+Tests that the inspected page does not crash after undoing a new rule addition. Bug 104806
+The test has passed (no crash).
+
+
diff --git a/LayoutTests/inspector/styles/undo-add-rule-crash.html b/LayoutTests/inspector/styles/undo-add-rule-crash.html
new file mode 100644 (file)
index 0000000..5ff8a6a
--- /dev/null
@@ -0,0 +1,47 @@
+<html>
+<head>
+<script src=../../http/tests/inspector/inspector-test.js></script>
+<script src=../../http/tests/inspector/elements-test.js></script>
+<script>
+
+function test()
+{
+    InspectorTest.selectNodeAndWaitForStyles("inspected", step1);
+
+    function step1()
+    {
+        addNewRuleAndSelectNode("other", step2);
+    }
+
+    function step2()
+    {
+        WebInspector.domAgent.undo();
+        InspectorTest.waitForStyles("other", step3);
+    }
+
+    function step3()
+    {
+        InspectorTest.completeTest();
+    }
+
+    function addNewRuleAndSelectNode(nodeId, next)
+    {
+        document.getElementById("add-style-button-test-id").click();
+        var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];
+        InspectorTest.selectNodeAndWaitForStyles(nodeId, next);
+    }
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+Tests that the inspected page does not crash after undoing a new rule addition. <a href="https://bugs.webkit.org/show_bug.cgi?id=104806">Bug 104806</a>
+
+<p>The test has passed (no crash).</p>
+<div id="inspected"><div id="other" /></div>
+<style>
+@-webkit-keyframes cfpulse1 { 0% { opacity: 0.1;  } }
+.c1 { -webkit-animation-name: cfpulse1;  }
+</style>
+</html>
index 6ef9dbe..0f16f6c 100644 (file)
@@ -1,3 +1,17 @@
+2012-12-12  Alexander Pavlov  <apavlov@chromium.org>
+
+        Web Inspector: [Crash] Clear cached stylesheet rules in InspectorStyleSheet::deleteRule()
+        https://bugs.webkit.org/show_bug.cgi?id=104806
+
+        Reviewed by Vsevolod Vlasov.
+
+        Cached rules (m_flatRules) should get cleared whenever a rule is deleted.
+
+        Test: inspector/styles/undo-add-rule-crash.html
+
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyleSheet::deleteRule):
+
 2012-12-12  Stephen White  <senorblanco@chromium.org>
 
         Unreviewed, rolling out r136975.
index f67311e..ab182c8 100644 (file)
@@ -898,7 +898,7 @@ bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionCode& ec
 
     String sheetText = m_parsedStyleSheet->text();
     sheetText.remove(sourceData->ruleHeaderRange.start, sourceData->ruleBodyRange.end - sourceData->ruleHeaderRange.start + 1);
-    m_parsedStyleSheet->setText(sheetText);
+    setText(sheetText);
     fireStyleSheetChanged();
     return true;
 }