Web Inspector: Second call to setAttributeNS creates non-prefixed attribute
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2019 08:53:39 +0000 (08:53 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Jul 2019 08:53:39 +0000 (08:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200230
<rdar://problem/53712672>

Reviewed by Joseph Pecoraro.

Source/WebCore:

Original patch by Chris Dumez <cdumez@apple.com>.

Test: inspector/dom/attributeModified.html

* dom/Element.cpp:
(WebCore::Element::didAddAttribute):
(WebCore::Element::didModifyAttribute):
(WebCore::Element::didRemoveAttribute):
Use the fully qualified name, not just the local name, when notifying the inspector frontend
about changes to attributes.

LayoutTests:

* inspector/dom/attributeModified.html: Added.
* inspector/dom/attributeModified-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/dom/attributeModified-expected.txt [new file with mode: 0644]
LayoutTests/inspector/dom/attributeModified.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp

index b54de7a..1e04e59 100644 (file)
@@ -1,3 +1,14 @@
+2019-07-31  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Second call to setAttributeNS creates non-prefixed attribute
+        https://bugs.webkit.org/show_bug.cgi?id=200230
+        <rdar://problem/53712672>
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/dom/attributeModified.html: Added.
+        * inspector/dom/attributeModified-expected.txt: Added.
+
 2019-07-31  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Datalist element support for TextFieldInputType
diff --git a/LayoutTests/inspector/dom/attributeModified-expected.txt b/LayoutTests/inspector/dom/attributeModified-expected.txt
new file mode 100644 (file)
index 0000000..e58a739
--- /dev/null
@@ -0,0 +1,33 @@
+Tests for the DOM.attributeModified event.
+
+
+== Running test suite: DOM.attributeModified
+-- Running test case: DOM.attributeModified.WithNamespace
+Creating test node...
+{
+  "id": "with-namespace",
+  "attribute:existing": "42"
+}
+
+Adding attribute with namespace...
+{
+  "id": "with-namespace",
+  "attribute:existing": "42",
+  "attribute:new": "1"
+}
+
+Replacing attribute with namespace...
+{
+  "id": "with-namespace",
+  "attribute:existing": "42",
+  "attribute:new": "2"
+}
+
+Replacing attribute without namespace...
+{
+  "id": "with-namespace",
+  "attribute:existing": "42",
+  "attribute:new": "3"
+}
+
+
diff --git a/LayoutTests/inspector/dom/attributeModified.html b/LayoutTests/inspector/dom/attributeModified.html
new file mode 100644 (file)
index 0000000..54d2d1e
--- /dev/null
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+
+function createTestNode(id) {
+    let node = document.body.appendChild(document.createElement("div"));
+    node.id = id;
+    node.setAttributeNS("http://example.com", "attribute:existing", 42);
+}
+
+function test() {
+    let documentNode = null;
+
+    let suite = InspectorTest.createAsyncSuite("DOM.attributeModified");
+
+    suite.addTestCase({
+        name: "DOM.attributeModified.WithNamespace",
+        description: "Check that the attributeModified event sends the full attribute name, including the namespace.",
+        async test() {
+            const id = "with-namespace";
+
+            InspectorTest.log("Creating test node...");
+            await InspectorTest.evaluateInPage(`createTestNode("${id}")`);
+            let testNodeId = await WI.domManager.querySelector(documentNode.id, "#" + id);
+            let testNode = WI.domManager.nodeForId(testNodeId);
+            InspectorTest.assert(testNode, "Missing test node for id " + testNodeId);
+
+            function logAttributes() {
+                let attributes = {};
+                for (let attribute of testNode.attributes())
+                    attributes[attribute.name] = attribute.value;
+                InspectorTest.json(attributes);
+                InspectorTest.log("");
+            }
+
+            logAttributes();
+
+            InspectorTest.log("Adding attribute with namespace...");
+            await Promise.all([
+                testNode.awaitEvent(WI.DOMNode.Event.AttributeModified),
+                InspectorTest.evaluateInPage(`document.getElementById("${id}").setAttributeNS("http://example.com", "attribute:new", 1)`)
+            ]);
+
+            logAttributes();
+
+            InspectorTest.log("Replacing attribute with namespace...");
+            await Promise.all([
+                testNode.awaitEvent(WI.DOMNode.Event.AttributeModified),
+                InspectorTest.evaluateInPage(`document.getElementById("${id}").setAttributeNS("http://example.com", "attribute:new", 2)`)
+            ]);
+
+            logAttributes();
+
+            InspectorTest.log("Replacing attribute without namespace...");
+            await Promise.all([
+                testNode.awaitEvent(WI.DOMNode.Event.AttributeModified),
+                InspectorTest.evaluateInPage(`document.getElementById("${id}").setAttribute("attribute:new", "3")`)
+            ]);
+
+            logAttributes();
+        },
+    });
+
+    WI.domManager.requestDocument((root) => {
+        documentNode = root;
+
+        suite.runTestCasesAndFinish();
+    });
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests for the DOM.attributeModified event.</p>
+</body>
+</html>
index b39bb31..a71e403 100644 (file)
@@ -1,3 +1,22 @@
+2019-07-31  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Second call to setAttributeNS creates non-prefixed attribute
+        https://bugs.webkit.org/show_bug.cgi?id=200230
+        <rdar://problem/53712672>
+
+        Reviewed by Joseph Pecoraro.
+
+        Original patch by Chris Dumez <cdumez@apple.com>.
+
+        Test: inspector/dom/attributeModified.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::didAddAttribute):
+        (WebCore::Element::didModifyAttribute):
+        (WebCore::Element::didRemoveAttribute):
+        Use the fully qualified name, not just the local name, when notifying the inspector frontend
+        about changes to attributes.
+
 2019-07-31  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Datalist element support for TextFieldInputType
index defaf94..7d8a931 100644 (file)
@@ -3852,21 +3852,21 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomString& o
 void Element::didAddAttribute(const QualifiedName& name, const AtomString& value)
 {
     attributeChanged(name, nullAtom(), value);
-    InspectorInstrumentation::didModifyDOMAttr(document(), *this, name.localName(), value);
+    InspectorInstrumentation::didModifyDOMAttr(document(), *this, name.toString(), value);
     dispatchSubtreeModifiedEvent();
 }
 
 void Element::didModifyAttribute(const QualifiedName& name, const AtomString& oldValue, const AtomString& newValue)
 {
     attributeChanged(name, oldValue, newValue);
-    InspectorInstrumentation::didModifyDOMAttr(document(), *this, name.localName(), newValue);
+    InspectorInstrumentation::didModifyDOMAttr(document(), *this, name.toString(), newValue);
     // Do not dispatch a DOMSubtreeModified event here; see bug 81141.
 }
 
 void Element::didRemoveAttribute(const QualifiedName& name, const AtomString& oldValue)
 {
     attributeChanged(name, oldValue, nullAtom());
-    InspectorInstrumentation::didRemoveDOMAttr(document(), *this, name.localName());
+    InspectorInstrumentation::didRemoveDOMAttr(document(), *this, name.toString());
     dispatchSubtreeModifiedEvent();
 }