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

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

Issue 2772163002: Make {Character,Directional}GranularityStrategy::updateExtent() to handle null position (Closed)
Patch Set: 2017-03-27T13:42:09 ASSERT_EQ(visiblePositionForContentsPoint(IntPoint(0, 0))) Created 3 years, 9 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/GranularityStrategy.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/GranularityStrategyTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp b/third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp
index 3291f0c34f2335adb945949d305e4399925fa632..7a1441940e39a18dedd96d145356bbdb629d4af0 100644
--- a/third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp
+++ b/third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp
@@ -40,6 +40,7 @@ class GranularityStrategyTest : public ::testing::Test {
DummyPageHolder& dummyPageHolder() const { return *m_dummyPageHolder; }
Document& document() const;
+ LocalFrame& frame() const { return m_dummyPageHolder->frame(); }
void setSelection(const VisibleSelection&);
FrameSelection& selection() const;
Text* appendTextNode(const String& data);
@@ -708,4 +709,69 @@ TEST_F(GranularityStrategyTest, DirectionSwitchStartOnBoundary) {
EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
}
+// For http://crbug.com/704529
+TEST_F(GranularityStrategyTest, UpdateExtentWithNullPositionForCharacter) {
+ dummyPageHolder().frame().settings()->setSelectionStrategy(
+ SelectionStrategy::Character);
+ document().body()->setInnerHTML("<div id=host></div><div id=sample>ab</div>");
+ // Simulate VIDEO element which has a RANGE as slider of video time.
+ Element* const host = document().getElementById("host");
+ ShadowRoot* const shadowRoot =
+ host->createShadowRootInternal(ShadowRootType::Open, ASSERT_NO_EXCEPTION);
+ shadowRoot->setInnerHTML("<input type=range>");
+ Element* const sample = document().getElementById("sample");
+ document().updateStyleAndLayout();
+ const SelectionInDOMTree& selectionInDOMTree =
+ SelectionInDOMTree::Builder()
+ .collapse(Position(sample->firstChild(), 2))
+ .setIsDirectional(true)
+ .setIsHandleVisible(true)
+ .build();
+ selection().setSelection(selectionInDOMTree);
+
+ // Since, it is not obvious that |visiblePositionForContentsPoint()| returns
+ // null position, we verify here.
+ ASSERT_EQ(Position(),
+ visiblePositionForContentsPoint(IntPoint(0, 0), &frame())
+ .deepEquivalent())
+ << "This test requires null position.";
+
+ // Point to RANGE inside shadow root to get null position from
+ // |visiblePositionForContentsPoint()|.
+ selection().moveRangeSelectionExtent(IntPoint(0, 0));
+ EXPECT_EQ(selectionInDOMTree, selection().selectionInDOMTree());
+}
+
+// For http://crbug.com/704529
+TEST_F(GranularityStrategyTest, UpdateExtentWithNullPositionForDirectional) {
+ document().body()->setInnerHTML("<div id=host></div><div id=sample>ab</div>");
+ // Simulate VIDEO element which has a RANGE as slider of video time.
+ Element* const host = document().getElementById("host");
+ ShadowRoot* const shadowRoot =
+ host->createShadowRootInternal(ShadowRootType::Open, ASSERT_NO_EXCEPTION);
+ shadowRoot->setInnerHTML("<input type=range>");
+ Element* const sample = document().getElementById("sample");
+ document().updateStyleAndLayout();
+ const SelectionInDOMTree& selectionInDOMTree =
+ SelectionInDOMTree::Builder()
+ .collapse(Position(sample->firstChild(), 2))
+ .setIsDirectional(true)
+ .setIsHandleVisible(true)
+ .build();
+ selection().setSelection(selectionInDOMTree);
+
+ // Since, it is not obvious that |visiblePositionForContentsPoint()| returns
+ // null position, we verify here.
+ ASSERT_EQ(Position(),
+ visiblePositionForContentsPoint(IntPoint(0, 0), &frame())
+ .deepEquivalent())
+ << "This test requires null position.";
+
+ // Point to RANGE inside shadow root to get null position from
+ // |visiblePositionForContentsPoint()|.
+ selection().moveRangeSelectionExtent(IntPoint(0, 0));
+
+ EXPECT_EQ(selectionInDOMTree, selection().selectionInDOMTree());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/GranularityStrategy.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698