| Index: third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp b/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp
|
| index ac920de651555b0554d9aaf68e52e5aadec8cbe6..8d536f1db546c3f34de12220991a8eb8e81441cd 100644
|
| --- a/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp
|
| @@ -328,4 +328,176 @@ TEST_F(FrameSelectionTest, SetSelectedRangePreservesHandle) {
|
| "selectSetSelectedRange they should be present after it.";
|
| }
|
|
|
| +TEST_F(FrameSelectionTest, CaretInFocusedShadowTree) {
|
| + SetBodyContent("<input id='field'>"); // <input> hosts a shadow tree.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const field = GetDocument().GetElementById("field");
|
| + field->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| +
|
| + field->blur(); // Move focus to document body.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_TRUE(Selection().IsHidden()); // Caret is now hidden.
|
| +}
|
| +
|
| +TEST_F(FrameSelectionTest, CaretInFocusedEditableDiv) {
|
| + SetBodyContent("<div contenteditable id='ce'>blabla</div>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const ce = GetDocument().GetElementById("ce");
|
| + ce->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| +
|
| + ce->blur(); // Move focus to document body.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_TRUE(Selection().IsHidden()); // Caret is now hidden.
|
| +}
|
| +
|
| +TEST_F(FrameSelectionTest, SelectionInFocusedEditableDiv) {
|
| + SetBodyContent("<div contenteditable id='ce'>blabla</div>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const ce = GetDocument().GetElementById("ce");
|
| + ce->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| +
|
| + Selection().SelectAll();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| +
|
| + ce->blur(); // Move focus to document body.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| + EXPECT_FALSE(Selection().IsHidden()); // Range is still visible.
|
| +}
|
| +
|
| +// crbug.com/692898
|
| +TEST_F(FrameSelectionTest, FocusingLinkHidesCaretInTextControl) {
|
| + SetBodyContent("<input id='field'><a href='www' id='alink'>link</a>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const field = GetDocument().GetElementById("field");
|
| + field->focus();
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| +
|
| + Element* const alink = GetDocument().GetElementById("alink");
|
| + alink->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +}
|
| +
|
| +// crbug.com/692898
|
| +TEST_F(FrameSelectionTest, FocusingLinkHidesSelectionInTextControl) {
|
| + SetBodyContent("<input id='field'><a href='www' id='alink'>link</a>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const field = GetDocument().GetElementById("field");
|
| + field->focus();
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| +
|
| + Selection().SelectAll();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| +
|
| + Element* const alink = GetDocument().GetElementById("alink");
|
| + alink->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +}
|
| +
|
| +// crbug.com/713051
|
| +TEST_F(FrameSelectionTest, FocusedNonEditableParent) {
|
| + SetBodyContent("<div tabindex='-1' id='parent'><input id='field'></div>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const field = GetDocument().GetElementById("field");
|
| + field->focus();
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| +
|
| + // Here the selection belongs to <input>'s shadow tree and that tree has a
|
| + // non-editable parent that is is focused.
|
| + Element* const parent = GetDocument().GetElementById("parent");
|
| + parent->focus();
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsCaret());
|
| + EXPECT_TRUE(Selection().IsHidden()); // Focus is outside editing boundary.
|
| +}
|
| +
|
| +// crbug.com/707143
|
| +TEST_F(FrameSelectionTest, RangeContainsFocus) {
|
| + SetBodyContent(
|
| + "<div id='outer'>"
|
| + " <div>"
|
| + " <span id='start'>start</span>"
|
| + " </div>"
|
| + " <a href='www' id='alink'>link</a>"
|
| + " <div>line 1</div>"
|
| + " <div id='middle'>line 2</div>"
|
| + " <div>line 3</div>"
|
| + " <div>line 4</div>"
|
| + " <span id='end'>end</span>"
|
| + " <div></div>"
|
| + "</div>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const start = GetDocument().GetElementById("start");
|
| + Element* const end = GetDocument().GetElementById("end");
|
| + Selection().SetSelection(
|
| + SelectionInDOMTree::Builder()
|
| + .SetBaseAndExtent(Position(start, 0), Position(end, 0))
|
| + .Build());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| +
|
| + Element* const alink = GetDocument().GetElementById("alink");
|
| + alink->focus();
|
| + EXPECT_FALSE(Selection().IsHidden()); // Range still visible.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| +}
|
| +
|
| +// crbug.com/707143
|
| +TEST_F(FrameSelectionTest, RangeOutsideFocus) {
|
| + SetBodyContent(
|
| + "<a href='www' id='alink'>link</a>"
|
| + "<div id='outer'>"
|
| + " <div>"
|
| + " <span id='start'>start</span>"
|
| + " </div>"
|
| + " <div>line 1</div>"
|
| + " <div id='middle'>line 2</div>"
|
| + " <div>line 3</div>"
|
| + " <div>line 4</div>"
|
| + " <span id='end'>end</span>"
|
| + " <div></div>"
|
| + "</div>");
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsNone());
|
| + EXPECT_TRUE(Selection().IsHidden());
|
| +
|
| + Element* const start = GetDocument().GetElementById("start");
|
| + Element* const end = GetDocument().GetElementById("end");
|
| + Selection().SetSelection(
|
| + SelectionInDOMTree::Builder()
|
| + .SetBaseAndExtent(Position(start, 0), Position(end, 0))
|
| + .Build());
|
| + EXPECT_FALSE(Selection().IsHidden());
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| +
|
| + Element* const alink = GetDocument().GetElementById("alink");
|
| + alink->focus();
|
| + EXPECT_FALSE(Selection().IsHidden()); // Range still visible.
|
| + EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange());
|
| +}
|
| +
|
| } // namespace blink
|
|
|