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

Unified Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp

Issue 2755013004: Improve how DocumentMarkerController updates markers in response to text edits (Closed)
Patch Set: Rebase Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp
index 6d3f23b8318c17df233ef239c26ab56e6d172e39..c9684a639544927fe56b334090d1c915f92c1b0e 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp
@@ -8,7 +8,15 @@
namespace blink {
-class DocumentMarkerTest : public ::testing::Test {};
+using MarkerOffsets = DocumentMarker::MarkerOffsets;
+
+class DocumentMarkerTest : public ::testing::Test {
+ protected:
+ DocumentMarker* CreateMarker(unsigned startOffset, unsigned endOffset) {
+ return new DocumentMarker(startOffset, endOffset,
+ DocumentMarker::MatchStatus::kInactive);
+ }
+};
TEST_F(DocumentMarkerTest, MarkerTypeIteratorEmpty) {
DocumentMarker::MarkerTypes types(0);
@@ -45,4 +53,166 @@ TEST_F(DocumentMarkerTest, MarkerTypeIteratorDistributed) {
++it;
EXPECT_TRUE(it == types.end());
}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 0);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(5u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteEndAndAfter) {
+ DocumentMarker* marker = CreateMarker(10, 15);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 0);
+ EXPECT_EQ(10u, result.value().start_offset);
+ EXPECT_EQ(13u, result.value().end_offset);
}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteBeforeAndAfter) {
+ DocumentMarker* marker = CreateMarker(20, 25);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 0);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteBeforeAndBeginning) {
+ DocumentMarker* marker = CreateMarker(30, 35);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 0);
+ EXPECT_EQ(13u, result.value().start_offset);
+ EXPECT_EQ(16u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteBefore) {
+ DocumentMarker* marker = CreateMarker(40, 45);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 0);
+ EXPECT_EQ(21u, result.value().start_offset);
+ EXPECT_EQ(26u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteStartAndAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 10, 0);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteBeforeAndEnd) {
+ DocumentMarker* marker = CreateMarker(5, 10);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 10, 0);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteMarkerExactly) {
+ DocumentMarker* marker = CreateMarker(5, 10);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(5, 5, 0);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_DeleteMiddleOfMarker) {
+ DocumentMarker* marker = CreateMarker(5, 10);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(6, 3, 0);
+ EXPECT_EQ(5u, result.value().start_offset);
+ EXPECT_EQ(7u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_InsertAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(10, 0, 5);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(5u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_InsertImmediatelyAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(5, 0, 5);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(5u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_InsertInMiddle) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(2, 0, 5);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(10u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_InsertImmediatelyBefore) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 0, 5);
+ EXPECT_EQ(5u, result.value().start_offset);
+ EXPECT_EQ(10u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_InsertBefore) {
+ DocumentMarker* marker = CreateMarker(5, 10);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 0, 5);
+ EXPECT_EQ(10u, result.value().start_offset);
+ EXPECT_EQ(15u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 1);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(5u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceEndAndAfter) {
+ DocumentMarker* marker = CreateMarker(10, 15);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 1);
+ EXPECT_EQ(10u, result.value().start_offset);
+ EXPECT_EQ(13u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBeforeAndAfter) {
+ DocumentMarker* marker = CreateMarker(20, 25);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 1);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBeforeAndBeginning) {
+ DocumentMarker* marker = CreateMarker(30, 35);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 1);
+ EXPECT_EQ(14u, result.value().start_offset);
+ EXPECT_EQ(17u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBefore) {
+ DocumentMarker* marker = CreateMarker(40, 45);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(13, 19, 1);
+ EXPECT_EQ(22u, result.value().start_offset);
+ EXPECT_EQ(27u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBeginning) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 2, 1);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(4u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceEnd) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(3, 2, 1);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(4u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceExactly) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 5, 1);
+ EXPECT_EQ(0u, result.value().start_offset);
+ EXPECT_EQ(1u, result.value().end_offset);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBeginningAndAfter) {
+ DocumentMarker* marker = CreateMarker(0, 5);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(0, 6, 1);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+TEST_F(DocumentMarkerTest, GetShiftedMarkerPosition_ReplaceBeforeAndEnd) {
+ DocumentMarker* marker = CreateMarker(5, 10);
+ Optional<MarkerOffsets> result = marker->ComputeOffsetsAfterShift(4, 6, 1);
+ EXPECT_EQ(WTF::kNullopt, result);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698