blob: 9b9a9917de42e08e72b8b09ab78bbc46d3b528c4 (
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
|
// Copyright 2018 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/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
namespace blink {
class CSSComputedStyleDeclarationTest : public PageTestBase {};
TEST_F(CSSComputedStyleDeclarationTest, CleanAncestorsNoRecalc) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<div id=dirty></div>
<div>
<div id=target style='color:green'></div>
</div>
)HTML");
GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_FALSE(GetDocument().NeedsLayoutTreeUpdate());
GetDocument().getElementById("dirty")->setAttribute("style", "color:pink");
EXPECT_TRUE(GetDocument().NeedsLayoutTreeUpdate());
Element* target = GetDocument().getElementById("target");
CSSComputedStyleDeclaration* computed =
CSSComputedStyleDeclaration::Create(target);
EXPECT_STREQ("rgb(0, 128, 0)",
computed->GetPropertyValue(CSSPropertyColor).Utf8().data());
EXPECT_TRUE(GetDocument().NeedsLayoutTreeUpdate());
}
TEST_F(CSSComputedStyleDeclarationTest, CleanShadowAncestorsNoRecalc) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<div id=dirty></div>
<div id=host></div>
)HTML");
Element* host = GetDocument().getElementById("host");
ShadowRoot& shadow_root =
host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root.SetInnerHTMLFromString(R"HTML(
<div id=target style='color:green'></div>
)HTML");
GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_FALSE(GetDocument().NeedsLayoutTreeUpdate());
GetDocument().getElementById("dirty")->setAttribute("style", "color:pink");
EXPECT_TRUE(GetDocument().NeedsLayoutTreeUpdate());
Element* target = shadow_root.getElementById("target");
CSSComputedStyleDeclaration* computed =
CSSComputedStyleDeclaration::Create(target);
EXPECT_STREQ("rgb(0, 128, 0)",
computed->GetPropertyValue(CSSPropertyColor).Utf8().data());
EXPECT_TRUE(GetDocument().NeedsLayoutTreeUpdate());
}
} // namespace blink
|