summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/svg/svg_foreign_object_element_test.cc
blob: 42d0805ac57656eb0fe22604470b966a2b5e8f73 (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
// Copyright 2019 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/svg/svg_foreign_object_element.h"

#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"

namespace blink {

class SVGForeignObjectElementTest : public PageTestBase {};

TEST_F(SVGForeignObjectElementTest, NoLayoutObjectInNonRendered) {
  GetDocument().body()->SetInnerHTMLFromString(R"HTML(
    <svg>
      <pattern>
        <foreignObject id="fo"></foreignObject>
      </pattern>
    </svg>
  )HTML");

  UpdateAllLifecyclePhasesForTest();

  Element* foreign_object = GetDocument().getElementById("fo");
  EXPECT_FALSE(foreign_object->GetLayoutObject());

  scoped_refptr<ComputedStyle> style = ComputedStyle::Create();
  LayoutObject* layout_object =
      foreign_object->CreateLayoutObject(*style, LegacyLayout::kAuto);
  EXPECT_FALSE(layout_object);
}

TEST_F(SVGForeignObjectElementTest, ReferenceForeignObjectInNonRenderedCrash) {
  GetDocument().body()->SetInnerHTMLFromString(R"HTML(
    <style>
      div { writing-mode: vertical-rl; }
      div > svg { float: right; }
    </style>
    <svg>
      <radialGradient id="gradient">
        <pattern>
          <foreignObject>
            <div id="foRoot">
              <svg><rect fill="url(#gradient)" /></svg>
            </div>
          </foreignObject>
        </pattern>
      </radialGradient>
    </svg>
  )HTML");

  // This should not trigger any DCHECK failures or crashes.
  UpdateAllLifecyclePhasesForTest();
}

}  // namespace blink