blob: 39b97a1bcb5d781d3d0e11eb93b37e5930ee00aa [file] [log] [blame]
// Copyright 2017 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 "core/layout/ng/ng_out_of_flow_layout_part.h"
#include "core/layout/ng/layout_ng_block_flow.h"
#include "core/layout/ng/ng_layout_result.h"
#include "core/layout/ng/ng_layout_test.h"
namespace blink {
namespace {
using NGOutOfFlowLayoutPartTest = NGLayoutTest;
// Fixed blocks inside absolute blocks trigger otherwise unused while loop
// inside NGOutOfFlowLayoutPart::Run.
// This test exercises this loop by placing two fixed elements inside abs.
TEST_F(NGOutOfFlowLayoutPartTest, FixedInsideAbs) {
SetBodyInnerHTML(
R"HTML(
<style>
body{ padding:0px; margin:0px}
#rel { position:relative }
#abs {
position: absolute;
top:49px;
left:0px;
}
#pad {
width:100px;
height:50px;
}
#fixed1 {
position:fixed;
width:50px;
}
#fixed2 {
position:fixed;
top:9px;
left:7px;
}
</style>
<div id='rel'>
<div id='abs'>
<div id='pad'></div>
<div id='fixed1'>
<p>fixed static</p>
</div>
<div id='fixed2'>
<p>fixed plain</p>
</div>
</div>
</div>
)HTML");
// Test whether the oof fragments have been collected at NG->Legacy boundary.
Element* rel = GetDocument().getElementById("rel");
LayoutBlockFlow* block_flow = ToLayoutBlockFlow(rel->GetLayoutObject());
scoped_refptr<NGConstraintSpace> space =
NGConstraintSpace::CreateFromLayoutObject(*block_flow);
scoped_refptr<NGLayoutResult> result =
block_flow->CachedLayoutResultForTesting();
EXPECT_TRUE(result);
EXPECT_EQ(result->OutOfFlowPositionedDescendants().size(), (size_t)2);
// Test the final result.
Element* fixed_1 = GetDocument().getElementById("fixed1");
Element* fixed_2 = GetDocument().getElementById("fixed2");
// fixed1 top is static: #abs.top + #pad.height
EXPECT_EQ(fixed_1->OffsetTop(), LayoutUnit(99));
// fixed2 top is positioned: #fixed2.top
EXPECT_EQ(fixed_2->OffsetTop(), LayoutUnit(9));
};
} // namespace
} // namespace blink