Web Inspector: DOMDebugger: "Attribute Modified" breakpoints pause after the modifica...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 17:27:40 +0000 (17:27 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 17:27:40 +0000 (17:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196556
<rdar://problem/49570681>

Reviewed by Timothy Hatcher.

Source/WebCore:

Test: inspector/dom-debugger/attribute-modified-style.html

* css/PropertySetCSSStyleDeclaration.h:
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::StyleAttributeMutationScope::~StyleAttributeMutationScope):
(WebCore::InlineCSSStyleDeclaration::willMutate): Added.

* dom/StyledElement.cpp:
(WebCore::StyledElement::styleAttributeChanged):
(WebCore::StyledElement::inlineStyleChanged):

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::willInvalidateStyleAttr): Added.
(WebCore::InspectorInstrumentation::didInvalidateStyleAttr):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willInvalidateStyleAttrImpl): Added.
(WebCore::InspectorInstrumentation::didInvalidateStyleAttrImpl):

* inspector/agents/InspectorDOMAgent.h:
* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::didInvalidateStyleAttr):

* inspector/agents/InspectorDOMDebuggerAgent.h:
* inspector/agents/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::willInvalidateStyleAttr): Added.
(WebCore::InspectorDOMDebuggerAgent::didInvalidateStyleAttr): Deleted.

LayoutTests:

* inspector/dom-debugger/attribute-modified-style.html: Added.
* inspector/dom-debugger/attribute-modified-style-expected.txt: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/dom-debugger/attribute-modified-style-expected.txt [new file with mode: 0644]
LayoutTests/inspector/dom-debugger/attribute-modified-style.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/css/PropertySetCSSStyleDeclaration.h
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMAgent.h
Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h

index d39dc93..91b0a72 100644 (file)
@@ -1,5 +1,16 @@
 2019-04-15  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: DOMDebugger: "Attribute Modified" breakpoints pause after the modification occurs for the style attribute
+        https://bugs.webkit.org/show_bug.cgi?id=196556
+        <rdar://problem/49570681>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/dom-debugger/attribute-modified-style.html: Added.
+        * inspector/dom-debugger/attribute-modified-style-expected.txt: Added.
+
+2019-04-15  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Elements: event listener change events should only be fired for the selected node and it's ancestors
         https://bugs.webkit.org/show_bug.cgi?id=196887
         <rdar://problem/49870627>
