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

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

Issue 2153043002: Make "Undo" command to restore selection after validating with the latest Layout tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-21T19:03:31 Created 4 years, 5 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/VisibleSelection.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/VisibleSelectionTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp b/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
index 820361524d7ec7d7b3b2654f36d96020d1046710..8d762b26265ad6ee75b9247b6b8f7aa0507ec1b9 100644
--- a/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
@@ -6,6 +6,7 @@
#include "core/dom/Range.h"
#include "core/editing/EditingTestBase.h"
+#include "core/editing/SelectionAdjuster.h"
#define LOREM_IPSUM \
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor " \
@@ -350,4 +351,29 @@ TEST_F(VisibleSelectionTest, WordGranularity)
}
}
+// This is for crbug.com/627783, simulating restoring selection
+// in undo stack.
+TEST_F(VisibleSelectionTest, validatePositionsIfNeededWithShadowHost)
+{
+ setBodyContent("<div id=host></div><div id=sample>foo</div>");
+ setShadowContent("<content>", "host");
+ Element* sample = document().getElementById("sample");
+
+ // Simulates saving selection in undo stack.
+ VisibleSelection selection(Position(sample->firstChild(), 0));
+ EXPECT_EQ(Position(sample->firstChild(), 0), selection.start());
+
+ // Simulates modifying DOM tree to invalidate distribution.
+ Element* host = document().getElementById("host");
+ host->appendChild(sample);
+
+ // Simulates to restore selection from undo stack.
+ selection.validatePositionsIfNeeded();
+ EXPECT_EQ(Position(sample->firstChild(), 0), selection.start());
+
+ VisibleSelectionInFlatTree selectionInFlatTree;
+ SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection);
+ EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.start());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698