Web Inspector: Editing non-inspector-stylesheet rule selectors fails after the first...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jul 2015 18:48:17 +0000 (18:48 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jul 2015 18:48:17 +0000 (18:48 +0000)
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.

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

LayoutTests/ChangeLog
LayoutTests/inspector/css/modify-rule-selector-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/modify-rule-selector.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorStyleSheet.cpp

index 5d995a8..efdbf0b 100644 (file)
@@ -1,3 +1,13 @@
+2015-07-24  Devin Rousso  <drousso@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  <saambarati1@gmail.com>
 
         [ES6] Add support for default parameters
diff --git a/LayoutTests/inspector/css/modify-rule-selector-expected.txt b/LayoutTests/inspector/css/modify-rule-selector-expected.txt
new file mode 100644 (file)
index 0000000..9a4a427
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/inspector/css/modify-rule-selector.html b/LayoutTests/inspector/css/modify-rule-selector.html
new file mode 100644 (file)
index 0000000..a6aab47
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+    .foo {}
+</style>
+<script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
+<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>
index e432f2f..070dadd 100644 (file)
@@ -1,3 +1,17 @@
+2015-07-24  Devin Rousso  <drousso@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  <pecoraro@apple.com>
 
         CSS "content" property is missing in getComputedStyles
index 06ec1b6..49d921a 100644 (file)
@@ -652,6 +652,10 @@ bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String
         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 @@ bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String
     String sheetText = m_parsedStyleSheet->text();
     sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderRange.length(), selector);
     m_parsedStyleSheet->setText(sheetText);
+    m_pageStyleSheet->clearHadRulesMutation();
     fireStyleSheetChanged();
     return true;
 }