diff --git a/LayoutTests/inspector/dom-debugger/attribute-modified-style-expected.txt b/LayoutTests/inspector/dom-debugger/attribute-modified-style-expected.txt
new file mode 100644 (file)
index 0000000..4397546
--- /dev/null
@@ -0,0 +1,61 @@
+Tests functionality of attribute modified DOM breakpoints when modifying the inline style attribute.
+
+Adding attribute modified breakpoint to #test...
+PASS: Added attribute modified breakpoint to #test.
+
+== Running test suite: DOMBreakpoints.AttributeModified.Style
+-- Running test case: DOMBreakpoints.AttributeModified.Style.Add
+Getting 'display'...
+PASS: 'display' should have the value ''.
+Setting 'display: none;'...
+PASS: Paused.
+Getting 'display'...
+PASS: 'display' should have the value ''.
+PASS: Resumed.
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+
+-- Running test case: DOMBreakpoints.AttributeModified.Style.ReplaceSame
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+Setting 'display: none;'...
+PASS: Paused.
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+PASS: Resumed.
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+
+-- Running test case: DOMBreakpoints.AttributeModified.Style.ReplaceDifferent
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+Setting 'display: block;'...
+PASS: Paused.
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+PASS: Resumed.
+Getting 'display'...
+PASS: 'display' should have the value 'block'.
+
+-- Running test case: DOMBreakpoints.AttributeModified.Style.Remove
+Getting 'display'...
+PASS: 'display' should have the value 'block'.
+Removing 'display'...
+PASS: Paused.
+Getting 'display'...
+PASS: 'display' should have the value 'block'.
+PASS: Resumed.
+Getting 'display'...
+PASS: 'display' should have the value ''.
+
+-- Running test case: DOMBreakpoints.AttributeModified.Style.Text
+Getting 'display'...
+PASS: 'display' should have the value ''.
+Setting style text to ''...
+PASS: Paused.
+Getting 'display'...
+PASS: 'display' should have the value ''.
+PASS: Resumed.
+Getting 'display'...
+PASS: 'display' should have the value 'none'.
+
diff --git a/LayoutTests/inspector/dom-debugger/attribute-modified-style.html b/LayoutTests/inspector/dom-debugger/attribute-modified-style.html
new file mode 100644 (file)
index 0000000..d37d58a
--- /dev/null
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script src="../debugger/resources/log-active-stack-trace.js"></script>
+<script>
+
+function getProperty(name) {
+    let node = document.getElementById("test");
+    return node.style.getPropertyValue(name);
+}
+
+function setProperty(name, value) {
+    let node = document.getElementById("test");
+    if (value)
+        node.style.setProperty(name, value);
+    else
+        node.style.removeProperty(name);
+}
+
+function test()
+{
+    InspectorTest.debug();
+
+    let suite = InspectorTest.createAsyncSuite("DOMBreakpoints.AttributeModified.Style");
+
+    async function checkPropertyValue(name, expectedValue) {
+        InspectorTest.log(`Getting '${name}'...`);
+        let value = await InspectorTest.evaluateInPage(`getProperty("${name}")`);
+        InspectorTest.expectEqual(value, expectedValue, `'${name}' should have the value '${expectedValue}'.`);
+    }
+
+    function addTestCase({name, propertyName, propertyValueBefore, propertyValueAfter}) {
+        suite.addTestCase({
+            name,
+            async test() {
+                await checkPropertyValue(propertyName, propertyValueBefore);
+
+                let pausedPromise = WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Paused);
+
+                if (propertyValueAfter)
+                    InspectorTest.log(`Setting '${propertyName}: ${propertyValueAfter};'...`);
+                else
+                    InspectorTest.log(`Removing '${propertyName}'...`);
+                let evaluatePromise = InspectorTest.evaluateInPage(`setProperty("${propertyName}", "${propertyValueAfter}")`);
+
+                await pausedPromise;
+                InspectorTest.pass("Paused.");
+
+                await checkPropertyValue(propertyName, propertyValueBefore);
+
+                await WI.debuggerManager.resume();
+                InspectorTest.pass("Resumed.");
+
+                await evaluatePromise;
+
+                await checkPropertyValue(propertyName, propertyValueAfter);
+            },
+        });
+    }
+
+    addTestCase({
+        name: "DOMBreakpoints.AttributeModified.Style.Add",
+        propertyName: "display",
+        propertyValueBefore: "",
+        propertyValueAfter: "none",
+    });
+    addTestCase({
+        name: "DOMBreakpoints.AttributeModified.Style.ReplaceSame",
+        propertyName: "display",
+        propertyValueBefore: "none",
+        propertyValueAfter: "none",
+    });
+    addTestCase({
+        name: "DOMBreakpoints.AttributeModified.Style.ReplaceDifferent",
+        propertyName: "display",
+        propertyValueBefore: "none",
+        propertyValueAfter: "block",
+    });
+    addTestCase({
+        name: "DOMBreakpoints.AttributeModified.Style.Remove",
+        propertyName: "display",
+        propertyValueBefore: "block",
+        propertyValueAfter: "",
+    });
+
+    suite.addTestCase({
+        name: "DOMBreakpoints.AttributeModified.Style.Text",
+        async test() {
+            await checkPropertyValue("display", "");
+
+            let pausedPromise = WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Paused);
+
+            InspectorTest.log(`Setting style text to ''...`);
+            let evaluatePromise = InspectorTest.evaluateInPage(`document.getElementById("test").style.cssText = "display: none;";`);
+
+            await pausedPromise;
+            InspectorTest.pass("Paused.");
+
+            await checkPropertyValue("display", "");
+
+            await WI.debuggerManager.resume();
+            InspectorTest.pass("Resumed.");
+
+            await evaluatePromise;
+
+            await checkPropertyValue("display", "none");
+        },
+    });
+
+    WI.domManager.requestDocument((documentNode) => {
+        if (!documentNode) {
+            InspectorTest.fail("Missing document node");
+            InspectorTest.completeTest();
+            return;
+        }
+
+        WI.domManager.querySelector(documentNode.id, "#test", async (nodeId) => {
+            let testNode = WI.domManager.nodeForId(nodeId);
+            if (!testNode) {
+                InspectorTest.fail("Missing #test node");
+                InspectorTest.completeTest();
+                return;
+            }
+
+            let promise = WI.domDebuggerManager.awaitEvent(WI.DOMDebuggerManager.Event.DOMBreakpointAdded)
+            .then((event) => {
+                InspectorTest.pass("Added attribute modified breakpoint to #test.");
+            });
+
+            InspectorTest.log("Adding attribute modified breakpoint to #test...");
+            WI.domDebuggerManager.addDOMBreakpoint(new WI.DOMBreakpoint(testNode, WI.DOMBreakpoint.Type.AttributeModified));
+            await promise;
+
+            InspectorTest.assert(!WI.debuggerManager.paused, "Should not be paused.");
+
+            suite.runTestCasesAndFinish();
+        });
+    });
+}
+</script>
+</head>
+<body onload="runTest()">
+    <p>Tests functionality of attribute modified DOM breakpoints when modifying the inline style attribute.</p>
+    <div id="test"></div>
+</body>
+</html>
index 7dce4f6..9afcd3a 100644 (file)
@@ -1,5 +1,40 @@
 2019-04-15  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: DOMDebugger: "Attribute Modified" breakpoints pause after the modification occurs for the style attribute
