summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/paint_containment_test.cc
blob: ba4f6fc31d6723bb1e56b6c1378882ede56afe35 (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
// 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 "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/layout/layout_block.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"

namespace blink {

class PaintContainmentTest : public RenderingTest {
 private:
  void SetUp() override {
    EnableCompositing();
    RenderingTest::SetUp();
  }
};

static void CheckIsClippingStackingContextAndContainer(
    LayoutBoxModelObject& obj) {
  EXPECT_TRUE(obj.CanContainFixedPositionObjects());
  EXPECT_TRUE(obj.HasClipRelatedProperty());
  EXPECT_TRUE(obj.ShouldApplyPaintContainment());

  // TODO(leviw): Ideally, we wouldn't require a paint layer to handle the
  // clipping and stacking performed by paint containment.
  DCHECK(obj.Layer());
  PaintLayer* layer = obj.Layer();
  EXPECT_TRUE(layer->GetLayoutObject().IsStackingContext());
}

TEST_F(PaintContainmentTest, BlockPaintContainment) {
  SetBodyInnerHTML("<div id='div' style='contain: paint'></div>");
  Element* div = GetDocument().getElementById(AtomicString("div"));
  DCHECK(div);
  LayoutObject* obj = div->GetLayoutObject();
  DCHECK(obj);
  DCHECK(obj->IsLayoutBlock());
  auto& block = To<LayoutBlock>(*obj);
  EXPECT_TRUE(block.CreatesNewFormattingContext());
  EXPECT_FALSE(block.CanBeScrolledAndHasScrollableArea());
  CheckIsClippingStackingContextAndContainer(block);
}

TEST_F(PaintContainmentTest, InlinePaintContainment) {
  SetBodyInnerHTML(
      "<div><span id='test' style='contain: paint'>Foo</span></div>");
  Element* span = GetDocument().getElementById(AtomicString("test"));
  DCHECK(span);
  // Paint containment shouldn't apply to non-atomic inlines.
  LayoutObject* obj = span->GetLayoutObject();
  DCHECK(obj);
  EXPECT_FALSE(obj->IsLayoutBlock());
}

TEST_F(PaintContainmentTest, SvgWithContainmentShouldNotCrash) {
  // SVG doesn't currently support PaintLayers and should not crash with
  // layer-related properties.
  SetBodyInnerHTML("<svg><text y='20' style='contain: paint'>Foo</text></svg>");
  SetBodyInnerHTML(
      "<svg><foreignObject style='contain: paint'>Foo</foreignObject></svg>");
  SetBodyInnerHTML(
      "<svg><foreignObject><span style='contain: "
      "paint'>Foo</span></foreignObject></svg>");
}

}  // namespace blink