OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/editing/commands/CompositeEditCommand.h" | |
6 | |
7 #include "core/css/StylePropertySet.h" | |
8 #include "core/dom/Document.h" | |
9 #include "core/editing/EditingTestBase.h" | |
10 #include "core/editing/FrameSelection.h" | |
11 #include "core/frame/LocalFrame.h" | |
12 | |
13 namespace blink { | |
14 | |
15 namespace { | |
16 | |
17 class SampleCommand final : public CompositeEditCommand { | |
18 public: | |
19 SampleCommand(Document&); | |
20 | |
21 void insertNodeBefore( | |
22 Node*, | |
23 Node* refChild, | |
24 EditingState*, | |
25 ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); | |
26 | |
27 // CompositeEditCommand member implementations | |
28 void doApply(EditingState*) final {} | |
29 InputEvent::InputType inputType() const final { | |
30 return InputEvent::InputType::None; | |
31 } | |
32 }; | |
33 | |
34 SampleCommand::SampleCommand(Document& document) | |
35 : CompositeEditCommand(document) {} | |
36 | |
37 void SampleCommand::insertNodeBefore( | |
38 Node* insertChild, | |
39 Node* refChild, | |
40 EditingState* editingState, | |
41 ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable) { | |
42 CompositeEditCommand::insertNodeBefore(insertChild, refChild, editingState, | |
43 shouldAssumeContentIsAlwaysEditable); | |
44 } | |
45 | |
46 } // namespace | |
47 | |
48 class CompositeEditCommandTest : public EditingTestBase {}; | |
49 | |
50 TEST_F(CompositeEditCommandTest, insertNodeBefore) { | |
51 setBodyContent("<div contenteditable><b></b></div>"); | |
52 SampleCommand& sample = *new SampleCommand(document()); | |
yoichio
2017/01/18 02:29:17
Why do you use reference than simple pointer?
yosin_UTC9
2017/01/18 03:44:14
Short form of
SampleCommand* const sample = new Sa
| |
53 Node* insertChild = document().createTextNode("foo"); | |
54 Element* refChild = document().querySelector("b"); | |
55 Element* div = document().querySelector("div"); | |
56 | |
57 EditingState editingState; | |
58 sample.insertNodeBefore(insertChild, refChild, &editingState); | |
59 EXPECT_FALSE(editingState.isAborted()); | |
60 EXPECT_EQ("foo<b></b>", div->innerHTML()); | |
61 } | |
62 | |
63 TEST_F(CompositeEditCommandTest, insertNodeBeforeInUneditable) { | |
64 setBodyContent("<div><b></b></div>"); | |
65 SampleCommand& sample = *new SampleCommand(document()); | |
66 Node* insertChild = document().createTextNode("foo"); | |
67 Element* refChild = document().querySelector("b"); | |
68 | |
69 EditingState editingState; | |
70 sample.insertNodeBefore(insertChild, refChild, &editingState); | |
71 EXPECT_TRUE(editingState.isAborted()); | |
72 } | |
73 | |
74 TEST_F(CompositeEditCommandTest, insertNodeBeforeDisconnectedNode) { | |
75 setBodyContent("<div><b></b></div>"); | |
76 SampleCommand& sample = *new SampleCommand(document()); | |
77 Node* insertChild = document().createTextNode("foo"); | |
78 Element* refChild = document().querySelector("b"); | |
79 Element* div = document().querySelector("div"); | |
80 div->remove(); | |
81 | |
82 EditingState editingState; | |
83 sample.insertNodeBefore(insertChild, refChild, &editingState); | |
84 EXPECT_FALSE(editingState.isAborted()); | |
85 EXPECT_EQ("<b></b>", div->innerHTML()) | |
86 << "InsertNodeBeforeCommand does nothing for disconnected node"; | |
87 } | |
88 | |
89 TEST_F(CompositeEditCommandTest, insertNodeBeforeWithDirtyLayoutTree) { | |
90 setBodyContent("<div><b></b></div>"); | |
91 SampleCommand& sample = *new SampleCommand(document()); | |
92 Node* insertChild = document().createTextNode("foo"); | |
93 Element* refChild = document().querySelector("b"); | |
94 Element* div = document().querySelector("div"); | |
95 div->setAttribute(HTMLNames::contenteditableAttr, "true"); | |
96 | |
97 EditingState editingState; | |
98 sample.insertNodeBefore(insertChild, refChild, &editingState); | |
99 EXPECT_FALSE(editingState.isAborted()); | |
100 EXPECT_EQ("foo<b></b>", div->innerHTML()); | |
101 } | |
102 | |
103 } // namespace blink | |
OLD | NEW |