+        https://bugs.webkit.org/show_bug.cgi?id=196556
+        <rdar://problem/49570681>
+
+        Reviewed by Timothy Hatcher.
+
+        Test: inspector/dom-debugger/attribute-modified-style.html
+
+        * css/PropertySetCSSStyleDeclaration.h:
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        (WebCore::StyleAttributeMutationScope::~StyleAttributeMutationScope):
+        (WebCore::InlineCSSStyleDeclaration::willMutate): Added.
+
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::styleAttributeChanged):
+        (WebCore::StyledElement::inlineStyleChanged):
+
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::willInvalidateStyleAttr): Added.
+        (WebCore::InspectorInstrumentation::didInvalidateStyleAttr):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willInvalidateStyleAttrImpl): Added.
+        (WebCore::InspectorInstrumentation::didInvalidateStyleAttrImpl):
+
+        * inspector/agents/InspectorDOMAgent.h:
+        * inspector/agents/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::didInvalidateStyleAttr):
+
+        * inspector/agents/InspectorDOMDebuggerAgent.h:
+        * inspector/agents/InspectorDOMDebuggerAgent.cpp:
+        (WebCore::InspectorDOMDebuggerAgent::willInvalidateStyleAttr): Added.
+        (WebCore::InspectorDOMDebuggerAgent::didInvalidateStyleAttr): Deleted.
+
+2019-04-15  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Elements: event listener change events should only be fired for the selected node and it's ancestors
         https://bugs.webkit.org/show_bug.cgi?id=196887
         <rdar://problem/49870627>
index 65d5ebe..ed1ff23 100644 (file)
@@ -104,8 +104,9 @@ public:
         PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
         s_currentDecl = nullptr;
         s_shouldNotifyInspector = false;
-        if (localCopyStyleDecl->parentElement())
-            InspectorInstrumentation::didInvalidateStyleAttr(localCopyStyleDecl->parentElement()->document(), *localCopyStyleDecl->parentElement());
+
+        if (auto* parentElement = localCopyStyleDecl->parentElement())
+            InspectorInstrumentation::didInvalidateStyleAttr(*parentElement);
     }
 
     void enqueueMutationRecord()
@@ -421,6 +422,13 @@ void StyleRuleCSSStyleDeclaration::reattach(MutableStyleProperties& propertySet)
     m_propertySet->ref();
 }
 
