Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / tests / LayoutGeometryMapTest.cpp
blob559612e0f5b9d3b668f020ed7d0a96d5701e38f2
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "config.h"
32 #include "core/layout/LayoutGeometryMap.h"
34 #include "core/dom/Document.h"
35 #include "core/layout/LayoutBox.h"
36 #include "core/paint/DeprecatedPaintLayer.h"
37 #include "platform/testing/URLTestHelpers.h"
38 #include "public/platform/Platform.h"
39 #include "public/platform/WebUnitTestSupport.h"
40 #include "public/web/WebFrameClient.h"
41 #include "web/WebLocalFrameImpl.h"
42 #include "web/tests/FrameTestHelpers.h"
43 #include <gtest/gtest.h>
45 namespace blink {
47 class MockWebFrameClient : public WebFrameClient {
50 class LayoutGeometryMapTest : public testing::Test {
51 public:
52 LayoutGeometryMapTest()
53 : m_baseURL("http://www.test.com/")
57 void TearDown() override
59 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
62 protected:
63 static LayoutBox* getFrameElement(const char* iframeName, WebView* webView, const WTF::AtomicString& elementId)
65 WebLocalFrameImpl* iframe = toWebLocalFrameImpl(webView->findFrameByName(WebString::fromUTF8(iframeName)));
66 if (!iframe)
67 return nullptr;
68 LocalFrame* frame = iframe->frame();
69 Document* doc = frame->document();
70 Element* element = doc->getElementById(elementId);
71 if (!element)
72 return nullptr;
73 return element->layoutBox();
76 static LayoutBox* getLayoutBox(WebView* webView, const WTF::AtomicString& elementId)
78 WebViewImpl* webViewImpl = toWebViewImpl(webView);
79 if (!webViewImpl)
80 return nullptr;
81 LocalFrame* frame = webViewImpl->mainFrameImpl()->frame();
82 Document* doc = frame->document();
83 Element* element = doc->getElementById(elementId);
84 if (!element)
85 return nullptr;
86 return element->layoutBox();
89 static const LayoutBoxModelObject* getLayoutContainer(WebView* webView, const WTF::AtomicString &elementId)
91 LayoutBox* rb = getLayoutBox(webView, elementId);
92 if (!rb)
93 return nullptr;
94 DeprecatedPaintLayer* compositingLayer = rb->enclosingLayer()->enclosingLayerForPaintInvalidation();
95 if (!compositingLayer)
96 return nullptr;
97 return compositingLayer->layoutObject();
100 static const LayoutBoxModelObject* getFrameLayoutContainer(const char* frameId, WebView* webView, const WTF::AtomicString &elementId)
102 LayoutBox* rb = getFrameElement(frameId, webView, elementId);
103 if (!rb)
104 return nullptr;
105 DeprecatedPaintLayer* compositingLayer = rb->enclosingLayer()->enclosingLayerForPaintInvalidation();
106 if (!compositingLayer)
107 return nullptr;
108 return compositingLayer->layoutObject();
111 static const FloatRect rectFromQuad(const FloatQuad& quad)
113 FloatRect rect;
114 rect.setX(std::min(quad.p1().x(), std::min(quad.p2().x(), std::min(quad.p3().x(), quad.p4().x()))));
115 rect.setY(std::min(quad.p1().y(), std::min(quad.p2().y(), std::min(quad.p3().y(), quad.p4().y()))));
117 rect.setWidth(std::max(quad.p1().x(), std::max(quad.p2().x(), std::max(quad.p3().x(), quad.p4().x()))) - rect.x());
118 rect.setHeight(std::max(quad.p1().y(), std::max(quad.p2().y(), std::max(quad.p3().y(), quad.p4().y()))) - rect.y());
119 return rect;
122 void registerMockedHttpURLLoad(const std::string& fileName)
124 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str()));
127 const std::string m_baseURL;
128 MockWebFrameClient m_mockWebViewClient;
131 TEST_F(LayoutGeometryMapTest, SimpleGeometryMapTest)
133 registerMockedHttpURLLoad("rgm_test.html");
134 FrameTestHelpers::WebViewHelper webViewHelper;
135 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "rgm_test.html", true, 0, 0);
136 webView->resize(WebSize(1000, 1000));
137 webView->layout();
139 // We are going test everything twice. Once with FloatPoints and once with
140 // FloatRects. This is because LayoutGeometryMap treats both slightly
141 // differently
142 LayoutGeometryMap rgm;
143 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InitialDiv"), 0);
144 FloatPoint point;
145 FloatRect rect(0.0f, 0.0f, 1.0f, 2.0f);
146 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgm.mapToContainer(point, nullptr));
147 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, nullptr));
149 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
150 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgm.mapToContainer(point, nullptr));
151 EXPECT_EQ(FloatQuad(FloatRect(0.0f, 0.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, nullptr));
153 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InnerDiv"), 0);
154 EXPECT_EQ(FloatPoint(21.0f, 6.0f), rgm.mapToContainer(point, getLayoutBox(webView, "CenterDiv")));
155 EXPECT_EQ(FloatQuad(FloatRect(21.0f, 6.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getLayoutBox(webView, "CenterDiv")));
157 rgm.pushMappingsToAncestor(getLayoutBox(webView, "OtherDiv"), getLayoutBox(webView, "InnerDiv"));
158 EXPECT_EQ(FloatPoint(22.0f, 12.0f), rgm.mapToContainer(point, getLayoutBox(webView, "CenterDiv")));
159 EXPECT_EQ(FloatQuad(FloatRect(22.0f, 12.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getLayoutBox(webView, "CenterDiv")));
161 EXPECT_EQ(FloatPoint(1.0f, 6.0f), rgm.mapToContainer(point, getLayoutBox(webView, "InnerDiv")));
162 EXPECT_EQ(FloatQuad(FloatRect(1.0f, 6.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getLayoutBox(webView, "InnerDiv")));
164 EXPECT_EQ(FloatPoint(50.0f, 44.0f), rgm.mapToContainer(point, nullptr));
165 EXPECT_EQ(FloatQuad(FloatRect(50.0f, 44.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, nullptr));
168 // Fails on Windows due to crbug.com/391457. When run through the transform the
169 // position on windows differs by a pixel
170 #if OS(WIN)
171 TEST_F(LayoutGeometryMapTest, DISABLED_TransformedGeometryTest)
172 #else
173 TEST_F(LayoutGeometryMapTest, TransformedGeometryTest)
174 #endif
176 registerMockedHttpURLLoad("rgm_transformed_test.html");
177 FrameTestHelpers::WebViewHelper webViewHelper;
178 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "rgm_transformed_test.html", true, 0, 0);
179 webView->resize(WebSize(1000, 1000));
180 webView->layout();
182 LayoutGeometryMap rgm;
183 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InitialDiv"), 0);
184 FloatPoint point;
185 const float rectWidth = 15.0f;
186 const float scaleWidth = 2.0f;
187 const float scaleHeight = 3.0f;
188 FloatRect rect(0.0f, 0.0f, 15.0f, 25.0f);
189 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgm.mapToContainer(point, nullptr));
190 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 15.0f, 25.0f)), rgm.mapToContainer(rect, nullptr));
192 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
193 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgm.mapToContainer(point, nullptr));
194 EXPECT_EQ(FloatQuad(FloatRect(0.0f, 0.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, nullptr).boundingBox());
196 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InnerDiv"), 0);
197 EXPECT_EQ(FloatPoint(523.0f, 6.0f), rgm.mapToContainer(point, getLayoutBox(webView, "CenterDiv")));
198 EXPECT_EQ(FloatQuad(FloatRect(523.0f - rectWidth, 6.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, getLayoutBox(webView, "CenterDiv")).boundingBox());
200 rgm.pushMappingsToAncestor(getLayoutBox(webView, "OtherDiv"), getLayoutBox(webView, "InnerDiv"));
201 EXPECT_EQ(FloatPoint(522.0f, 12.0f), rgm.mapToContainer(point, getLayoutBox(webView, "CenterDiv")));
202 EXPECT_EQ(FloatQuad(FloatRect(522.0f - rectWidth, 12.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, getLayoutBox(webView, "CenterDiv")).boundingBox());
204 EXPECT_EQ(FloatPoint(1.0f, 6.0f), rgm.mapToContainer(point, getLayoutBox(webView, "InnerDiv")));
205 EXPECT_EQ(FloatQuad(FloatRect(1.0f, 6.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, getLayoutBox(webView, "InnerDiv")).boundingBox());
207 EXPECT_EQ(FloatPoint(821.0f, 31.0f), rgm.mapToContainer(point, nullptr));
208 EXPECT_EQ(FloatQuad(FloatRect(821.0f - rectWidth * scaleWidth, 31.0f, 15.0f * scaleWidth, 25.0f * scaleHeight)).boundingBox(), rgm.mapToContainer(rect, nullptr).boundingBox());
210 point = FloatPoint(10.0f, 25.0f);
211 rect = FloatRect(10.0f, 25.0f, 15.0f, 25.0f);
212 EXPECT_EQ(FloatPoint(512.0f, 37.0f), rgm.mapToContainer(point, getLayoutBox(webView, "CenterDiv")));
213 EXPECT_EQ(FloatQuad(FloatRect(512.0f - rectWidth, 37.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, getLayoutBox(webView, "CenterDiv")).boundingBox());
215 EXPECT_EQ(FloatPoint(11.0f, 31.0f), rgm.mapToContainer(point, getLayoutBox(webView, "InnerDiv")));
216 EXPECT_EQ(FloatQuad(FloatRect(11.0f, 31.0f, 15.0f, 25.0f)).boundingBox(), rgm.mapToContainer(rect, getLayoutBox(webView, "InnerDiv")).boundingBox());
218 EXPECT_EQ(FloatPoint(801.0f, 106.0f), rgm.mapToContainer(point, nullptr));
219 EXPECT_EQ(FloatQuad(FloatRect(801.0f - rectWidth * scaleWidth, 106.0f, 15.0f * scaleWidth, 25.0f * scaleHeight)).boundingBox(), rgm.mapToContainer(rect, nullptr).boundingBox());
222 TEST_F(LayoutGeometryMapTest, FixedGeometryTest)
224 registerMockedHttpURLLoad("rgm_fixed_position_test.html");
225 FrameTestHelpers::WebViewHelper webViewHelper;
226 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "rgm_fixed_position_test.html", true, 0, 0);
227 webView->resize(WebSize(1000, 1000));
228 webView->layout();
230 LayoutGeometryMap rgm;
231 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InitialDiv"), 0);
232 FloatPoint point;
233 FloatRect rect(0.0f, 0.0f, 15.0f, 25.0f);
234 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgm.mapToContainer(point, nullptr));
235 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 15.0f, 25.0f)), rgm.mapToContainer(rect, nullptr));
237 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
238 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgm.mapToContainer(point, nullptr));
239 EXPECT_EQ(FloatQuad(FloatRect(0.0f, 0.0f, 15.0f, 25.0f)), rgm.mapToContainer(rect, nullptr));
241 rgm.pushMappingsToAncestor(getLayoutBox(webView, "InnerDiv"), 0);
242 EXPECT_EQ(FloatPoint(20.0f, 14.0f), rgm.mapToContainer(point, getLayoutContainer(webView, "CenterDiv")));
243 EXPECT_EQ(FloatQuad(FloatRect(20.0f, 14.0f, 15.0f, 25.0f)), rgm.mapToContainer(rect, nullptr));
245 rgm.pushMappingsToAncestor(getLayoutBox(webView, "OtherDiv"), getLayoutBox(webView, "InnerDiv"));
246 EXPECT_EQ(FloatPoint(21.0f, 20.0f), rgm.mapToContainer(point, getLayoutContainer(webView, "CenterDiv")));
247 EXPECT_EQ(FloatQuad(FloatRect(21.0f, 20.0f, 15.0f, 25.0f)), rgm.mapToContainer(rect, getLayoutContainer(webView, "CenterDiv")));
249 EXPECT_EQ(FloatPoint(21.0f, 20.0f), rgm.mapToContainer(point, getLayoutContainer(webView, "InnerDiv")));
250 EXPECT_EQ(FloatPoint(21.0f, 20.0f), rgm.mapToContainer(point, nullptr));
252 point = FloatPoint(10.0f, 25.0f);
253 rect = FloatRect(22.0f, 15.2f, 15.3f, 0.0f);
254 EXPECT_EQ(FloatQuad(FloatRect(43.0f, 35.2f, 15.3f, 0.0f)), rgm.mapToContainer(rect, getLayoutContainer(webView, "CenterDiv")));
256 EXPECT_EQ(FloatPoint(31.0f, 45.0f), rgm.mapToContainer(point, getLayoutContainer(webView, "InnerDiv")));
257 EXPECT_EQ(FloatQuad(FloatRect(43.0f, 35.2f, 15.3f, 0.0f)), rgm.mapToContainer(rect, getLayoutContainer(webView, "InnerDiv")));
259 EXPECT_EQ(FloatPoint(31.0f, 45.0f), rgm.mapToContainer(point, nullptr));
260 EXPECT_EQ(FloatQuad(FloatRect(43.0f, 35.2f, 15.3f, 0.0f)), rgm.mapToContainer(rect, nullptr));
263 TEST_F(LayoutGeometryMapTest, IframeTest)
265 registerMockedHttpURLLoad("rgm_iframe_test.html");
266 registerMockedHttpURLLoad("rgm_test.html");
267 FrameTestHelpers::WebViewHelper webViewHelper;
268 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "rgm_iframe_test.html", true, 0, 0);
269 webView->resize(WebSize(1000, 1000));
270 webView->layout();
272 LayoutGeometryMap rgm(TraverseDocumentBoundaries);
273 LayoutGeometryMap rgmNoFrame;
275 rgmNoFrame.pushMappingsToAncestor(getFrameElement("test_frame", webView, "InitialDiv"), 0);
276 rgm.pushMappingsToAncestor(getFrameElement("test_frame", webView, "InitialDiv"), 0);
277 FloatPoint point;
278 FloatRect rect(0.0f, 0.0f, 1.0f, 2.0f);
280 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgmNoFrame.mapToContainer(point, nullptr));
281 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 1.0f, 2.0f)), rgmNoFrame.mapToContainer(rect, nullptr));
283 // Our initial rect looks like: (0, 0, 1, 2)
284 // p0_____
285 // | |
286 // | |
287 // | |
288 // |___|
289 // When we rotate we get a rect of the form:
290 // p0_
291 // / -_
292 // / /
293 // / /
294 // -_/
295 // So it is sensible that the minimum y is the same as for a point at 0, 0.
296 // The minimum x should be p0.x - 2 * sin(30deg) = p0.x - 1.
297 // That maximum x should likewise be p0.x + cos(30deg) = p0.x + 0.866.
298 // And the maximum y should be p0.x + sin(30deg) + 2*cos(30deg)
299 // = p0.y + 2.232.
300 EXPECT_NEAR(70.5244f, rgm.mapToContainer(point, nullptr).x(), 0.0001f);
301 EXPECT_NEAR(-44.0237f, rgm.mapToContainer(point, nullptr).y(), 0.0001f);
302 EXPECT_NEAR(69.5244f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).x(), 0.0001f);
303 EXPECT_NEAR(-44.0237, rectFromQuad(rgm.mapToContainer(rect, nullptr)).y(), 0.0001f);
304 EXPECT_NEAR(1.866, rectFromQuad(rgm.mapToContainer(rect, nullptr)).width(), 0.0001f);
305 EXPECT_NEAR(2.232, rectFromQuad(rgm.mapToContainer(rect, nullptr)).height(), 0.0001f);
307 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
308 rgmNoFrame.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
309 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgm.mapToContainer(point, nullptr));
310 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgmNoFrame.mapToContainer(point, nullptr));
312 rgm.pushMappingsToAncestor(getFrameElement("test_frame", webView, "InnerDiv"), 0);
313 rgmNoFrame.pushMappingsToAncestor(getFrameElement("test_frame", webView, "InnerDiv"), 0);
314 EXPECT_EQ(FloatPoint(21.0f, 6.0f), rgm.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
315 EXPECT_EQ(FloatQuad(FloatRect(21.0f, 6.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
316 EXPECT_EQ(FloatPoint(21.0f, 6.0f), rgmNoFrame.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
317 EXPECT_EQ(FloatQuad(FloatRect(21.0f, 6.0f, 1.0f, 2.0f)), rgmNoFrame.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
319 rgm.pushMappingsToAncestor(getFrameElement("test_frame", webView, "OtherDiv"), getFrameLayoutContainer("test_frame", webView, "InnerDiv"));
320 rgmNoFrame.pushMappingsToAncestor(getFrameElement("test_frame", webView, "OtherDiv"), getFrameLayoutContainer("test_frame", webView, "InnerDiv"));
321 EXPECT_EQ(FloatPoint(22.0f, 12.0f), rgm.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
322 EXPECT_EQ(FloatQuad(FloatRect(22.0f, 12.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
323 EXPECT_EQ(FloatPoint(22.0f, 12.0f), rgmNoFrame.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
324 EXPECT_EQ(FloatQuad(FloatRect(22.0f, 12.0f, 1.0f, 2.0f)), rgmNoFrame.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "CenterDiv")));
326 EXPECT_EQ(FloatPoint(1.0f, 6.0f), rgm.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "InnerDiv")));
327 EXPECT_EQ(FloatQuad(FloatRect(1.0f, 6.0f, 1.0f, 2.0f)), rgm.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "InnerDiv")));
328 EXPECT_EQ(FloatPoint(1.0f, 6.0f), rgmNoFrame.mapToContainer(point, getFrameLayoutContainer("test_frame", webView, "InnerDiv")));
329 EXPECT_EQ(FloatQuad(FloatRect(1.0f, 6.0f, 1.0f, 2.0f)), rgmNoFrame.mapToContainer(rect, getFrameLayoutContainer("test_frame", webView, "InnerDiv")));
331 EXPECT_NEAR(88.8975f, rgm.mapToContainer(point, nullptr).x(), 0.0001f);
332 EXPECT_NEAR(8.1532f, rgm.mapToContainer(point, nullptr).y(), 0.0001f);
333 EXPECT_NEAR(87.8975f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).x(), 0.0001f);
334 EXPECT_NEAR(8.1532f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).y(), 0.0001f);
335 EXPECT_NEAR(1.866, rectFromQuad(rgm.mapToContainer(rect, nullptr)).width(), 0.0001f);
336 EXPECT_NEAR(2.232, rectFromQuad(rgm.mapToContainer(rect, nullptr)).height(), 0.0001f);
338 EXPECT_EQ(FloatPoint(50.0f, 44.0f), rgmNoFrame.mapToContainer(point, nullptr));
339 EXPECT_EQ(FloatQuad(FloatRect(50.0f, 44.0f, 1.0f, 2.0f)), rgmNoFrame.mapToContainer(rect, nullptr));
342 TEST_F(LayoutGeometryMapTest, ColumnTest)
344 registerMockedHttpURLLoad("rgm_column_test.html");
345 FrameTestHelpers::WebViewHelper webViewHelper;
346 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "rgm_column_test.html", true, 0, 0);
347 webView->resize(WebSize(1000, 1000));
348 webView->layout();
350 // The document is 1000f wide (we resized to that size).
351 // We have a 8px margin on either side of the document.
352 // Between each column we have a 10px gap, and we have 3 columns.
353 // The width of a given column is (1000 - 16 - 20)/3.
354 // The total offset between any column and it's neighbour is width + 10px
355 // (for the gap).
356 float offset = (1000.0f - 16.0f - 20.0f) / 3.0f + 10.0f;
358 LayoutGeometryMap rgm;
359 rgm.pushMappingsToAncestor(getLayoutBox(webView, "A"), 0);
360 FloatPoint point;
361 FloatRect rect(0.0f, 0.0f, 5.0f, 3.0f);
363 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgm.mapToContainer(point, nullptr));
364 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 5.0f, 3.0f)), rgm.mapToContainer(rect, nullptr));
366 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
367 EXPECT_EQ(FloatPoint(0.0f, 0.0f), rgm.mapToContainer(point, nullptr));
368 EXPECT_EQ(FloatQuad(FloatRect(0.0f, 0.0f, 5.0f, 3.0f)), rgm.mapToContainer(rect, nullptr));
370 rgm.pushMappingsToAncestor(getLayoutBox(webView, "Col1"), 0);
371 EXPECT_EQ(FloatPoint(8.0f, 8.0f), rgm.mapToContainer(point, nullptr));
372 EXPECT_EQ(FloatQuad(FloatRect(8.0f, 8.0f, 5.0f, 3.0f)), rgm.mapToContainer(rect, nullptr));
374 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
375 rgm.pushMappingsToAncestor(getLayoutBox(webView, "Col2"), nullptr);
376 EXPECT_NEAR(8.0f + offset, rgm.mapToContainer(point, nullptr).x(), 0.1f);
377 EXPECT_NEAR(8.0f, rgm.mapToContainer(point, nullptr).y(), 0.1f);
378 EXPECT_NEAR(8.0f + offset, rectFromQuad(rgm.mapToContainer(rect, nullptr)).x(), 0.1f);
379 EXPECT_NEAR(8.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).y(), 0.1f);
380 EXPECT_EQ(5.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).width());
381 EXPECT_EQ(3.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).height());
383 rgm.popMappingsToAncestor(static_cast<DeprecatedPaintLayer*>(nullptr));
384 rgm.pushMappingsToAncestor(getLayoutBox(webView, "Col3"), nullptr);
385 EXPECT_NEAR(8.0f + offset * 2.0f, rgm.mapToContainer(point, nullptr).x(), 0.1f);
386 EXPECT_NEAR(8.0f, rgm.mapToContainer(point, nullptr).y(), 0.1f);
387 EXPECT_NEAR(8.0f + offset * 2.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).x(), 0.1f);
388 EXPECT_NEAR(8.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).y(), 0.1f);
389 EXPECT_EQ(5.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).width());
390 EXPECT_EQ(3.0f, rectFromQuad(rgm.mapToContainer(rect, nullptr)).height());
394 } // namespace blink