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

Unified Diff: third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp

Issue 2354893002: Introduce VisiblePosition::isValid (Closed)
Patch Set: 201609211817 Created 4 years, 3 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
Index: third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp b/third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp
index 2b1baab6ed0e4bf2e136f5b2b41d7e6268fd9dc3..8470e4e90282b6e5eef459390769311cfe2f999d 100644
--- a/third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp
+++ b/third_party/WebKit/Source/core/editing/VisiblePositionTest.cpp
@@ -4,6 +4,7 @@
#include "core/editing/VisiblePosition.h"
+#include "core/css/CSSStyleDeclaration.h"
#include "core/editing/EditingTestBase.h"
#include "core/editing/VisibleUnits.h"
@@ -36,4 +37,68 @@ TEST_F(VisiblePositionTest, ShadowV0DistributedNodes)
EXPECT_EQ(PositionInFlatTree(four->firstChild(), 2), createVisiblePosition(PositionInFlatTree(two, 0)).deepEquivalent());
}
+#if DCHECK_IS_ON()
+
+TEST_F(VisiblePositionTest, NullIsValid)
+{
+ EXPECT_TRUE(VisiblePosition().isValid());
+}
+
+TEST_F(VisiblePositionTest, NonNullIsValidBeforeMutation)
+{
+ setBodyContent("<p>one</p>");
+
+ Element* paragraph = document().querySelector("p");
+ Position position(paragraph->firstChild(), 1);
+ EXPECT_TRUE(createVisiblePosition(position).isValid());
+}
+
+TEST_F(VisiblePositionTest, NonNullInvalidatedAfterDOMChange)
+{
+ setBodyContent("<p>one</p>");
+
+ Element* paragraph = document().querySelector("p");
+ Position position(paragraph->firstChild(), 1);
+ VisiblePosition nullVisiblePosition;
+ VisiblePosition nonNullVisiblePosition = createVisiblePosition(position);
+
+ Element* div = document().createElement("div", ASSERT_NO_EXCEPTION);
+ document().body()->appendChild(div);
+
+ EXPECT_TRUE(nullVisiblePosition.isValid());
+ EXPECT_FALSE(nonNullVisiblePosition.isValid());
+
+ updateAllLifecyclePhases();
+
+ // Invalid VisiblePosition can never become valid again.
+ EXPECT_FALSE(nonNullVisiblePosition.isValid());
+}
+
+TEST_F(VisiblePositionTest, NonNullInvalidatedAfterStyleChange)
+{
+ setBodyContent("<div>one</div><p>two</p>");
+
+ Element* paragraph = document().querySelector("p");
+ Element* div = document().querySelector("div");
+ Position position(paragraph->firstChild(), 1);
+
+ VisiblePosition visiblePosition1 = createVisiblePosition(position);
+ div->style()->setProperty("color", "red", "important", ASSERT_NO_EXCEPTION);
+ EXPECT_FALSE(visiblePosition1.isValid());
+
+ updateAllLifecyclePhases();
+
+ VisiblePosition visiblePosition2 = createVisiblePosition(position);
+ div->style()->setProperty("display", "none", "important", ASSERT_NO_EXCEPTION);
+ EXPECT_FALSE(visiblePosition2.isValid());
+
+ updateAllLifecyclePhases();
+
+ // Invalid VisiblePosition can never become valid again.
+ EXPECT_FALSE(visiblePosition1.isValid());
+ EXPECT_FALSE(visiblePosition2.isValid());
+}
+
+#endif
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisiblePosition.cpp ('k') | third_party/WebKit/Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698