File: RenderMultiColumnFlowThreadTest.cpp

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (262 lines) | stat: -rw-r--r-- 14,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "core/rendering/RenderMultiColumnFlowThread.h"

#include "core/rendering/RenderMultiColumnSet.h"
#include "core/rendering/RenderMultiColumnSpannerPlaceholder.h"
#include "core/rendering/RenderingTestHelper.h"

#include <gtest/gtest.h>

namespace blink {

namespace {

class MultiColumnRenderingTest : public RenderingTest {
public:
    RenderMultiColumnFlowThread* findFlowThread(const char* id) const;

    // Generate a signature string based on what kind of column boxes the flow thread has
    // established. 'c' is used for regular column content sets, while 's' is used for spanners.
    // '?' is used when there's an unknown box type (which should be considered a failure).
    String columnSetSignature(RenderMultiColumnFlowThread*);
    String columnSetSignature(const char* multicolId);

    void setMulticolHTML(const String&);
};

RenderMultiColumnFlowThread* MultiColumnRenderingTest::findFlowThread(const char* id) const
{
    Node* multicol = document().getElementById(id);
    if (!multicol)
        return 0;
    RenderBlockFlow* multicolContainer = toRenderBlockFlow(multicol->renderer());
    if (!multicolContainer)
        return 0;
    return multicolContainer->multiColumnFlowThread();
}

String MultiColumnRenderingTest::columnSetSignature(RenderMultiColumnFlowThread* flowThread)
{
    String signature = "";
    for (RenderBox* columnBox = flowThread->firstMultiColumnBox();
        columnBox;
        columnBox = columnBox->nextSiblingMultiColumnBox()) {
        if (columnBox->isRenderMultiColumnSpannerPlaceholder())
            signature.append('s');
        else if (columnBox->isRenderMultiColumnSet())
            signature.append('c');
        else
            signature.append('?');
    }
    return signature;
}

String MultiColumnRenderingTest::columnSetSignature(const char* multicolId)
{
    return columnSetSignature(findFlowThread(multicolId));
}

void MultiColumnRenderingTest::setMulticolHTML(const String& html)
{
    const char* style =
        "<style>"
        "  #mc { -webkit-columns:2; }"
        "  .s, #spanner, #spanner1, #spanner2 { -webkit-column-span:all; }"
        "</style>";
    setBodyInnerHTML(style + html);
}

TEST_F(MultiColumnRenderingTest, OneBlockWithInDepthTreeStructureCheck)
{
    // Examine the render tree established by a simple multicol container with a block with some text inside.
    setMulticolHTML("<div id='mc'><div>xxx</div></div>");
    Node* multicol = document().getElementById("mc");
    ASSERT_TRUE(multicol);
    RenderBlockFlow* multicolContainer = toRenderBlockFlow(multicol->renderer());
    ASSERT_TRUE(multicolContainer);
    RenderMultiColumnFlowThread* flowThread = multicolContainer->multiColumnFlowThread();
    ASSERT_TRUE(flowThread);
    EXPECT_EQ(columnSetSignature(flowThread), "c");
    EXPECT_EQ(flowThread->parent(), multicolContainer);
    EXPECT_FALSE(flowThread->previousSibling());
    RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
    ASSERT_TRUE(columnSet);
    EXPECT_EQ(columnSet->previousSibling(), flowThread);
    EXPECT_FALSE(columnSet->nextSibling());
    RenderBlockFlow* block = toRenderBlockFlow(flowThread->firstChild());
    ASSERT_TRUE(block);
    EXPECT_FALSE(block->nextSibling());
    ASSERT_TRUE(block->firstChild());
    EXPECT_TRUE(block->firstChild()->isText());
    EXPECT_FALSE(block->firstChild()->nextSibling());
}

TEST_F(MultiColumnRenderingTest, Empty)
{
    // If there's no column content, there should be no column set.
    setMulticolHTML("<div id='mc'></div>");
    EXPECT_EQ(columnSetSignature("mc"), "");
}

TEST_F(MultiColumnRenderingTest, OneBlock)
{
    // There is some content, so we should create a column set.
    setMulticolHTML("<div id='mc'><div id='block'></div></div>");
    ASSERT_EQ(columnSetSignature("mc"), "c");
}

TEST_F(MultiColumnRenderingTest, TwoBlocks)
{
    // No matter how much content, we should only create one column set (unless there are spanners).
    setMulticolHTML("<div id='mc'><div id='block1'></div><div id='block2'></div></div>");
    ASSERT_EQ(columnSetSignature("mc"), "c");
}

TEST_F(MultiColumnRenderingTest, Spanner)
{
    // With one spanner and no column content, we should create a spanner set.
    setMulticolHTML("<div id='mc'><div id='spanner'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "s");
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->firstMultiColumnSet(), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner")->renderer()->spannerPlaceholder(), columnBox);
}

TEST_F(MultiColumnRenderingTest, ContentThenSpanner)
{
    // With some column content followed by a spanner, we need a column set followed by a spanner set.
    setMulticolHTML("<div id='mc'><div id='columnContent'></div><div id='spanner'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "cs");
    RenderBox* columnBox = flowThread->lastMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("columnContent")->renderer()), nullptr);
}

TEST_F(MultiColumnRenderingTest, SpannerThenContent)
{
    // With a spanner followed by some column content, we need a spanner set followed by a column set.
    setMulticolHTML("<div id='mc'><div id='spanner'></div><div id='columnContent'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "sc");
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("columnContent")->renderer()), nullptr);
}

TEST_F(MultiColumnRenderingTest, ContentThenSpannerThenContent)
{
    // With column content followed by a spanner followed by some column content, we need a column
    // set followed by a spanner set followed by a column set.
    setMulticolHTML("<div id='mc'><div id='columnContentBefore'></div><div id='spanner'></div><div id='columnContentAfter'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "csc");
    RenderBox* columnBox = flowThread->firstMultiColumnSet()->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("columnContentBefore")->renderer()), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("columnContentAfter")->renderer()), nullptr);
}

