Commit 0f115ef6 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[FragmentItem] Add tests for NGFragmentItems-rooted cursors

r795011 crrev.com/c/2313736 added tests for:
* Enumerate all fragments for a |LayoutObject| across
  fragmentainers.
* Enumerate all fragments for a |LayoutObject| within a
  specified item (line).
but did not cover the case:
* Enumerate all fragments for a |LayoutObject| within a
  specified fragmentainer (NGFragmentItems).

This patch extends the tests to cover the last case.

Bug: 1112657
Change-Id: Ia559421a09451c902c35f58346391666749da73e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340405Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795342}
parent 3c845ceb
...@@ -1016,8 +1016,8 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject { ...@@ -1016,8 +1016,8 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
wtf_size_t Size() const { return layout_results_.size(); } wtf_size_t Size() const { return layout_results_.size(); }
bool IsEmpty() const { return layout_results_.IsEmpty(); } bool IsEmpty() const { return layout_results_.IsEmpty(); }
class Iterator : public std::iterator<std::forward_iterator_tag, class CORE_EXPORT Iterator : public std::iterator<std::forward_iterator_tag,
NGPhysicalBoxFragment> { NGPhysicalBoxFragment> {
public: public:
explicit Iterator(const NGLayoutResultList::const_iterator& iterator) explicit Iterator(const NGLayoutResultList::const_iterator& iterator)
: iterator_(iterator) {} : iterator_(iterator) {}
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_item.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_item.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node_data.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node_data.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h" #include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
namespace blink { namespace blink {
...@@ -1124,54 +1125,80 @@ TEST_F(NGInlineCursorBlockFragmentationTest, MoveToLayoutObject) { ...@@ -1124,54 +1125,80 @@ TEST_F(NGInlineCursorBlockFragmentationTest, MoveToLayoutObject) {
// Line-ranged cursors can find fragments only in the line. // Line-ranged cursors can find fragments only in the line.
// The 1st line has "1111", from "text1". // The 1st line has "1111", from "text1".
NGInlineCursor cursor(*span1->FragmentItemsContainer()); const LayoutBlockFlow* block_flow = span1->FragmentItemsContainer();
NGInlineCursor cursor(*block_flow);
EXPECT_TRUE(cursor.Current().IsLineBox()); EXPECT_TRUE(cursor.Current().IsLineBox());
NGInlineCursor line1 = cursor.CursorForDescendants(); NGInlineCursor line1 = cursor.CursorForDescendants();
line1.MoveTo(*text1); const auto TestFragment1 = [&](const NGInlineCursor& initial_cursor) {
EXPECT_THAT(LayoutObjectToDebugStringList(line1), ElementsAre("1111")); NGInlineCursor cursor = initial_cursor;
line1 = cursor.CursorForDescendants(); cursor.MoveTo(*text1);
line1.MoveToIncludingCulledInline(*span1); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("1111"));
EXPECT_THAT(LayoutObjectToDebugStringList(line1), ElementsAre("1111")); cursor = initial_cursor;
line1 = cursor.CursorForDescendants(); cursor.MoveToIncludingCulledInline(*span1);
line1.MoveTo(*text2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("1111"));
EXPECT_THAT(LayoutObjectToDebugStringList(line1), ElementsAre()); cursor = initial_cursor;
line1 = cursor.CursorForDescendants(); cursor.MoveTo(*text2);
line1.MoveToIncludingCulledInline(*span2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre());
EXPECT_THAT(LayoutObjectToDebugStringList(line1), ElementsAre()); cursor = initial_cursor;
cursor.MoveToIncludingCulledInline(*span2);
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre());
};
TestFragment1(line1);
// The 2nd line has "22" from "text1" and "33" from text2. // The 2nd line has "22" from "text1" and "33" from text2.
cursor.MoveToNextFragmentainer(); cursor.MoveToNextFragmentainer();
EXPECT_TRUE(cursor); EXPECT_TRUE(cursor);
EXPECT_TRUE(cursor.Current().IsLineBox()); EXPECT_TRUE(cursor.Current().IsLineBox());
NGInlineCursor line2 = cursor.CursorForDescendants(); NGInlineCursor line2 = cursor.CursorForDescendants();
line2.MoveTo(*text1); const auto TestFragment2 = [&](const NGInlineCursor& initial_cursor) {
EXPECT_THAT(LayoutObjectToDebugStringList(line2), ElementsAre("22")); NGInlineCursor cursor = initial_cursor;
line2 = cursor.CursorForDescendants(); cursor.MoveTo(*text1);
line2.MoveToIncludingCulledInline(*span1); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("22"));
EXPECT_THAT(LayoutObjectToDebugStringList(line2), ElementsAre("22")); cursor = initial_cursor;
line2 = cursor.CursorForDescendants(); cursor.MoveToIncludingCulledInline(*span1);
line2.MoveTo(*text2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("22"));
EXPECT_THAT(LayoutObjectToDebugStringList(line2), ElementsAre("33")); cursor = initial_cursor;
line2 = cursor.CursorForDescendants(); cursor.MoveTo(*text2);
line2.MoveToIncludingCulledInline(*span2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("33"));
EXPECT_THAT(LayoutObjectToDebugStringList(line2), ElementsAre("33")); cursor = initial_cursor;
cursor.MoveToIncludingCulledInline(*span2);
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("33"));
};
TestFragment2(line2);
// The 3rd line has "4444" from text2. // The 3rd line has "4444" from text2.
cursor.MoveToNextFragmentainer(); cursor.MoveToNextFragmentainer();
EXPECT_TRUE(cursor); EXPECT_TRUE(cursor);
EXPECT_TRUE(cursor.Current().IsLineBox()); EXPECT_TRUE(cursor.Current().IsLineBox());
NGInlineCursor line3 = cursor.CursorForDescendants(); NGInlineCursor line3 = cursor.CursorForDescendants();
line3.MoveTo(*text1); const auto TestFragment3 = [&](const NGInlineCursor& initial_cursor) {
EXPECT_THAT(LayoutObjectToDebugStringList(line3), ElementsAre()); NGInlineCursor cursor = initial_cursor;
line3 = cursor.CursorForDescendants(); cursor.MoveTo(*text1);
line3.MoveToIncludingCulledInline(*span1); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre());
EXPECT_THAT(LayoutObjectToDebugStringList(line3), ElementsAre()); cursor = initial_cursor;
line3 = cursor.CursorForDescendants(); cursor.MoveToIncludingCulledInline(*span1);
line3.MoveTo(*text2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre());
EXPECT_THAT(LayoutObjectToDebugStringList(line3), ElementsAre("4444")); cursor = initial_cursor;
line3 = cursor.CursorForDescendants(); cursor.MoveTo(*text2);
line3.MoveToIncludingCulledInline(*span2); EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("4444"));
EXPECT_THAT(LayoutObjectToDebugStringList(line3), ElementsAre("4444")); cursor = initial_cursor;
cursor.MoveToIncludingCulledInline(*span2);
EXPECT_THAT(LayoutObjectToDebugStringList(cursor), ElementsAre("4444"));
};
TestFragment3(line3);
// Test cursors rooted at |NGFragmentItems|.
// They can enumerate fragments only in the specified fragmentainer.
Vector<const NGFragmentItems*> fragment_items_list;
for (const NGPhysicalBoxFragment& fragment :
block_flow->PhysicalFragments()) {
fragment_items_list.push_back(fragment.Items());
DCHECK_NE(fragment_items_list.back(), nullptr);
}
EXPECT_EQ(fragment_items_list.size(), 3u);
TestFragment1(NGInlineCursor(*fragment_items_list[0]));
TestFragment2(NGInlineCursor(*fragment_items_list[1]));
TestFragment3(NGInlineCursor(*fragment_items_list[2]));
} }
} // namespace } // namespace
......
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