Title: [187352] trunk
Revision
187352
Author
drou...@apple.com
Date
2015-07-24 11:48:17 -0700 (Fri, 24 Jul 2015)

Log Message

Web Inspector: Editing non-inspector-stylesheet rule selectors fails after the first change
https://bugs.webkit.org/show_bug.cgi?id=147229

Reviewed by Timothy Hatcher.

Source/WebCore:

Test: inspector/css/modify-rule-selector.html

* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::setRuleSelector):
Now checks to see if the stylesheet is not mutated before making the change to the
rule's selector, and if so mark it as not mutated to allow future edits.

LayoutTests:

* inspector/css/modify-rule-selector-expected.txt: Added.
* inspector/css/modify-rule-selector.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (187351 => 187352)


--- trunk/LayoutTests/ChangeLog	2015-07-24 18:40:58 UTC (rev 187351)
+++ trunk/LayoutTests/ChangeLog	2015-07-24 18:48:17 UTC (rev 187352)
@@ -1,3 +1,13 @@
+2015-07-24  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: Editing non-inspector-stylesheet rule selectors fails after the first change
+        https://bugs.webkit.org/show_bug.cgi?id=147229
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/css/modify-rule-selector-expected.txt: Added.
+        * inspector/css/modify-rule-selector.html: Added.
+
 2015-07-24  Saam barati  <saambara...@gmail.com>
 
         [ES6] Add support for default parameters

Added: trunk/LayoutTests/inspector/css/modify-rule-selector-expected.txt (0 => 187352)


--- trunk/LayoutTests/inspector/css/modify-rule-selector-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/modify-rule-selector-expected.txt	2015-07-24 18:48:17 UTC (rev 187352)
@@ -0,0 +1,9 @@
+Testing that selectors are able to be modified more than once.
+
+ 
+Selector before mutation: .foo
+Selector after mutation: span.foo
+
+Selector before mutation: span.foo
+Selector after mutation: body > .foo
+

Added: trunk/LayoutTests/inspector/css/modify-rule-selector.html (0 => 187352)


--- trunk/LayoutTests/inspector/css/modify-rule-selector.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/css/modify-rule-selector.html	2015-07-24 18:48:17 UTC (rev 187352)
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+    .foo {}
+</style>
+<script type="text/_javascript_" src=""
+<script>
+function test() {
+    var nodeStyles;
+    var selectors = ["span.foo", "body > .foo"];
+    var index = 0;
+
+    function modifyRuleSelector(selector) {
+        if (!nodeStyles.matchedRules.length) {
+            InspectorTest.log("ERROR: missing matched rules");
+            InspectorTest.completeTest();
+            return;
+        }
+
+        var rule = nodeStyles.matchedRules[0];
+        CSSAgent.setRuleSelector(rule.id, selector, function(error, payload) {
+            if (error) {
+                InspectorTest.log("ERROR: " + error);
+                InspectorTest.completeTest();
+                return;
+            }
+
+            var newSelector = payload.selectorList.text;
+            InspectorTest.log("\nSelector before mutation: " + rule.selectorText);
+            InspectorTest.log("Selector after mutation: " + newSelector);
+            InspectorTest.assert(newSelector === selector, "FAIL: Selector " + newSelector + " should be updated to " + selector + ".");
+
+            nodeStyles.refresh();
+        });
+    }
+
+    // Every time the nodeStyles refreshes, attempt to change the selector
+    // of the first rule to the next selector in the list.
+    function onStylesRefreshed()
+    {
+        if (index >= selectors.length) {
+            InspectorTest.completeTest();
+            return;
+        }
+
+        modifyRuleSelector(selectors[index]);
+        ++index;
+    }
+
+    WebInspector.domTreeManager.requestDocument(function(documentNode) {
+        if (!documentNode) {
+            InspectorTest.log("ERROR: document not found.");
+            InspectorTest.completeTest();
+            return;
+        }
+
+        WebInspector.domTreeManager.querySelector(documentNode.id, ".foo", function(contentNodeId) {
+            if (!contentNodeId) {
+                InspectorTest.log("ERROR: DOM node not found.");
+                InspectorTest.completeTest();
+                return;
+            }
+
+            var domNode = WebInspector.domTreeManager.nodeForId(contentNodeId);
+            nodeStyles = WebInspector.cssStyleManager.stylesForNode(domNode);
+
+            nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, onStylesRefreshed, this);
+            if (!nodeStyles.needsRefresh)
+                onStylesRefreshed();
+        });
+    });
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Testing that selectors are able to be modified more than once.</p>
+
+    <span class="foo"></span>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (187351 => 187352)


--- trunk/Source/WebCore/ChangeLog	2015-07-24 18:40:58 UTC (rev 187351)
+++ trunk/Source/WebCore/ChangeLog	2015-07-24 18:48:17 UTC (rev 187352)
@@ -1,3 +1,17 @@
+2015-07-24  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: Editing non-inspector-stylesheet rule selectors fails after the first change
+        https://bugs.webkit.org/show_bug.cgi?id=147229
+
+        Reviewed by Timothy Hatcher.
+
+        Test: inspector/css/modify-rule-selector.html
+
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyleSheet::setRuleSelector):
+        Now checks to see if the stylesheet is not mutated before making the change to the
+        rule's selector, and if so mark it as not mutated to allow future edits.
+
 2015-07-24  Joseph Pecoraro  <pecor...@apple.com>
 
         CSS "content" property is missing in getComputedStyles

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (187351 => 187352)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2015-07-24 18:40:58 UTC (rev 187351)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2015-07-24 18:48:17 UTC (rev 187352)
@@ -652,6 +652,10 @@
         return false;
     }
 
+    // If the stylesheet is already mutated at this point, that must mean that our data has been modified
+    // elsewhere. This should never happen as ensureParsedDataReady would return false in that case.
+    ASSERT(!styleSheetMutated());
+
     rule->setSelectorText(selector);
     RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(&rule->style());
     if (!sourceData) {
@@ -662,6 +666,7 @@
     String sheetText = m_parsedStyleSheet->text();
     sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderRange.length(), selector);
     m_parsedStyleSheet->setText(sheetText);
+    m_pageStyleSheet->clearHadRulesMutation();
     fireStyleSheetChanged();
     return true;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to