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
|
// Copyright 2016 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_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_style_rule.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TEST(CSSStyleDeclarationTest, getPropertyShorthand) {
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("div { padding: var(--p); }");
ASSERT_TRUE(sheet.CssRules());
ASSERT_EQ(1u, sheet.CssRules()->length());
ASSERT_EQ(CSSRule::kStyleRule, sheet.CssRules()->item(0)->type());
CSSStyleRule* style_rule = To<CSSStyleRule>(sheet.CssRules()->item(0));
CSSStyleDeclaration* style = style_rule->style();
ASSERT_TRUE(style);
EXPECT_EQ(AtomicString(), style->GetPropertyShorthand("padding"));
}
TEST(CSSStyleDeclarationTest, ParsingRevertWithFeatureEnabled) {
ScopedCSSRevertForTest scoped_revert(true);
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("div { top: revert; --x: revert; }");
ASSERT_TRUE(sheet.CssRules());
ASSERT_EQ(1u, sheet.CssRules()->length());
CSSStyleRule* style_rule = To<CSSStyleRule>(sheet.CssRules()->item(0));
CSSStyleDeclaration* style = style_rule->style();
ASSERT_TRUE(style);
EXPECT_EQ("revert", style->getPropertyValue("top"));
EXPECT_EQ("revert", style->getPropertyValue("--x"));
// Test setProperty/getPropertyValue:
DummyExceptionStateForTesting exception_state;
style->SetPropertyInternal(CSSPropertyID::kLeft, "left", "revert", false,
SecureContextMode::kSecureContext,
exception_state);
style->SetPropertyInternal(CSSPropertyID::kVariable, "--y", " revert", false,
SecureContextMode::kSecureContext,
exception_state);
EXPECT_EQ("revert", style->getPropertyValue("left"));
EXPECT_EQ("revert", style->getPropertyValue("--y"));
EXPECT_FALSE(exception_state.HadException());
}
TEST(CSSStyleDeclarationTest, ParsingRevertWithFeatureDisabled) {
ScopedCSSRevertForTest scoped_revert(false);
css_test_helpers::TestStyleSheet sheet;
sheet.AddCSSRules("div { top: revert; --x: revert; }");
ASSERT_TRUE(sheet.CssRules());
ASSERT_EQ(1u, sheet.CssRules()->length());
CSSStyleRule* style_rule = To<CSSStyleRule>(sheet.CssRules()->item(0));
CSSStyleDeclaration* style = style_rule->style();
ASSERT_TRUE(style);
EXPECT_EQ("", style->getPropertyValue("top"));
EXPECT_EQ(" revert", style->getPropertyValue("--x"));
// Test setProperty/getPropertyValue:
DummyExceptionStateForTesting exception_state;
style->SetPropertyInternal(CSSPropertyID::kLeft, "left", "revert", false,
SecureContextMode::kSecureContext,
exception_state);
style->SetPropertyInternal(CSSPropertyID::kVariable, "--y", " revert", false,
SecureContextMode::kSecureContext,
exception_state);
EXPECT_EQ("", style->getPropertyValue("left"));
EXPECT_EQ(" revert", style->getPropertyValue("--y"));
EXPECT_FALSE(exception_state.HadException());
}
} // namespace blink
|