+bool InlineCSSStyleDeclaration::willMutate()
+{
+    if (m_parentElement)
+        InspectorInstrumentation::willInvalidateStyleAttr(*m_parentElement);
+    return true;
+}
+
 void InlineCSSStyleDeclaration::didMutate(MutationType type)
 {
     if (type == NoChanges)
index 59388ab..3d342c8 100644 (file)
@@ -134,6 +134,7 @@ private:
     StyledElement* parentElement() const final { return m_parentElement; }
     void clearParentElement() final { m_parentElement = nullptr; }
 
+    bool willMutate() final WARN_UNUSED_RETURN;
     void didMutate(MutationType) final;
     CSSParserContext cssParserContext() const final;
 
index 92a973a..80c81f8 100644 (file)
@@ -206,7 +206,7 @@ void StyledElement::styleAttributeChanged(const AtomicString& newStyleString, At
     elementData()->setStyleAttributeIsDirty(false);
 
     invalidateStyle();
-    InspectorInstrumentation::didInvalidateStyleAttr(document(), *this);
+    InspectorInstrumentation::didInvalidateStyleAttr(*this);
 }
 
 void StyledElement::invalidateStyleAttribute()
@@ -231,7 +231,7 @@ void StyledElement::invalidateStyleAttribute()
 void StyledElement::inlineStyleChanged()
 {
     invalidateStyleAttribute();
-    InspectorInstrumentation::didInvalidateStyleAttr(document(), *this);
+    InspectorInstrumentation::didInvalidateStyleAttr(*this);
 }
     
 bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, CSSValueID identifier, bool important)
index ba8fb42..3f472c5 100644 (file)
@@ -188,12 +188,16 @@ void InspectorInstrumentation::didRemoveDOMAttrImpl(InstrumentingAgents& instrum
         domAgent->didRemoveDOMAttr(element, name);
 }
 
-void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents& instrumentingAgents, Node& node)
+void InspectorInstrumentation::willInvalidateStyleAttrImpl(InstrumentingAgents& instrumentingAgents, Element& element)
 {
-    if (InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent())
-        domAgent->didInvalidateStyleAttr(node);
-    if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
-        domDebuggerAgent->didInvalidateStyleAttr(node);
+    if (auto* domDebuggerAgent = instrumentingAgents.inspectorDOMDebuggerAgent())
+        domDebuggerAgent->willInvalidateStyleAttr(element);
+}
+
+void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents& instrumentingAgents, Element& element)
+{
+    if (auto* domAgent = instrumentingAgents.inspectorDOMAgent())
+        domAgent->didInvalidateStyleAttr(element);
 }
 
 void InspectorInstrumentation::documentDetachedImpl(InstrumentingAgents& instrumentingAgents, Document& document)
index 1f17920..c86453f 100644 (file)
@@ -115,7 +115,8 @@ public:
     static void didModifyDOMAttr(Document&, Element&, const AtomicString& name, const AtomicString& value);
     static void didRemoveDOMAttr(Document&, Element&, const AtomicString& name);
     static void characterDataModified(Document&, CharacterData&);
-    static void didInvalidateStyleAttr(Document&, Node&);
+    static void willInvalidateStyleAttr(Element&);
+    static void didInvalidateStyleAttr(Element&);
     static void documentDetached(Document&);
     static void frameWindowDiscarded(Frame&, DOMWindow*);
     static void mediaQueryResultChanged(Document&);
@@ -308,7 +309,8 @@ private:
     static void didModifyDOMAttrImpl(InstrumentingAgents&, Element&, const AtomicString& name, const AtomicString& value);
     static void didRemoveDOMAttrImpl(InstrumentingAgents&, Element&, const AtomicString& name);
     static void characterDataModifiedImpl(InstrumentingAgents&, CharacterData&);
-    static void didInvalidateStyleAttrImpl(InstrumentingAgents&, Node&);
+    static void willInvalidateStyleAttrImpl(InstrumentingAgents&, Element&);
+    static void didInvalidateStyleAttrImpl(InstrumentingAgents&, Element&);
     static void documentDetachedImpl(InstrumentingAgents&, Document&);
     static void frameWindowDiscardedImpl(InstrumentingAgents&, DOMWindow*);
     static void mediaQueryResultChangedImpl(InstrumentingAgents&);
