#include "third_party/blink/renderer/core/layout/layout_text.h"
#include <numeric>
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/dom/pseudo_element.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/position_with_affinity.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/testing/selection_sample.h"
#include "third_party/blink/renderer/core/layout/inline/inline_node_data.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/testing/font_test_helpers.h"
namespace blink {
ElementsAre;
namespace {
class LayoutTextTest : public RenderingTest { … };
}
#if BUILDFLAG(IS_WIN)
TEST_F(LayoutTextTest, PrewarmFamily) {
test::ScopedTestFontPrewarmer prewarmer;
SetBodyInnerHTML(R"HTML(
<style>
#container { font-family: testfont; }
</style>
<div id="container">text</div>
)HTML");
EXPECT_THAT(prewarmer.PrewarmedFamilyNames(), ElementsAre("testfont"));
LayoutObject* container = GetLayoutObjectByElementId("container");
EXPECT_TRUE(container->StyleRef()
.GetFont()
.GetFontDescription()
.Family()
.IsPrewarmed());
}
TEST_F(LayoutTextTest, PrewarmFontFace) {
test::ScopedTestFontPrewarmer prewarmer;
SetBodyInnerHTML(R"HTML(
<style>
@font-face {
font-family: testfont;
src: local(Arial);
}
#container { font-family: testfont; }
</style>
<div id="container">text</div>
)HTML");
EXPECT_THAT(prewarmer.PrewarmedFamilyNames(), ElementsAre());
LayoutObject* container = GetLayoutObjectByElementId("container");
EXPECT_FALSE(container->StyleRef()
.GetFont()
.GetFontDescription()
.Family()
.IsPrewarmed());
}
TEST_F(LayoutTextTest, PrewarmGenericFamily) {
test::ScopedTestFontPrewarmer prewarmer;
SetBodyInnerHTML(R"HTML(
<style>
#container { font-family: serif; }
</style>
<div id="container">text</div>
)HTML");
EXPECT_THAT(prewarmer.PrewarmedFamilyNames(), ElementsAre());
LayoutObject* container = GetLayoutObjectByElementId("container");
EXPECT_TRUE(container->StyleRef()
.GetFont()
.GetFontDescription()
.Family()
.IsPrewarmed());
}
#endif
struct OffsetMappingTestData { … } offset_mapping_test_data[] = …;
std::ostream& operator<<(std::ostream& out, OffsetMappingTestData data) { … }
class MapDOMOffsetToTextContentOffset
: public LayoutTextTest,
public testing::WithParamInterface<OffsetMappingTestData> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(MapDOMOffsetToTextContentOffset, Basic) { … }
TEST_F(LayoutTextTest, CharacterAfterWhitespaceCollapsing) { … }
TEST_F(LayoutTextTest, CaretMinMaxOffset) { … }
TEST_F(LayoutTextTest, ResolvedTextLength) { … }
TEST_F(LayoutTextTest, ContainsCaretOffset) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetInPre) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetInPreLine) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetWithTrailingSpace) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetWithTrailingSpace1) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetWithTrailingSpace2) { … }
TEST_F(LayoutTextTest, ContainsCaretOffsetWithTrailingSpace3) { … }
TEST_F(LayoutTextTest, GetTextBoxInfoWithCollapsedWhiteSpace) { … }
TEST_F(LayoutTextTest, GetTextBoxInfoWithGeneratedContent) { … }
TEST_F(LayoutTextTest, GetTextBoxInfoWithHidden) { … }
TEST_F(LayoutTextTest, GetTextBoxInfoWithEllipsis) { … }
TEST_F(LayoutTextTest, GetTextBoxInfoWithEllipsisForPseudoAfter) { … }
TEST_F(LayoutTextTest, PlainTextInPseudo) { … }
TEST_F(LayoutTextTest, IsBeforeAfterNonCollapsedCharacterNoLineWrap) { … }
TEST_F(LayoutTextTest, IsBeforeAfterNonCollapsedLineWrapSpace) { … }
TEST_F(LayoutTextTest, IsBeforeAfterNonCollapsedCharacterBR) { … }
TEST_F(LayoutTextTest, AbsoluteQuads) { … }
TEST_F(LayoutTextTest, AbsoluteQuadsVRL) { … }
TEST_F(LayoutTextTest, PhysicalLinesBoundingBox) { … }
TEST_F(LayoutTextTest, PhysicalLinesBoundingBoxTextCombine) { … }
TEST_F(LayoutTextTest, PhysicalLinesBoundingBoxVerticalRL) { … }
TEST_F(LayoutTextTest, WordBreakElement) { … }
TEST_F(LayoutTextTest, LocalSelectionRect) { … }
TEST_F(LayoutTextTest, LocalSelectionRectLineBreak) { … }
TEST_F(LayoutTextTest, LocalSelectionRectLineBreakPre) { … }
TEST_F(LayoutTextTest, LocalSelectionRectRTL) { … }
TEST_F(LayoutTextTest, LocalSelectionRectVertical) { … }
TEST_F(LayoutTextTest, LocalSelectionRectVerticalRTL) { … }
TEST_F(LayoutTextTest, LocalSelectionRectLineHeight) { … }
TEST_F(LayoutTextTest, LocalSelectionRectNegativeLeading) { … }
TEST_F(LayoutTextTest, LocalSelectionRectLineHeightVertical) { … }
TEST_F(LayoutTextTest, VisualRectInDocumentSVGTspan) { … }
TEST_F(LayoutTextTest, VisualRectInDocumentSVGTspanTB) { … }
TEST_F(LayoutTextTest, PositionForPointAtLeading) { … }
TEST_F(LayoutTextTest, FloatFirstLetterPlainText) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetAppendBidi) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetAppendControl) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetAppendCollapseWhiteSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetAppend) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetAppendEmojiWithZWJ) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDelete) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteCollapseWhiteSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteCollapseWhiteSpaceEnd) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetCopyItemBefore) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteNbspInPreWrap) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteRTL) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteRTL2) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteThenNonCollapse) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteThenNonCollapse2) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteWithBidiControl) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetDeleteWithGeneratedBreakOpportunity) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetEditingTextCollapsedSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetInsert) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetInsertAfterSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetInserBeforetSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetInsertSameCharacters) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetNoRelocation) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetPrepend) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetReplace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetReplaceCollapseWhiteSpace) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetReplaceToExtend) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetReplaceToShrink) { … }
TEST_F(LayoutTextTest, SetTextWithOffsetToEmpty) { … }
}