blob: 5cbca2548afffb5b7a41e517ba1a7b3dbb594099 [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 "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
namespace blink {
class LayoutViewTest : public RenderingTest {
public:
LayoutViewTest() : RenderingTest(SingleChildLocalFrameClient::Create()) {}
};
TEST_F(LayoutViewTest, UpdateCountersLayout) {
SetBodyInnerHTML(R"HTML(
<style>
div.incX { counter-increment: x }
div.incY { counter-increment: y }
div::before { content: counter(y) }
</style>
<div id=inc></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
Element* inc = GetDocument().getElementById("inc");
inc->setAttribute("class", "incX");
GetDocument().UpdateStyleAndLayoutTree();
EXPECT_FALSE(GetDocument().View()->NeedsLayout());
UpdateAllLifecyclePhasesForTest();
inc->setAttribute("class", "incY");
GetDocument().UpdateStyleAndLayoutTree();
EXPECT_TRUE(GetDocument().View()->NeedsLayout());
}
TEST_F(LayoutViewTest, DisplayNoneFrame) {
SetBodyInnerHTML(R"HTML(
<iframe id="iframe" style="display:none"></iframe>
)HTML");
UpdateAllLifecyclePhasesForTest();
HTMLIFrameElement* iframe =
ToHTMLIFrameElement(GetDocument().getElementById("iframe"));
Document* frame_doc = iframe->contentDocument();
ASSERT_TRUE(frame_doc);
LayoutObject* view = frame_doc->GetLayoutView();
ASSERT_TRUE(view);
EXPECT_FALSE(view->CanHaveChildren());
frame_doc->body()->SetInnerHTMLFromString(R"HTML(
<div id="div"></div>
)HTML");
frame_doc->Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
frame_doc->GetStyleEngine().RecalcStyle(kNoChange);
Element* div = frame_doc->getElementById("div");
EXPECT_FALSE(div->GetNonAttachedStyle());
}
} // namespace blink