Index: third_party/WebKit/Source/core/editing/markers/EditingMarkerListTest.cpp |
diff --git a/third_party/WebKit/Source/core/editing/markers/EditingMarkerListTest.cpp b/third_party/WebKit/Source/core/editing/markers/EditingMarkerListTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3f818fc9a642cee6806caa6c3149bf22e796ac3b |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/editing/markers/EditingMarkerListTest.cpp |
@@ -0,0 +1,60 @@ |
+// Copyright 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/markers/EditingMarkerList.h" |
+ |
+#include "platform/heap/Handle.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace blink { |
+ |
+class EditingMarkerListForTesting : public EditingMarkerList { |
+ public: |
+ DocumentMarker::MarkerType allowedMarkerType() const final { |
+ return DocumentMarker::Composition; |
+ } |
+ |
+ bool markerListIsSortedPublicForTesting() const { |
+ return markerListIsSorted(); |
+ } |
+}; |
+ |
+class EditingMarkerListTest : public ::testing::Test { |
+ protected: |
+ EditingMarkerListTest() : m_markerList(new EditingMarkerListForTesting()) {} |
+ |
+ DocumentMarker* createMarker(unsigned startOffset, unsigned endOffset) { |
+ return new DocumentMarker(startOffset, endOffset, Color::black, false, |
+ Color::black); |
+ } |
+ |
+ Persistent<EditingMarkerListForTesting> m_markerList; |
+}; |
+ |
+TEST_F(EditingMarkerListTest, NewlyConstructedListIsSorted) { |
+ EXPECT_TRUE(m_markerList->markerListIsSortedPublicForTesting()); |
+} |
+ |
+TEST_F(EditingMarkerListTest, InsertingMarkersInSortedOrderKeepsListSorted) { |
+ m_markerList->add(createMarker(1, 2)); |
+ m_markerList->add(createMarker(2, 3)); |
+ m_markerList->add(createMarker(3, 4)); |
+ EXPECT_TRUE(m_markerList->markerListIsSortedPublicForTesting()); |
+} |
+ |
+TEST_F(EditingMarkerListTest, InsertingMarkersOutOfOrderMakesListUnsorted) { |
+ m_markerList->add(createMarker(1, 2)); |
+ m_markerList->add(createMarker(0, 1)); |
+ EXPECT_FALSE(m_markerList->markerListIsSortedPublicForTesting()); |
+} |
+ |
+TEST_F(EditingMarkerListTest, ClearingListMakesItSorted) { |
+ m_markerList->add(createMarker(1, 2)); |
+ m_markerList->add(createMarker(0, 1)); |
+ EXPECT_FALSE(m_markerList->markerListIsSortedPublicForTesting()); |
+ m_markerList->clear(); |
+ EXPECT_TRUE(m_markerList->markerListIsSortedPublicForTesting()); |
+} |
+ |
+} // namespace blink |