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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementReactionTestHelpers.h

Issue 2456773002: Clear the custom element's reaction queue if upgrade fails. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElementReaction.h" 5 #include "core/dom/custom/CustomElementReaction.h"
6 6
7 #include "core/dom/custom/CustomElementReactionQueue.h" 7 #include "core/dom/custom/CustomElementReactionQueue.h"
8 #include "core/dom/custom/CustomElementReactionStack.h"
8 #include "platform/heap/Handle.h" 9 #include "platform/heap/Handle.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "wtf/Functional.h"
9 #include "wtf/Noncopyable.h" 12 #include "wtf/Noncopyable.h"
10 #include <initializer_list> 13 #include <initializer_list>
14 #include <memory>
11 #include <vector> 15 #include <vector>
12 16
13 namespace blink { 17 namespace blink {
14 18
15 class Element; 19 class Element;
16 20
17 class Command : public GarbageCollectedFinalized<Command> { 21 class Command : public GarbageCollectedFinalized<Command> {
18 WTF_MAKE_NONCOPYABLE(Command); 22 WTF_MAKE_NONCOPYABLE(Command);
19 23
20 public: 24 public:
21 Command() = default; 25 Command() = default;
22 virtual ~Command() = default; 26 virtual ~Command() = default;
23 DEFINE_INLINE_VIRTUAL_TRACE() {} 27 DEFINE_INLINE_VIRTUAL_TRACE() {}
24 virtual void run(Element*) = 0; 28 virtual void run(Element*) = 0;
25 }; 29 };
26 30
31 class Call : public Command {
32 WTF_MAKE_NONCOPYABLE(Call);
33
34 public:
35 using Callback = WTF::Function<void(Element*)>;
36 Call(std::unique_ptr<Callback> callback) : m_callback(std::move(callback)) {}
37 ~Call() override = default;
38 void run(Element* element) override { m_callback->operator()(element); }
39
40 private:
41 std::unique_ptr<Callback> m_callback;
42 };
43
44 class Unreached : public Command {
45 WTF_MAKE_NONCOPYABLE(Unreached);
46
47 public:
48 Unreached(const char* message) : m_message(message) {}
49 ~Unreached() override = default;
50 void run(Element*) override { EXPECT_TRUE(false) << m_message; }
51
52 private:
53 const char* m_message;
54 };
55
27 class Log : public Command { 56 class Log : public Command {
28 WTF_MAKE_NONCOPYABLE(Log); 57 WTF_MAKE_NONCOPYABLE(Log);
29 58
30 public: 59 public:
31 Log(char what, std::vector<char>& where) : m_what(what), m_where(where) {} 60 Log(char what, std::vector<char>& where) : m_what(what), m_where(where) {}
32 ~Log() override = default; 61 ~Log() override = default;
33 void run(Element*) override { m_where.push_back(m_what); } 62 void run(Element*) override { m_where.push_back(m_what); }
34 63
35 private: 64 private:
36 char m_what; 65 char m_what;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 119 }
91 void invoke(Element* element) override { 120 void invoke(Element* element) override {
92 for (auto& command : m_commands) 121 for (auto& command : m_commands)
93 command->run(element); 122 command->run(element);
94 } 123 }
95 124
96 private: 125 private:
97 HeapVector<Member<Command>> m_commands; 126 HeapVector<Member<Command>> m_commands;
98 }; 127 };
99 128
129 class ResetCustomElementReactionStackForTest final {
130 STACK_ALLOCATED();
131 WTF_MAKE_NONCOPYABLE(ResetCustomElementReactionStackForTest);
132
133 public:
134 ResetCustomElementReactionStackForTest()
135 : m_stack(new CustomElementReactionStack),
136 m_oldStack(
137 CustomElementReactionStackTestSupport::setCurrentForTest(m_stack)) {
138 }
139
140 ~ResetCustomElementReactionStackForTest() {
141 CustomElementReactionStackTestSupport::setCurrentForTest(m_oldStack);
142 }
143
144 CustomElementReactionStack& stack() { return *m_stack; }
145
146 private:
147 Member<CustomElementReactionStack> m_stack;
148 Member<CustomElementReactionStack> m_oldStack;
149 };
150
100 } // namespace blink 151 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698