TEST_F(MultiColumnRenderingTest, TwoSpanners)
{
    // With two spanners and no column content, we need two spanner sets.
    setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='spanner2'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "ss");
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->firstMultiColumnSet(), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner1")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner1")->renderer()->spannerPlaceholder(), columnBox);
    columnBox = columnBox->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner2")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner2")->renderer()->spannerPlaceholder(), columnBox);
}

TEST_F(MultiColumnRenderingTest, SpannerThenContentThenSpanner)
{
    // With two spanners and some column content in-between, we need a spanner set, a column set and another spanner set.
    setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='columnContent'></div><div id='spanner2'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "scs");
    RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
    EXPECT_EQ(columnSet->nextSiblingMultiColumnSet(), nullptr);
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner1")->renderer()), columnBox);
    columnBox = columnBox->nextSiblingMultiColumnBox();
    EXPECT_EQ(columnBox, columnSet);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("columnContent")->renderer()), nullptr);
    columnBox = columnBox->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner2")->renderer()), columnBox);
}

TEST_F(MultiColumnRenderingTest, SpannerWithSpanner)
{
    // column-span:all on something inside column-span:all has no effect.
    setMulticolHTML("<div id='mc'><div id='spanner'><div id='invalidSpanner' class='s'></div></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    ASSERT_EQ(columnSetSignature(flowThread), "s");
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("invalidSpanner")->renderer()), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner")->renderer());
    EXPECT_EQ(document().getElementById("spanner")->renderer()->spannerPlaceholder(), columnBox);
    EXPECT_EQ(document().getElementById("invalidSpanner")->renderer()->spannerPlaceholder(), nullptr);
}

TEST_F(MultiColumnRenderingTest, SubtreeWithSpanner)
{
    setMulticolHTML("<div id='mc'><div id='outer'><div id='block1'></div><div id='spanner'></div><div id='block2'></div></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    EXPECT_EQ(columnSetSignature(flowThread), "csc");
    RenderBox* columnBox = flowThread->firstMultiColumnSet()->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner")->renderer()->spannerPlaceholder(), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner")->renderer());
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("outer")->renderer()), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("block1")->renderer()), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("block2")->renderer()), nullptr);
}

TEST_F(MultiColumnRenderingTest, SubtreeWithSpannerAfterSpanner)
{
    setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='outer'>text<div id='spanner2'></div><div id='after'></div></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    EXPECT_EQ(columnSetSignature(flowThread), "scsc");
    RenderBox* columnBox = flowThread->firstMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner1")->renderer()), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner1")->renderer());
    EXPECT_EQ(document().getElementById("spanner1")->renderer()->spannerPlaceholder(), columnBox);
    columnBox = columnBox->nextSiblingMultiColumnBox()->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner2")->renderer()), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner2")->renderer());
    EXPECT_EQ(document().getElementById("spanner2")->renderer()->spannerPlaceholder(), columnBox);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("outer")->renderer()), nullptr);
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("after")->renderer()), nullptr);
}

TEST_F(MultiColumnRenderingTest, SubtreeWithSpannerBeforeSpanner)
{
    setMulticolHTML("<div id='mc'><div id='outer'>text<div id='spanner1'></div>text</div><div id='spanner2'></div></div>");
    RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
    EXPECT_EQ(columnSetSignature(flowThread), "cscs");
    RenderBox* columnBox = flowThread->firstMultiColumnSet()->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner1")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner1")->renderer()->spannerPlaceholder(), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner1")->renderer());
    columnBox = columnBox->nextSiblingMultiColumnBox()->nextSiblingMultiColumnBox();
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("spanner2")->renderer()), columnBox);
    EXPECT_EQ(document().getElementById("spanner2")->renderer()->spannerPlaceholder(), columnBox);
    EXPECT_EQ(toRenderMultiColumnSpannerPlaceholder(columnBox)->rendererInFlowThread(), document().getElementById("spanner2")->renderer());
    EXPECT_EQ(flowThread->containingColumnSpannerPlaceholder(document().getElementById("outer")->renderer()), nullptr);
}

} // anonymous namespace

} // namespace blink