OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/custom/CustomElementReactionStack.h" |
| 6 |
| 7 #include "core/dom/custom/CustomElementReaction.h" |
| 8 #include "core/dom/custom/CustomElementReactionTestHelpers.h" |
| 9 #include "core/dom/custom/CustomElementTestHelpers.h" |
| 10 #include "core/html/HTMLDocument.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "wtf/text/AtomicString.h" |
| 13 #include <initializer_list> |
| 14 #include <vector> |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 TEST(CustomElementReactionStackTest, one) |
| 19 { |
| 20 std::vector<char> log; |
| 21 |
| 22 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 23 stack->push(); |
| 24 stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)})); |
| 25 stack->popInvokingReactions(); |
| 26 |
| 27 EXPECT_EQ(log, std::vector<char>({'a'})) |
| 28 << "popping the reaction stack should run reactions"; |
| 29 } |
| 30 |
| 31 TEST(CustomElementReactionStackTest, multipleElements) |
| 32 { |
| 33 std::vector<char> log; |
| 34 |
| 35 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 36 stack->push(); |
| 37 stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)})); |
| 38 stack->enqueue(CreateElement("a"), new TestReaction({new Log('b', log)})); |
| 39 stack->popInvokingReactions(); |
| 40 |
| 41 EXPECT_EQ(log, std::vector<char>({'a', 'b'})) |
| 42 << "reactions should run in the order the elements queued"; |
| 43 } |
| 44 |
| 45 TEST(CustomElementReactionStackTest, popTopEmpty) |
| 46 { |
| 47 std::vector<char> log; |
| 48 |
| 49 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 50 stack->push(); |
| 51 stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)})); |
| 52 stack->push(); |
| 53 stack->popInvokingReactions(); |
| 54 |
| 55 EXPECT_EQ(log, std::vector<char>()) |
| 56 << "popping the empty top-of-stack should not run any reactions"; |
| 57 } |
| 58 |
| 59 TEST(CustomElementReactionStackTest, popTop) |
| 60 { |
| 61 std::vector<char> log; |
| 62 |
| 63 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 64 stack->push(); |
| 65 stack->enqueue(CreateElement("a"), new TestReaction({new Log('a', log)})); |
| 66 stack->push(); |
| 67 stack->enqueue(CreateElement("a"), new TestReaction({new Log('b', log)})); |
| 68 stack->popInvokingReactions(); |
| 69 |
| 70 EXPECT_EQ(log, std::vector<char>({'b'})) |
| 71 << "popping the top-of-stack should only run top-of-stack reactions"; |
| 72 } |
| 73 |
| 74 TEST(CustomElementReactionStackTest, requeueingDoesNotReorderElements) |
| 75 { |
| 76 std::vector<char> log; |
| 77 |
| 78 Element* element = CreateElement("a"); |
| 79 |
| 80 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 81 stack->push(); |
| 82 stack->enqueue(element, new TestReaction({new Log('a', log)})); |
| 83 stack->enqueue(CreateElement("a"), new TestReaction({new Log('z', log)})); |
| 84 stack->enqueue(element, new TestReaction({new Log('b', log)})); |
| 85 stack->popInvokingReactions(); |
| 86 |
| 87 EXPECT_EQ(log, std::vector<char>({'a', 'b', 'z'})) |
| 88 << "reactions should run together in the order elements were queued"; |
| 89 } |
| 90 |
| 91 TEST(CustomElementReactionStackTest, oneReactionQueuePerElement) |
| 92 { |
| 93 std::vector<char> log; |
| 94 |
| 95 Element* element = CreateElement("a"); |
| 96 |
| 97 CustomElementReactionStack* stack = new CustomElementReactionStack(); |
| 98 stack->push(); |
| 99 stack->enqueue(element, new TestReaction({new Log('a', log)})); |
| 100 stack->enqueue(CreateElement("a"), new TestReaction({new Log('z', log)})); |
| 101 stack->push(); |
| 102 stack->enqueue(CreateElement("a"), new TestReaction({new Log('y', log)})); |
| 103 stack->enqueue(element, new TestReaction({new Log('b', log)})); |
| 104 stack->popInvokingReactions(); |
| 105 |
| 106 EXPECT_EQ(log, std::vector<char>({'y', 'a', 'b'})) |
| 107 << "reactions should run together in the order elements were queued"; |
| 108 |
| 109 log.clear(); |
| 110 stack->popInvokingReactions(); |
| 111 EXPECT_EQ(log, std::vector<char>({'z'})) << "reactions should be run once"; |
| 112 } |
| 113 |
| 114 } // namespace blink |
OLD | NEW |