Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: Source/core/rendering/RenderMultiColumnFlowThreadTest.cpp

Issue 688703003: [New Multicolumn] Add RenderMultiColumnSpannerSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase master Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "core/rendering/RenderMultiColumnFlowThread.h"
8
9 #include "core/rendering/RenderMultiColumnSet.h"
10 #include "core/rendering/RenderMultiColumnSpannerSet.h"
11 #include "core/rendering/RenderingTestHelper.h"
12
13 #include <gtest/gtest.h>
14
15 namespace blink {
16
17 namespace {
18
19 class MultiColumnRenderingTest : public RenderingTest {
20 public:
21 RenderMultiColumnFlowThread* findFlowThread(const char* id) const;
22
23 // Generate a signature string based on what kind of column sets the flow th read has
24 // established. There will be one character for each column set. 'c' is used for regular column
25 // content sets, while 's' is used for spanner sets.
26 String columnSetSignature(RenderMultiColumnFlowThread*);
27 String columnSetSignature(const char* multicolId);
Julien - ping for review 2014/11/05 16:52:39 The signature based check saves quite some code bu
mstensho (USE GERRIT) 2014/11/05 21:43:06 For some of the tests that we currently have, colu
28
29 void setMulticolHTML(const String&);
30 };
31
32 RenderMultiColumnFlowThread* MultiColumnRenderingTest::findFlowThread(const char * id) const
33 {
34 Node* multicol = document().getElementById(id);
35 if (!multicol)
36 return 0;
37 RenderBlockFlow* multicolContainer = toRenderBlockFlow(multicol->renderer()) ;
38 if (!multicolContainer)
39 return 0;
40 return multicolContainer->multiColumnFlowThread();
41 }
42
43 String MultiColumnRenderingTest::columnSetSignature(RenderMultiColumnFlowThread* flowThread)
44 {
45 String signature = "";
46 for (RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet(); co lumnSet; columnSet = columnSet->nextSiblingMultiColumnSet()) {
47 if (columnSet->isRenderMultiColumnSpannerSet())
48 signature.append('s');
49 else
50 signature.append('c');
51 }
52 return signature;
53 }
54
55 String MultiColumnRenderingTest::columnSetSignature(const char* multicolId)
56 {
57 return columnSetSignature(findFlowThread(multicolId));
58 }
59
60 void MultiColumnRenderingTest::setMulticolHTML(const String& html)
61 {
62 const char* style =
63 "<style>"
64 " #mc { -webkit-columns:2; }"
65 " .s, #spanner, #spanner1, #spanner2 { -webkit-column-span:all; }"
66 "</style>";
67 setBodyInnerHTML(style + html);
68 }
69
70 TEST_F(MultiColumnRenderingTest, BasicSanityTest)
Julien - ping for review 2014/11/05 16:52:39 There is quite some overlap with the other tests,
mstensho (USE GERRIT) 2014/11/05 21:43:06 Done.
71 {
72 // Examine the render tree established by a simple multicol container with a block with some text inside.
73 setMulticolHTML("<div id='mc'><div>xxx</div></div>");
74 Node* multicol = document().getElementById("mc");
75 ASSERT_TRUE(multicol);
76 RenderBlockFlow* multicolContainer = toRenderBlockFlow(multicol->renderer()) ;
77 ASSERT_TRUE(multicolContainer);
78 RenderMultiColumnFlowThread* flowThread = multicolContainer->multiColumnFlow Thread();
79 ASSERT_TRUE(flowThread);
80 EXPECT_EQ(columnSetSignature(flowThread), "c");
81 EXPECT_EQ(flowThread->parent(), multicolContainer);
82 EXPECT_FALSE(flowThread->previousSibling());
83 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
84 ASSERT_TRUE(columnSet);
85 EXPECT_EQ(columnSet->previousSibling(), flowThread);
86 EXPECT_FALSE(columnSet->nextSibling());
87 RenderBlockFlow* block = toRenderBlockFlow(flowThread->firstChild());
88 ASSERT_TRUE(block);
89 EXPECT_FALSE(block->nextSibling());
90 ASSERT_TRUE(block->firstChild());
91 EXPECT_TRUE(block->firstChild()->isText());
92 EXPECT_FALSE(block->firstChild()->nextSibling());
93 }
94
95 TEST_F(MultiColumnRenderingTest, Empty)
96 {
97 // If there's no column content, there should be no column set.
98 setMulticolHTML("<div id='mc'></div>");
99 EXPECT_EQ(columnSetSignature("mc"), "");
100 }
101
102 TEST_F(MultiColumnRenderingTest, OneBlock)
103 {
104 // There is some content, so we should create a column set.
105 setMulticolHTML("<div id='mc'><div id='block'></div></div>");
106 ASSERT_EQ(columnSetSignature("mc"), "c");
107 }
108
109 TEST_F(MultiColumnRenderingTest, TwoBlocks)
110 {
111 // No matter how much content, we should only create one column set (unless there are spanners).
112 setMulticolHTML("<div id='mc'><div id='block1'></div><div id='block2'></div> </div>");
113 ASSERT_EQ(columnSetSignature("mc"), "c");
114 }
115
116 TEST_F(MultiColumnRenderingTest, Spanner)
117 {
118 // With one spanner and no column content, we should create a spanner set.
119 setMulticolHTML("<div id='mc'><div id='spanner'></div></div>");
120 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
121 ASSERT_EQ(columnSetSignature(flowThread), "s");
122 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
123 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
124 }
125
126 TEST_F(MultiColumnRenderingTest, ContentAndSpanner)
Julien - ping for review 2014/11/05 16:52:39 Maybe better name ContentThenSpanner or SpannerFol
mstensho (USE GERRIT) 2014/11/05 21:43:06 Done.
127 {
128 // With some column content followed by a spanner, we need a column set foll owed by a spanner set.
129 setMulticolHTML("<div id='mc'><div id='columnContent'></div><div id='spanner '></div></div>");
130 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
131 ASSERT_EQ(columnSetSignature(flowThread), "cs");
132 RenderMultiColumnSet* columnSet = flowThread->lastMultiColumnSet();
133 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
134 }
135
136 TEST_F(MultiColumnRenderingTest, SpannerAndContent)
137 {
138 // With a spanner followed by some column content, we need a spanner set fol lowed by a column set.
139 setMulticolHTML("<div id='mc'><div id='spanner'></div><div id='columnContent '></div></div>");
140 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
141 ASSERT_EQ(columnSetSignature(flowThread), "sc");
142 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
143 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
144 }
145
146 TEST_F(MultiColumnRenderingTest, ContentAndSpannerAndContent)
147 {
148 // With column content followed by a spanner followed by some column content , we need a column
149 // set followed by a spanner set followed by a column set.
150 setMulticolHTML("<div id='mc'><div id='columnContentBefore'></div><div id='s panner'></div><div id='columnContentAfter'></div></div>");
151 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
152 ASSERT_EQ(columnSetSignature(flowThread), "csc");
153 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet()->nextSib lingMultiColumnSet();
154 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
155 }
156
157 TEST_F(MultiColumnRenderingTest, TwoSpanners)
158 {
159 // With two spanners and no column content, we need two spanner sets.
160 setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='spanner2'></ div></div>");
161 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
162 ASSERT_EQ(columnSetSignature(flowThread), "ss");
163 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
164 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner1")->renderer()), columnSet);
165 columnSet = columnSet->nextSiblingMultiColumnSet();
166 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner2")->renderer()), columnSet);
167 }
168
169 TEST_F(MultiColumnRenderingTest, SpannerAndContentAndSpanner)
170 {
171 // With two spanners and some column content in-between, we need a spanner s et, a column set and another spanner set.
172 setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='columnConten t'></div><div id='spanner2'></div></div>");
173 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
174 ASSERT_EQ(columnSetSignature(flowThread), "scs");
175 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
176 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner1")->renderer()), columnSet);
177 columnSet = columnSet->nextSiblingMultiColumnSet()->nextSiblingMultiColumnSe t();
178 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner2")->renderer()), columnSet);
179 }
180
181 TEST_F(MultiColumnRenderingTest, SpannerWithSpanner)
182 {
183 // column-span:all on something inside column-span:all has no effect.
184 setMulticolHTML("<div id='mc'><div id='spanner'><div id='invalidSpanner' cla ss='s'></div></div></div>");
185 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
186 ASSERT_EQ(columnSetSignature(flowThread), "s");
187 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
188 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
189 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" invalidSpanner")->renderer()), columnSet);
190 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner")->renderer());
191 }
192
193 TEST_F(MultiColumnRenderingTest, SubtreeWithSpanner)
194 {
195 setMulticolHTML("<div id='mc'><div id='outer'><div id='block1'></div><div id ='spanner'></div><div id='block2'></div></div></div>");
196 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
197 EXPECT_EQ(columnSetSignature(flowThread), "csc");
198 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet()->nextSib lingMultiColumnSet();
199 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner")->renderer()), columnSet);
200 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner")->renderer());
201 }
202
203 TEST_F(MultiColumnRenderingTest, SubtreeWithSpannerAfterSpanner)
204 {
205 setMulticolHTML("<div id='mc'><div id='spanner1'></div><div id='outer'>text< div id='spanner2'></div><div id='after'></div></div></div>");
206 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
207 EXPECT_EQ(columnSetSignature(flowThread), "scsc");
208 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet();
209 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner1")->renderer()), columnSet);
210 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner1")->renderer());
211 columnSet = columnSet->nextSiblingMultiColumnSet()->nextSiblingMultiColumnSe t();
212 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner2")->renderer()), columnSet);
213 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner2")->renderer());
214 }
215
216 TEST_F(MultiColumnRenderingTest, SubtreeWithSpannerBeforeSpanner)
217 {
218 setMulticolHTML("<div id='mc'><div id='outer'>text<div id='spanner1'></div>t ext</div><div id='spanner2'></div></div>");
219 RenderMultiColumnFlowThread* flowThread = findFlowThread("mc");
220 EXPECT_EQ(columnSetSignature(flowThread), "cscs");
221 RenderMultiColumnSet* columnSet = flowThread->firstMultiColumnSet()->nextSib lingMultiColumnSet();
222 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner1")->renderer()), columnSet);
223 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner1")->renderer());
224 columnSet = columnSet->nextSiblingMultiColumnSet()->nextSiblingMultiColumnSe t();
225 EXPECT_EQ(flowThread->containingColumnSpannerSet(document().getElementById(" spanner2")->renderer()), columnSet);
226 EXPECT_EQ(toRenderMultiColumnSpannerSet(columnSet)->rendererInFlowThread(), document().getElementById("spanner2")->renderer());
227 }
228
229 } // anonymous namespace
230
231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698