@@ -552,11 +554,18 @@ inline void InspectorInstrumentation::didRemoveDOMAttr(Document& document, Eleme
         didRemoveDOMAttrImpl(*instrumentingAgents, element, name);
 }
 
-inline void InspectorInstrumentation::didInvalidateStyleAttr(Document& document, Node& node)
+inline void InspectorInstrumentation::willInvalidateStyleAttr(Element& element)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
-        didInvalidateStyleAttrImpl(*instrumentingAgents, node);
+    if (auto* instrumentingAgents = instrumentingAgentsForDocument(element.document()))
+        willInvalidateStyleAttrImpl(*instrumentingAgents, element);
+}
+
+inline void InspectorInstrumentation::didInvalidateStyleAttr(Element& element)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    if (auto* instrumentingAgents = instrumentingAgentsForDocument(element.document()))
+        didInvalidateStyleAttrImpl(*instrumentingAgents, element);
 }
 
 inline void InspectorInstrumentation::documentDetached(Document& document)
index 27d960f..0121a7a 100644 (file)
@@ -2311,15 +2311,15 @@ void InspectorDOMAgent::characterDataModified(CharacterData& characterData)
     m_frontendDispatcher->characterDataModified(id, characterData.data());
 }
 
-void InspectorDOMAgent::didInvalidateStyleAttr(Node& node)
+void InspectorDOMAgent::didInvalidateStyleAttr(Element& element)
 {
-    int id = m_documentNodeToIdMap.get(&node);
+    int id = m_documentNodeToIdMap.get(&element);
     if (!id)
         return;
 
     if (!m_revalidateStyleAttrTask)
         m_revalidateStyleAttrTask = std::make_unique<RevalidateStyleAttributeTask>(this);
-    m_revalidateStyleAttrTask->scheduleFor(downcast<Element>(&node));
+    m_revalidateStyleAttrTask->scheduleFor(&element);
 }
 
 void InspectorDOMAgent::didPushShadowRoot(Element& host, ShadowRoot& root)
index 6a244c5..df23ced 100644 (file)
@@ -146,7 +146,7 @@ public:
     void didModifyDOMAttr(Element&, const AtomicString& name, const AtomicString& value);
     void didRemoveDOMAttr(Element&, const AtomicString& name);
     void characterDataModified(CharacterData&);
-    void didInvalidateStyleAttr(Node&);
+    void didInvalidateStyleAttr(Element&);
     void didPushShadowRoot(Element& host, ShadowRoot&);
     void willPopShadowRoot(Element& host, ShadowRoot&);
     void didChangeCustomElementState(Element&);
index 3f7d9c8..54475dd 100644 (file)
@@ -170,14 +170,14 @@ void InspectorDOMDebuggerAgent::removeEventBreakpoint(ErrorString& error, const
     m_eventBreakpoints.remove(std::make_pair(*breakpointType, eventName));
 }
 
-void InspectorDOMDebuggerAgent::didInvalidateStyleAttr(Node& node)
+void InspectorDOMDebuggerAgent::willInvalidateStyleAttr(Element& element)
 {
     if (!m_debuggerAgent->breakpointsActive())
         return;
 
-    if (hasBreakpoint(&node, AttributeModified)) {
+    if (hasBreakpoint(&element, AttributeModified)) {
         Ref<JSON::Object> eventData = JSON::Object::create();
-        descriptionForDOMEvent(node, AttributeModified, false, eventData.get());
+        descriptionForDOMEvent(element, AttributeModified, false, eventData.get());
         m_debuggerAgent->breakProgram(Inspector::DebuggerFrontendDispatcher::Reason::DOM, WTFMove(eventData));
     }
 }
index a365939..dda730e 100644 (file)
@@ -69,7 +69,7 @@ public:
 
     // InspectorInstrumentation
     void willInsertDOMNode(Node& parent);
-    void didInvalidateStyleAttr(Node&);
+    void willInvalidateStyleAttr(Element&);
     void didInsertDOMNode(Node&);
     void willRemoveDOMNode(Node&);
     void didRemoveDOMNode(Node&);