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

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementReactionStackTest.cpp

Issue 2027513002: Add a stack of queues of elements with reaction queues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ce-element-queue
Patch Set: Rebase. Created 4 years, 7 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
Index: third_party/WebKit/Source/core/dom/custom/CustomElementReactionStackTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStackTest.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStackTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8290dbc9f07624b8917514cddc3787a229eb24ca
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStackTest.cpp
@@ -0,0 +1,114 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/custom/CustomElementReactionStack.h"
+
+#include "core/dom/custom/CustomElementReaction.h"
+#include "core/dom/custom/CustomElementReactionTestHelpers.h"
+#include "core/dom/custom/CustomElementTestHelpers.h"
+#include "core/html/HTMLDocument.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/text/AtomicString.h"
+#include <initializer_list>
+#include <vector>
+
+namespace blink {
+
+TEST(CustomElementReactionStackTest, one)
+{
+ std::vector<char> log;
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)}));
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>({'a'}))
+ << "popping the reaction stack should run reactions";
+}
+
+TEST(CustomElementReactionStackTest, multipleElements)
+{
+ std::vector<char> log;
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)}));
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('b', log)}));
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>({'a', 'b'}))
+ << "reactions should run in the order the elements queued";
+}
+
+TEST(CustomElementReactionStackTest, popTopEmpty)
+{
+ std::vector<char> log;
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)}));
+ stack->push();
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>())
+ << "popping the empty top-of-stack should not run any reactions";
+}
+
+TEST(CustomElementReactionStackTest, popTop)
+{
+ std::vector<char> log;
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)}));
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('b', log)}));
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>({'b'}))
+ << "popping the top-of-stack should only run top-of-stack reactions";
+}
+
+TEST(CustomElementReactionStackTest, requeueingDoesNotReorderElements)
+{
+ std::vector<char> log;
+
+ Element* element = CreateElement("a");
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(element, new TestReaction({new Log('a', log)}));
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('z', log)}));
+ stack->enqueue(element, new TestReaction({new Log('b', log)}));
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>({'a', 'b', 'z'}))
+ << "reactions should run together in the order elements were queued";
+}
+
+TEST(CustomElementReactionStackTest, oneReactionQueuePerElement)
+{
+ std::vector<char> log;
+
+ Element* element = CreateElement("a");
+
+ CustomElementReactionStack* stack = new CustomElementReactionStack();
+ stack->push();
+ stack->enqueue(element, new TestReaction({new Log('a', log)}));
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('z', log)}));
+ stack->push();
+ stack->enqueue(CreateElement("a"), new TestReaction({new Log('y', log)}));
+ stack->enqueue(element, new TestReaction({new Log('b', log)}));
+ stack->popInvokingReactions();
+
+ EXPECT_EQ(log, std::vector<char>({'y', 'a', 'b'}))
+ << "reactions should run together in the order elements were queued";
+
+ log.clear();
+ stack->popInvokingReactions();
+ EXPECT_EQ(log, std::vector<char>({'z'})) << "reactions should be run once";
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698