Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: third_party/WebKit/Source/core/dom/DocumentTest.cpp

Issue 2641803003: Introduce SynchronousMutationObserver::didChangeAttribute() (Closed)
Patch Set: 2017-01-20T14:34:58 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/Element.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/DocumentTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/DocumentTest.cpp b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
index d9e2f2fa11a05e89f2ccce87903289a10a8db15c..df592898ecdc892382732b589870bf50156a047e 100644
--- a/third_party/WebKit/Source/core/dom/DocumentTest.cpp
+++ b/third_party/WebKit/Source/core/dom/DocumentTest.cpp
@@ -123,6 +123,10 @@ class TestSynchronousMutationObserver
return m_contextDestroyedCalledCounter;
}
+ const HeapVector<Member<const Element>>& attributeChangedElements() const {
+ return m_attributeChangedElements;
+ }
+
const HeapVector<Member<const ContainerNode>>& childrenChangedNodes() const {
return m_childrenChangedNodes;
}
@@ -158,6 +162,7 @@ class TestSynchronousMutationObserver
private:
// Implement |SynchronousMutationObserver| member functions.
void contextDestroyed(Document*) final;
+ void didChangeAttribute(const Element&) final;
void didChangeChildren(const ContainerNode&) final;
void didMergeTextNodes(const Text&, const NodeWithIndex&, unsigned) final;
void didMoveTreeToNewDocument(const Node& root) final;
@@ -170,6 +175,7 @@ class TestSynchronousMutationObserver
void nodeWillBeRemoved(Node&) final;
int m_contextDestroyedCalledCounter = 0;
+ HeapVector<Member<const Element>> m_attributeChangedElements;
HeapVector<Member<const ContainerNode>> m_childrenChangedNodes;
HeapVector<Member<MergeTextNodesRecord>> m_mergeTextNodesRecords;
HeapVector<Member<const Node>> m_moveTreeToNewDocumentNodes;
@@ -190,6 +196,11 @@ void TestSynchronousMutationObserver::contextDestroyed(Document*) {
++m_contextDestroyedCalledCounter;
}
+void TestSynchronousMutationObserver::didChangeAttribute(
+ const Element& element) {
+ m_attributeChangedElements.push_back(&element);
+}
+
void TestSynchronousMutationObserver::didChangeChildren(
const ContainerNode& container) {
m_childrenChangedNodes.push_back(&container);
@@ -231,6 +242,7 @@ void TestSynchronousMutationObserver::nodeWillBeRemoved(Node& node) {
}
DEFINE_TRACE(TestSynchronousMutationObserver) {
+ visitor->trace(m_attributeChangedElements);
visitor->trace(m_childrenChangedNodes);
visitor->trace(m_mergeTextNodesRecords);
visitor->trace(m_moveTreeToNewDocumentNodes);
@@ -505,6 +517,24 @@ TEST_F(DocumentTest, SynchronousMutationNotifier) {
EXPECT_EQ(1, observer.countContextDestroyedCalled());
}
+TEST_F(DocumentTest, SynchronousMutationNotifierChangeAttribute) {
+ auto& observer = *new TestSynchronousMutationObserver(document());
+ Element* divNode = document().createElement("div");
+ document().body()->appendChild(divNode);
+ divNode->setAttribute(HTMLNames::classAttr, "foo");
+
+ ASSERT_EQ(1u, observer.attributeChangedElements().size());
+ EXPECT_EQ(divNode, observer.attributeChangedElements()[0]);
+
+ divNode->setAttribute(HTMLNames::classAttr, "bar");
+ ASSERT_EQ(2u, observer.attributeChangedElements().size());
+ EXPECT_EQ(divNode, observer.attributeChangedElements()[1]);
+
+ divNode->removeAttribute(HTMLNames::classAttr);
+ ASSERT_EQ(3u, observer.attributeChangedElements().size());
+ EXPECT_EQ(divNode, observer.attributeChangedElements()[2]);
+}
+
TEST_F(DocumentTest, SynchronousMutationNotifieAppendChild) {
auto& observer = *new TestSynchronousMutationObserver(document());
document().body()->appendChild(document().createTextNode("a123456789"));
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698