Commit fbb37ade authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Add overloaded GetSelectionTextFromBody() to simplify code.

This change adds an overloaded GetSelectionTextFromBody() function in
EditingTestBase. It returns text of Selection().GetSelectionInDOMTree().
This can simplify the test code and improve code health.
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: I5548e4f168176a0e9921d2c4798fdf9126661b75
Reviewed-on: https://chromium-review.googlesource.com/1000655Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549135}
parent 18fb38eb
......@@ -121,7 +121,7 @@ TEST_F(ApplyBlockElementCommandTest, InsertPlaceHolderAtDisconnectedPosition) {
EXPECT_FALSE(command->Apply());
EXPECT_EQ(
"<pre>|<input></pre><input class=\"input\" style=\"position:absolute\">",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
} // namespace blink
......@@ -93,6 +93,6 @@ TEST_F(ApplyStyleCommandTest, FontSizeDeltaWithSpanElement) {
InputEvent::InputType::kNone)
->Apply();
EXPECT_EQ("<div contenteditable><div></div><span>^a|</span></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
} // namespace blink
......@@ -72,8 +72,7 @@ TEST_F(DeleteSelectionCommandTest, ForwardDeleteWithFirstLetter) {
.SetSanitizeMarkup(true)
.Build());
EXPECT_TRUE(command.Apply()) << "the delete command should have succeeded";
EXPECT_EQ("<p contenteditable>a|c</p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
EXPECT_EQ("<p contenteditable>a|c</p>", GetSelectionTextFromBody());
}
} // namespace blink
......@@ -65,7 +65,7 @@ TEST_F(InsertListCommandTest, UnlistifyParagraphCrashOnVisuallyEmptyParagraph) {
"<dl><ul>"
"|<textarea style=\"float:left;\"></textarea>"
"</ul></dl>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// Refer https://crbug.com/798176
......@@ -91,7 +91,7 @@ TEST_F(InsertListCommandTest, CleanupNodeSameAsDestinationNode) {
"<ul><li><br></li></ul>"
"</col></colgroup></table>"
"<button></button>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
TEST_F(InsertListCommandTest, InsertListOnEmptyHiddenElements) {
......@@ -108,7 +108,7 @@ TEST_F(InsertListCommandTest, InsertListOnEmptyHiddenElements) {
"<button>"
"|<ul><li><br></li></ul>"
"</button>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// Refer https://crbug.com/797520
......@@ -128,6 +128,6 @@ TEST_F(InsertListCommandTest, InsertListWithCollapsedVisibility) {
"<dl>"
"<ol></ol><ul>^a|</ul>"
"</dl>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
}
......@@ -29,7 +29,7 @@ TEST_F(InsertParagraphSeparatorCommandTest,
"<table contenteditable>"
" <colgroup style=\"-webkit-appearance:radio;\">|<br></colgroup>"
"</table>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// http://crbug.com/777378
......@@ -52,7 +52,7 @@ TEST_F(InsertParagraphSeparatorCommandTest,
" <col>"
" </colgroup>"
"</table>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
} // namespace blink
......@@ -39,7 +39,7 @@ TEST_F(InsertTextCommandTest, InsertChar) {
SetSelectionTextToBody("<p contenteditable><span>\ta|c</span></p>"));
GetDocument().execCommand("insertText", false, "B", ASSERT_NO_EXCEPTION);
EXPECT_EQ("<p contenteditable><span>\taB|c</span></p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()))
GetSelectionTextFromBody())
<< "We should not split Text node";
}
......@@ -54,7 +54,7 @@ TEST_F(InsertTextCommandTest, InsertCharToWhiteSpacePre) {
"B|"
"<span style=\"white-space:pre\">c</span>"
"</p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()))
GetSelectionTextFromBody())
<< "This is a just record current behavior. We should not split SPAN.";
}
......@@ -64,7 +64,7 @@ TEST_F(InsertTextCommandTest, InsertSpace) {
SetSelectionTextToBody("<p contenteditable><span>\ta|c</span></p>"));
GetDocument().execCommand("insertText", false, " ", ASSERT_NO_EXCEPTION);
EXPECT_EQ("<p contenteditable><span>\ta\xC2\xA0 |c</span></p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()))
GetSelectionTextFromBody())
<< "We should insert U+0020 without splitting SPAN";
}
......@@ -78,7 +78,7 @@ TEST_F(InsertTextCommandTest, InsertSpaceToWhiteSpacePre) {
"<span style=\"white-space:pre\">\ta</span>"
"\xC2\xA0\xC2\xA0|"
"<span style=\"white-space:pre\">c</span></p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()))
GetSelectionTextFromBody())
<< "We should insert U+0020 without splitting SPAN";
}
......@@ -91,7 +91,7 @@ TEST_F(InsertTextCommandTest, InsertTab) {
"<p contenteditable>"
"<span>\ta<span style=\"white-space:pre\">\t|</span>c</span>"
"</p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// http://crbug.com/741826
......@@ -101,7 +101,7 @@ TEST_F(InsertTextCommandTest, InsertTabToWhiteSpacePre) {
GetDocument().execCommand("insertText", false, "\t", ASSERT_NO_EXCEPTION);
EXPECT_EQ(
"<p contenteditable><span style=\"white-space:pre\">\ta\t|c</span></p>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// http://crbug.com/752860
......@@ -112,7 +112,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupBeforeParagraph) {
// The space after "qux" should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable>qux\xC2\xA0|<p>baz</p></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable>qux^ bar|<p>baz</p>"));
......@@ -120,7 +120,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupBeforeParagraph) {
// The newly-inserted space should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable>qux\xC2\xA0|<p>baz</p></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable>qux^bar| <p>baz</p>"));
......@@ -128,7 +128,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupBeforeParagraph) {
// The space after "bar" was already being collapsed before the edit. It
// should not have been converted to a no-break space.
EXPECT_EQ("<div contenteditable>qux|<p>baz</p></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable>qux^bar |<p>baz</p>"));
......@@ -136,7 +136,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupBeforeParagraph) {
// The newly-inserted space should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable>qux\xC2\xA0|<p>baz</p></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable>qux\t^bar|<p>baz</p>"));
......@@ -144,7 +144,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupBeforeParagraph) {
// The tab should have been converted to a no-break space (U+00A0) to prevent
// it from being collapsed.
EXPECT_EQ("<div contenteditable>qux\xC2\xA0|<p>baz</p></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
......@@ -154,7 +154,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
// The space before "qux" should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable><p>baz</p>|\xC2\xA0qux</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable><p>baz</p>^bar |qux"));
......@@ -162,7 +162,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
// The newly-inserted space should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable><p>baz</p>\xC2\xA0|qux</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable><p>baz</p> ^bar|qux"));
......@@ -170,7 +170,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
// The space before "bar" was already being collapsed before the edit. It
// should not have been converted to a no-break space.
EXPECT_EQ("<div contenteditable><p>baz</p>|qux</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable><p>baz</p>^ bar|qux"));
......@@ -178,7 +178,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
// The newly-inserted space should have been converted to a no-break space
// (U+00A0) to prevent it from being collapsed.
EXPECT_EQ("<div contenteditable><p>baz</p>\xC2\xA0|qux</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
Selection().SetSelectionAndEndTyping(
SetSelectionTextToBody("<div contenteditable><p>baz</p>^bar|\tqux"));
......@@ -186,7 +186,7 @@ TEST_F(InsertTextCommandTest, WhitespaceFixupAfterParagraph) {
// The tab should have been converted to a no-break space (U+00A0) to prevent
// it from being collapsed.
EXPECT_EQ("<div contenteditable><p>baz</p>|\xC2\xA0qux</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// http://crbug.com/779376
......@@ -212,7 +212,7 @@ TEST_F(InsertTextCommandTest, NoVisibleSelectionAfterDeletingSelection) {
" <navi></navi>"
" ^</strike></ruby>"
"|</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// http://crbug.com/778901
......@@ -277,7 +277,7 @@ TEST_F(InsertTextCommandTest, AnchorElementWithBlockCrash) {
"<i style=\"display: block;\">"
"<a href=\"www\" style=\"display: block;\">a</a>"
"</i>|",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
} // namespace blink
......@@ -171,8 +171,7 @@ TEST_F(ReplaceSelectionCommandTest, TrailingNonVisibleTextCrash) {
// Crash should not occur on applying ReplaceSelectionCommand
EXPECT_FALSE(command->Apply());
EXPECT_EQ("<div>bar</div>|<br>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
EXPECT_EQ("<div>bar</div>|<br>", GetSelectionTextFromBody());
}
// This is a regression test for https://crbug.com/796840
......@@ -185,8 +184,7 @@ TEST_F(ReplaceSelectionCommandTest, CrashWithNoSelection) {
// Crash should not occur on applying ReplaceSelectionCommand
EXPECT_FALSE(command->Apply());
EXPECT_EQ("<div></div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
EXPECT_EQ("<div></div>", GetSelectionTextFromBody());
}
} // namespace blink
......@@ -65,7 +65,7 @@ TEST_F(TypingCommandTest,
GetDocument(), " ", 0,
TypingCommand::TextCompositionType::kTextCompositionUpdate, true);
EXPECT_EQ("<div contenteditable>^<h1></h1>|</div>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
// crbug.com/794397
......@@ -90,7 +90,7 @@ TEST_F(TypingCommandTest, ForwardDeleteInvalidatesSelection) {
"</table>\n"
"<svg></svg>"
"</q>",
GetSelectionTextFromBody(Selection().GetSelectionInDOMTree()));
GetSelectionTextFromBody());
}
} // namespace blink
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/position.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/testing/selection_sample.h"
......@@ -71,6 +72,10 @@ std::string EditingTestBase::GetSelectionTextFromBody(
return SelectionSample::GetSelectionText(*GetDocument().body(), selection);
}
std::string EditingTestBase::GetSelectionTextFromBody() const {
return GetSelectionTextFromBody(Selection().GetSelectionInDOMTree());
}
std::string EditingTestBase::GetSelectionTextInFlatTreeFromBody(
const SelectionInFlatTree& selection) const {
return SelectionSample::GetSelectionTextInFlatTree(*GetDocument().body(),
......
......@@ -58,6 +58,8 @@ class EditingTestBase : public PageTestBase {
// |SelectionInDOMTree|.
std::string GetSelectionTextFromBody(const SelectionInDOMTree&) const;
std::string GetSelectionTextFromBody() const;
// Returns selection text for child nodes of BODY with specified
// |SelectionInFlatTree|.
std::string GetSelectionTextInFlatTreeFromBody(
......
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