summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/layout_block_test.cc
blob: 093e8a67b9319640815eba8a4bbd9e7efdb2157f (plain)
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
// 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 "build/build_config.h"

#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/layout/layout_block.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"

using ::testing::MatchesRegex;

namespace blink {

class LayoutBlockTest : public RenderingTest {};

TEST_F(LayoutBlockTest, LayoutNameCalledWithNullStyle) {
  scoped_refptr<ComputedStyle> style = ComputedStyle::Create();
  LayoutObject* obj = LayoutBlockFlow::CreateAnonymous(&GetDocument(), style);
  obj->SetModifiedStyleOutsideStyleRecalc(nullptr,
                                          LayoutObject::ApplyStyleChanges::kNo);
  EXPECT_FALSE(obj->Style());
  EXPECT_THAT(obj->DecoratedName().Ascii().data(),
              MatchesRegex("LayoutN?G?BlockFlow \\(anonymous\\)"));
  obj->Destroy();
}

TEST_F(LayoutBlockTest, WidthAvailableToChildrenChanged) {
  ScopedOverlayScrollbarsForTest overlay_scrollbars(false);
  SetBodyInnerHTML(R"HTML(
    <!DOCTYPE html>
    <div id='list' style='overflow-y:auto; width:150px; height:100px'>
      <div style='height:20px'>Item</div>
      <div style='height:20px'>Item</div>
      <div style='height:20px'>Item</div>
      <div style='height:20px'>Item</div>
      <div style='height:20px'>Item</div>
      <div style='height:20px'>Item</div>
    </div>
  )HTML");
  Element* list_element = GetDocument().getElementById("list");
  ASSERT_TRUE(list_element);
  LayoutBox* list_box = ToLayoutBox(list_element->GetLayoutObject());
  Element* item_element = ElementTraversal::FirstChild(*list_element);
  ASSERT_TRUE(item_element);
  ASSERT_GT(list_box->VerticalScrollbarWidth(), 0);
  ASSERT_EQ(item_element->OffsetWidth(),
            150 - list_box->VerticalScrollbarWidth());

  DummyExceptionStateForTesting exception_state;
  list_element->style()->setCSSText(&GetDocument(), "width:150px;height:100px;",
                                    exception_state);
  ASSERT_FALSE(exception_state.HadException());
  UpdateAllLifecyclePhasesForTest();
  ASSERT_EQ(list_box->VerticalScrollbarWidth(), 0);
  ASSERT_EQ(item_element->OffsetWidth(), 150);
}

TEST_F(LayoutBlockTest, OverflowWithTransformAndPerspective) {
  SetBodyInnerHTML(R"HTML(
    <div id='target' style='width: 100px; height: 100px; overflow: scroll;
        perspective: 200px;'>
      <div style='transform: rotateY(-45deg); width: 140px; height: 100px'>
      </div>
    </div>
  )HTML");
  LayoutBox* scroller =
      ToLayoutBox(GetDocument().getElementById("target")->GetLayoutObject());
  EXPECT_EQ(119.5, scroller->LayoutOverflowRect().Width().ToFloat());
}

TEST_F(LayoutBlockTest, NestedInlineVisualOverflow) {
  // Only exercises legacy code.
  if (RuntimeEnabledFeatures::LayoutNGEnabled())
    return;
  SetBodyInnerHTML(R"HTML(
    <label style="font-size: 0px">
      <input type="radio" style="margin-left: -15px">
    </label>
  )HTML");
  LayoutBlockFlow* body =
      ToLayoutBlockFlow(GetDocument().body()->GetLayoutObject());
  RootInlineBox* box = body->FirstRootBox();
#if defined(OS_MACOSX)
  EXPECT_EQ(LayoutRect(-17, 0, 16, 19),
            box->VisualOverflowRect(box->LineTop(), box->LineBottom()));
#elif defined(OS_ANDROID)
  EXPECT_EQ(LayoutRect(-15, 3, 19, 16),
            box->VisualOverflowRect(box->LineTop(), box->LineBottom()));
#else
  EXPECT_EQ(LayoutRect(-15, 3, 16, 13),
            box->VisualOverflowRect(box->LineTop(), box->LineBottom()));
#endif
}

}  // namespace blink