Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommandTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommandTest.cpp b/third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommandTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f697002be5f5bc6075e935157d70f41fd6a26371 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommandTest.cpp |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2017 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/editing/commands/SplitTextNodeCommand.h" |
| + |
| +#include "core/editing/EditingTestBase.h" |
| +#include "core/editing/PlainTextRange.h" |
| +#include "core/editing/commands/EditingState.h" |
| +#include "core/editing/markers/DocumentMarkerController.h" |
| + |
| +namespace blink { |
| + |
| +class SplitTextNodeCommandTest : public EditingTestBase {}; |
| + |
| +TEST_F(SplitTextNodeCommandTest, splitInMarkerInterior) { |
| + setBodyContent("<div contenteditable>test1 test2 test3</div>"); |
| + |
| + ContainerNode* div = toContainerNode(document().body()->firstChild()); |
| + |
| + EphemeralRange range = PlainTextRange(0, 5).createRange(*div); |
| + document().markers().addTextMatchMarker( |
| + range, DocumentMarker::MatchStatus::kInactive); |
| + |
| + range = PlainTextRange(6, 11).createRange(*div); |
| + document().markers().addTextMatchMarker( |
| + range, DocumentMarker::MatchStatus::kInactive); |
| + |
| + range = PlainTextRange(12, 17).createRange(*div); |
| + document().markers().addTextMatchMarker( |
| + range, DocumentMarker::MatchStatus::kInactive); |
| + |
| + SimpleEditCommand* command = SplitTextNodeCommand::create( |
| + toText(document().body()->firstChild()->firstChild()), 8); |
| + |
| + EditingState editingState; |
| + command->doApply(&editingState); |
| + |
| + Node* text1 = toText(div->firstChild()); |
| + Node* text2 = toText(text1->nextSibling()); |
| + |
| + // The first marker should end up in text1, the second marker should be |
| + // truncated and end up text1, the third marker should end up in text2 |
| + // and its offset shifted to remain on the same piece of text |
| + |
| + EXPECT_EQ(2u, document().markers().markersFor(text1).size()); |
| + |
| + EXPECT_EQ(0u, document().markers().markersFor(text1)[0]->startOffset()); |
| + EXPECT_EQ(5u, document().markers().markersFor(text1)[0]->endOffset()); |
| + |
| + EXPECT_EQ(6u, document().markers().markersFor(text1)[1]->startOffset()); |
| + EXPECT_EQ(7u, document().markers().markersFor(text1)[1]->endOffset()); |
| + |
| + EXPECT_EQ(1u, document().markers().markersFor(text2).size()); |
| + |
| + EXPECT_EQ(4u, document().markers().markersFor(text2)[0]->startOffset()); |
| + EXPECT_EQ(9u, document().markers().markersFor(text2)[0]->endOffset()); |
| + |
| + // Test undo |
| + command->doUnapply(); |
| + |
| + Node* text = toText(div->firstChild()); |
| + |
| + EXPECT_EQ(3u, document().markers().markersFor(text).size()); |
| + |
| + EXPECT_EQ(0u, document().markers().markersFor(text)[0]->startOffset()); |
| + EXPECT_EQ(5u, document().markers().markersFor(text)[0]->endOffset()); |
| + |
| + // TODO(rlanday): the truncated marker that spanned node boundaries is not |
|
Xiaocheng
2017/04/08 02:38:19
Do you really plan to fix it?
I don't see a clean
|
| + // restored properly |
| + EXPECT_EQ(6u, document().markers().markersFor(text)[1]->startOffset()); |
| + EXPECT_EQ(7u, document().markers().markersFor(text)[1]->endOffset()); |
| + |
| + EXPECT_EQ(12u, document().markers().markersFor(text)[2]->startOffset()); |
| + EXPECT_EQ(17u, document().markers().markersFor(text)[2]->endOffset()); |
| + |
| + // Test redo |
| + command->doReapply(); |
| + |
| + text1 = toText(div->firstChild()); |
| + text2 = toText(text1->nextSibling()); |
| + |
| + EXPECT_EQ(2u, document().markers().markersFor(text1).size()); |
| + |
| + EXPECT_EQ(0u, document().markers().markersFor(text1)[0]->startOffset()); |
| + EXPECT_EQ(5u, document().markers().markersFor(text1)[0]->endOffset()); |
| + |
| + EXPECT_EQ(6u, document().markers().markersFor(text1)[1]->startOffset()); |
| + EXPECT_EQ(7u, document().markers().markersFor(text1)[1]->endOffset()); |
| + |
| + EXPECT_EQ(1u, document().markers().markersFor(text2).size()); |
| + |
| + EXPECT_EQ(4u, document().markers().markersFor(text2)[0]->startOffset()); |
| + EXPECT_EQ(9u, document().markers().markersFor(text2)[0]->endOffset()); |
| +} |
| + |
| +} // namespace blink |