Commit 97d22fa5 authored by tanvir.rizvi's avatar tanvir.rizvi Committed by Commit Bot

Clean up call sites of FrameSelection::SetSelectionAndEndTyping

Many call sites which use this function do not
bother about the clearing the typing but they use
this function which is confusing.
Rather we will use FrameSelection::SetSelection
and pass default options now.
This CL does it from the EditorCommand.

Bug: 867563
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ie25813f1cd76b00001a0447118c9a3e8cd42cc52
Reviewed-on: https://chromium-review.googlesource.com/1154861
Commit-Queue: Tanvir Rizvi <tanvir.rizvi@samsung.com>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579329}
parent ac6abd59
......@@ -37,12 +37,13 @@ TEST_F(ApplyBlockElementCommandTest, selectionCrossingOverBody) {
GetDocument().body()->setContentEditable("false", ASSERT_NO_EXCEPTION);
GetDocument().setDesignMode("on");
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
Selection().SetSelectionAndEndTyping(
Selection().SetSelection(
SelectionInDOMTree::Builder()
.SetBaseAndExtent(
Position(GetDocument().documentElement(), 1),
Position(GetDocument().getElementById("va")->firstChild(), 2))
.Build());
.Build(),
SetSelectionOptions());
FormatBlockCommand* command =
FormatBlockCommand::Create(GetDocument(), HTMLNames::footerTag);
......@@ -63,10 +64,11 @@ TEST_F(ApplyBlockElementCommandTest, visibilityChangeDuringCommand) {
GetDocument().setDesignMode("on");
UpdateAllLifecyclePhases();
Selection().SetSelectionAndEndTyping(
Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(GetDocument().QuerySelector("li"), 0))
.Build());
.Build(),
SetSelectionOptions());
IndentOutdentCommand* command = IndentOutdentCommand::Create(
GetDocument(), IndentOutdentCommand::kIndent);
......@@ -87,10 +89,11 @@ TEST_F(ApplyBlockElementCommandTest, IndentHeadingIntoBlockquote) {
"</div>");
Element* button = GetDocument().QuerySelector("button");
Element* object = GetDocument().QuerySelector("object");
Selection().SetSelectionAndEndTyping(SelectionInDOMTree::Builder()
.Collapse(Position(button, 0))
.Extend(Position(object, 0))
.Build());
Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(button, 0))
.Extend(Position(object, 0))
.Build(),
SetSelectionOptions());
IndentOutdentCommand* command = IndentOutdentCommand::Create(
GetDocument(), IndentOutdentCommand::kIndent);
......@@ -113,8 +116,10 @@ TEST_F(ApplyBlockElementCommandTest, IndentHeadingIntoBlockquote) {
TEST_F(ApplyBlockElementCommandTest, InsertPlaceHolderAtDisconnectedPosition) {
GetDocument().setDesignMode("on");
InsertStyleElement(".input:nth-of-type(2n+1) { visibility:collapse; }");
Selection().SetSelectionAndEndTyping(SetSelectionTextToBody(
"^<input><input class=\"input\" style=\"position:absolute\">|"));
Selection().SetSelection(
SetSelectionTextToBody(
"^<input><input class=\"input\" style=\"position:absolute\">|"),
SetSelectionOptions());
FormatBlockCommand* command =
FormatBlockCommand::Create(GetDocument(), HTMLNames::preTag);
// Crash happens here.
......
......@@ -35,10 +35,11 @@ TEST_F(ApplyStyleCommandTest, RemoveRedundantBlocksWithStarEditableStyle) {
Element* li = GetDocument().QuerySelector("li");
LocalFrame* frame = GetDocument().GetFrame();
frame->Selection().SetSelectionAndEndTyping(
frame->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(li, PositionAnchorType::kBeforeAnchor))
.Build());
.Build(),
SetSelectionOptions());
MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
......@@ -82,8 +83,10 @@ TEST_F(ApplyStyleCommandTest, JustifyRightDetachesDestination) {
// This is a regression test for https://crbug.com/726992
TEST_F(ApplyStyleCommandTest, FontSizeDeltaWithSpanElement) {
Selection().SetSelectionAndEndTyping(SetSelectionTextToBody(
"<div contenteditable>^<div></div>a<span></span>|</div>"));
Selection().SetSelection(
SetSelectionTextToBody(
"<div contenteditable>^<div></div>a<span></span>|</div>"),
SetSelectionOptions());
MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
......
......@@ -37,11 +37,12 @@ TEST_F(DeleteSelectionCommandTest, deleteListFromTable) {
Element* br = GetDocument().QuerySelector("br");
LocalFrame* frame = GetDocument().GetFrame();
frame->Selection().SetSelectionAndEndTyping(
frame->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(br, PositionAnchorType::kBeforeAnchor))
.Extend(Position(table, PositionAnchorType::kAfterAnchor))
.Build());
.Build(),
SetSelectionOptions());
DeleteSelectionCommand* command =
DeleteSelectionCommand::Create(GetDocument(),
......@@ -63,8 +64,9 @@ TEST_F(DeleteSelectionCommandTest, deleteListFromTable) {
TEST_F(DeleteSelectionCommandTest, ForwardDeleteWithFirstLetter) {
InsertStyleElement("p::first-letter {font-size:200%;}");
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<p contenteditable>a^b|c</p>"));
Selection().SetSelection(
SetSelectionTextToBody("<p contenteditable>a^b|c</p>"),
SetSelectionOptions());
DeleteSelectionCommand& command = *DeleteSelectionCommand::Create(
GetDocument(), DeleteSelectionOptions::Builder()
......
......@@ -17,11 +17,11 @@ TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsReplace) {
SetBodyContent("<div id=sample contenteditable><a>a</a>b&#x1F63A;</div>");
Element* const sample = GetDocument().getElementById("sample");
const String new_text(Vector<UChar>{0xD83D, 0xDE38}); // U+1F638
Selection().SetSelectionAndEndTyping(
SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 3))
.Build());
Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 3))
.Build(),
SetSelectionOptions());
CompositeEditCommand* const command =
InsertIncrementalTextCommand::Create(GetDocument(), new_text);
command->Apply();
......@@ -35,11 +35,11 @@ TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsNoReplace) {
SetBodyContent("<div id=sample contenteditable><a>a</a>b&#x1F63A;</div>");
Element* const sample = GetDocument().getElementById("sample");
const String new_text(Vector<UChar>{0xD83D, 0xDE3A}); // U+1F63A
Selection().SetSelectionAndEndTyping(
SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 3))
.Build());
Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 3))
.Build(),
SetSelectionOptions());
CompositeEditCommand* const command =
InsertIncrementalTextCommand::Create(GetDocument(), new_text);
command->Apply();
......@@ -55,11 +55,11 @@ TEST_F(InsertIncrementalTextCommandTest, SurrogatePairsTwo) {
"<div id=sample contenteditable><a>a</a>b&#x1F63A;&#x1F63A;</div>");
Element* const sample = GetDocument().getElementById("sample");
const String new_text(Vector<UChar>{0xD83D, 0xDE38}); // U+1F638
Selection().SetSelectionAndEndTyping(
SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 5))
.Build());
Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(sample->lastChild(), 1))
.Extend(Position(sample->lastChild(), 5))
.Build(),
SetSelectionOptions());
CompositeEditCommand* const command =
InsertIncrementalTextCommand::Create(GetDocument(), new_text);
command->Apply();
......
......@@ -36,11 +36,12 @@ TEST_F(InsertListCommandTest, ShouldCleanlyRemoveSpuriousTextNode) {
GetDocument().body()->InsertBefore(empty_text,
GetDocument().body()->firstChild());
UpdateAllLifecyclePhases();
GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping(
GetDocument().GetFrame()->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(GetDocument().body(), 0))
.Extend(Position(GetDocument().body(), 2))
.Build());
.Build(),
SetSelectionOptions());
InsertListCommand* command =
InsertListCommand::Create(GetDocument(), InsertListCommand::kOrderedList);
......@@ -53,10 +54,11 @@ TEST_F(InsertListCommandTest, ShouldCleanlyRemoveSpuriousTextNode) {
// Refer https://crbug.com/794356
TEST_F(InsertListCommandTest, UnlistifyParagraphCrashOnVisuallyEmptyParagraph) {
GetDocument().setDesignMode("on");
Selection().SetSelectionAndEndTyping(
Selection().SetSelection(
SetSelectionTextToBody("^<dl>"
"<textarea style='float:left;'></textarea>"
"</dl>|"));
"</dl>|"),
SetSelectionOptions());
InsertListCommand* command = InsertListCommand::Create(
GetDocument(), InsertListCommand::kUnorderedList);
// Crash happens here.
......@@ -75,9 +77,9 @@ TEST_F(InsertListCommandTest, CleanupNodeSameAsDestinationNode) {
"* { -webkit-appearance:checkbox; }"
"br { visibility:hidden; }"
"colgroup { -webkit-column-count:2; }");
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("^<table><col></table>"
"<button></button>|"));
Selection().SetSelection(SetSelectionTextToBody("^<table><col></table>"
"<button></button>|"),
SetSelectionOptions());
InsertListCommand* command = InsertListCommand::Create(
GetDocument(), InsertListCommand::kUnorderedList);
......@@ -97,8 +99,8 @@ TEST_F(InsertListCommandTest, CleanupNodeSameAsDestinationNode) {
TEST_F(InsertListCommandTest, InsertListOnEmptyHiddenElements) {
GetDocument().setDesignMode("on");
InsertStyleElement("br { visibility:hidden; }");
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("^<button></button>|"));
Selection().SetSelection(SetSelectionTextToBody("^<button></button>|"),
SetSelectionOptions());
InsertListCommand* command = InsertListCommand::Create(
GetDocument(), InsertListCommand::kUnorderedList);
......@@ -118,7 +120,8 @@ TEST_F(InsertListCommandTest, InsertListWithCollapsedVisibility) {
"ul { visibility:collapse; }"
"dl { visibility:visible; }");
Selection().SetSelectionAndEndTyping(SetSelectionTextToBody("^<dl>a</dl>|"));
Selection().SetSelection(SetSelectionTextToBody("^<dl>a</dl>|"),
SetSelectionOptions());
InsertListCommand* command =
InsertListCommand::Create(GetDocument(), InsertListCommand::kOrderedList);
......
......@@ -17,10 +17,12 @@ class InsertParagraphSeparatorCommandTest : public EditingTestBase {};
// http://crbug.com/777378
TEST_F(InsertParagraphSeparatorCommandTest,
CrashWithAppearanceStyleOnEmptyColgroup) {
Selection().SetSelectionAndEndTyping(SetSelectionTextToBody(
"<table contenteditable>"
" <colgroup style='-webkit-appearance:radio;'><!--|--></colgroup>"
"</table>"));
Selection().SetSelection(
SetSelectionTextToBody(
"<table contenteditable>"
" <colgroup style='-webkit-appearance:radio;'><!--|--></colgroup>"
"</table>"),
SetSelectionOptions());
InsertParagraphSeparatorCommand* command =
InsertParagraphSeparatorCommand::Create(GetDocument());
......@@ -37,12 +39,13 @@ TEST_F(InsertParagraphSeparatorCommandTest,
// http://crbug.com/777378
TEST_F(InsertParagraphSeparatorCommandTest,
CrashWithAppearanceStyleOnEmptyColumn) {
Selection().SetSelectionAndEndTyping(
Selection().SetSelection(
SetSelectionTextToBody("<table contenteditable>"
" <colgroup style='-webkit-appearance:radio;'>"
" <col><!--|--></col>"
" </colgroup>"
"</table>"));
"</table>"),
SetSelectionOptions());
InsertParagraphSeparatorCommand* command =
InsertParagraphSeparatorCommand::Create(GetDocument());
......
......@@ -33,10 +33,11 @@ TEST_F(ReplaceSelectionCommandTest, pastingEmptySpan) {
SetBodyContent("foo");
LocalFrame* frame = GetDocument().GetFrame();
frame->Selection().SetSelectionAndEndTyping(
frame->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(GetDocument().body(), 0))
.Build());
.Build(),
SetSelectionOptions());
DocumentFragment* fragment = GetDocument().createDocumentFragment();
fragment->AppendChild(GetDocument().CreateRawElement(HTMLNames::spanTag));
......@@ -64,10 +65,11 @@ TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) {
Element* b_element = GetDocument().QuerySelector("b");
LocalFrame* frame = GetDocument().GetFrame();
frame->Selection().SetSelectionAndEndTyping(
frame->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(b_element->firstChild(), 1))
.Build());
.Build(),
SetSelectionOptions());
DocumentFragment* fragment = GetDocument().createDocumentFragment();
fragment->ParseHTML("<span><div>bar</div></span>", b_element);
......@@ -85,10 +87,11 @@ TEST_F(ReplaceSelectionCommandTest, pasteSpanInText) {
TEST_F(ReplaceSelectionCommandTest, styleTagsInPastedHeadIncludedInContent) {
GetDocument().setDesignMode("on");
UpdateAllLifecyclePhases();
GetDummyPageHolder().GetFrame().Selection().SetSelectionAndEndTyping(
GetDummyPageHolder().GetFrame().Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(GetDocument().body(), 0))
.Build());
.Build(),
SetSelectionOptions());
DocumentFragment* fragment = GetDocument().createDocumentFragment();
fragment->ParseHTML(
......@@ -137,11 +140,12 @@ TEST_F(ReplaceSelectionCommandTest, TextAutosizingDoesntInflateText) {
Element* span = GetDocument().QuerySelector("span");
// Select "bar".
GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping(
GetDocument().GetFrame()->Selection().SetSelection(
SelectionInDOMTree::Builder()
.Collapse(Position(span->firstChild(), 4))
.Extend(Position(span->firstChild(), 7))
.Build());
.Build(),
SetSelectionOptions());
DocumentFragment* fragment = GetDocument().createDocumentFragment();
fragment->ParseHTML("baz", span);
......@@ -160,8 +164,8 @@ TEST_F(ReplaceSelectionCommandTest, TextAutosizingDoesntInflateText) {
// This is a regression test for https://crbug.com/781282
TEST_F(ReplaceSelectionCommandTest, TrailingNonVisibleTextCrash) {
GetDocument().setDesignMode("on");
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div>^foo|</div>"));
Selection().SetSelection(SetSelectionTextToBody("<div>^foo|</div>"),
SetSelectionOptions());
DocumentFragment* fragment = GetDocument().createDocumentFragment();
fragment->ParseHTML("<div>bar</div> ", GetDocument().QuerySelector("div"));
......
......@@ -45,10 +45,11 @@ TEST_F(TypingCommandTest, insertLineBreakWithIllFormedHTML) {
div->AppendChild(tr);
LocalFrame* frame = GetDocument().GetFrame();
frame->Selection().SetSelectionAndEndTyping(SelectionInDOMTree::Builder()
.Collapse(Position(form, 0))
.Extend(Position(header, 0))
.Build());
frame->Selection().SetSelection(SelectionInDOMTree::Builder()
.Collapse(Position(form, 0))
.Extend(Position(header, 0))
.Build(),
SetSelectionOptions());
// Inserting line break should not crash or hit assertion.
TypingCommand::InsertLineBreak(GetDocument());
......@@ -57,8 +58,9 @@ TEST_F(TypingCommandTest, insertLineBreakWithIllFormedHTML) {
// http://crbug.com/767599
TEST_F(TypingCommandTest,
DontCrashWhenReplaceSelectionCommandLeavesBadSelection) {
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable>^<h1>H1</h1>ello|</div>"));
Selection().SetSelection(
SetSelectionTextToBody("<div contenteditable>^<h1>H1</h1>ello|</div>"),
SetSelectionOptions());
// This call shouldn't crash.
TypingCommand::InsertText(
......@@ -71,13 +73,15 @@ TEST_F(TypingCommandTest,
// crbug.com/794397
TEST_F(TypingCommandTest, ForwardDeleteInvalidatesSelection) {
GetDocument().setDesignMode("on");
Selection().SetSelectionAndEndTyping(SetSelectionTextToBody(
"<blockquote>^"
"<q>"
"<table contenteditable=\"false\"><colgroup width=\"-1\">\n</table>|"
"</q>"
"</blockquote>"
"<q>\n<svg></svg></q>"));
Selection().SetSelection(
SetSelectionTextToBody(
"<blockquote>^"
"<q>"
"<table contenteditable=\"false\"><colgroup width=\"-1\">\n</table>|"
"</q>"
"</blockquote>"
"<q>\n<svg></svg></q>"),
SetSelectionOptions());
EditingState editing_state;
TypingCommand::ForwardDeleteKeyPressed(GetDocument(), &editing_state);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment