Commit cbf246df authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Introduce namespace css_test_helpers.

We currently have a class CSSTestHelper which assists test cases in
creating RuleSets. This is nice, but we need a place to put general CSS
testing utils (not just for RuleSet) if we want to avoid repeating
ourselves many times.

This CL:

 * Moves CSSTestHelper to css_test_helpers::TestStyleSheet.
 * Deduplicates the almost-identical copies of RegisterProperty found
   in various test files.
 * Removes #include css_test_helper.h from some files which didn't really
   use CSSTestHelper.

R=futhark@chromium.org

Change-Id: I495f4ac33c9eda2ff087d73f45213acdc1852114
Reviewed-on: https://chromium-review.googlesource.com/c/1335562
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608333}
parent db74d5dd
......@@ -1739,8 +1739,8 @@ jumbo_source_set("unit_tests") {
"css/css_selector_watch_test.cc",
"css/css_style_declaration_test.cc",
"css/css_style_sheet_test.cc",
"css/css_test_helper.cc",
"css/css_test_helper.h",
"css/css_test_helpers.cc",
"css/css_test_helpers.h",
"css/css_value_test_helper.h",
"css/cssom/css_math_invert_test.cc",
"css/cssom/css_math_negate_test.cc",
......
......@@ -46,9 +46,7 @@
#include "third_party/blink/renderer/core/animation/element_animations.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect.h"
#include "third_party/blink/renderer/core/animation/pending_animations.h"
#include "third_party/blink/renderer/core/css/property_descriptor.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.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/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
......@@ -76,6 +74,8 @@
namespace blink {
using namespace css_test_helpers;
class AnimationCompositorAnimationsTest : public RenderingTest {
protected:
scoped_refptr<TimingFunction> linear_timing_function_;
......@@ -264,21 +264,6 @@ class AnimationCompositorAnimationsTest : public RenderingTest {
return frames;
}
void RegisterProperty(const String& name,
const String& syntax,
const String& initial_value,
bool is_inherited) {
DummyExceptionStateForTesting exception_state;
PropertyDescriptor* property_descriptor = PropertyDescriptor::Create();
property_descriptor->setName(name);
property_descriptor->setSyntax(syntax);
property_descriptor->setInitialValue(initial_value);
property_descriptor->setInherits(is_inherited);
PropertyRegistration::registerProperty(&GetDocument(), property_descriptor,
exception_state);
EXPECT_FALSE(exception_state.HadException());
}
void SetCustomProperty(const String& name, const String& value) {
DummyExceptionStateForTesting exception_state;
element_->style()->setProperty(&GetDocument(), name, value, g_empty_string,
......@@ -580,8 +565,8 @@ TEST_F(AnimationCompositorAnimationsTest,
TEST_F(AnimationCompositorAnimationsTest,
CanStartEffectOnCompositorCustomCssProperty) {
ScopedOffMainThreadCSSPaintForTest off_main_thread_css_paint(true);
RegisterProperty("--foo", "<number>", "0", false);
RegisterProperty("--bar", "<length>", "10px", false);
RegisterProperty(GetDocument(), "--foo", "<number>", "0", false);
RegisterProperty(GetDocument(), "--bar", "<length>", "10px", false);
SetCustomProperty("--foo", "10");
SetCustomProperty("--bar", "10px");
......@@ -1639,7 +1624,7 @@ TEST_F(AnimationCompositorAnimationsTest,
CreateSimpleCustomFloatPropertyAnimation) {
ScopedOffMainThreadCSSPaintForTest off_main_thread_css_paint(true);
RegisterProperty("--foo", "<number>", "0", false);
RegisterProperty(GetDocument(), "--foo", "<number>", "0", false);
SetCustomProperty("--foo", "10");
StringKeyframeEffectModel* effect =
......
......@@ -5,52 +5,54 @@
#include "third_party/blink/renderer/core/css/css_page_rule.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_test_helper.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
using namespace css_test_helpers;
TEST(CSSPageRule, Serializing) {
CSSTestHelper helper;
TestStyleSheet sheet;
const char* css_rule = "@page :left { size: auto; }";
helper.AddCSSRules(css_rule);
if (helper.CssRules()) {
EXPECT_EQ(1u, helper.CssRules()->length());
EXPECT_EQ(String(css_rule), helper.CssRules()->item(0)->cssText());
EXPECT_EQ(CSSRule::kPageRule, helper.CssRules()->item(0)->type());
if (CSSPageRule* page_rule = ToCSSPageRule(helper.CssRules()->item(0)))
sheet.AddCSSRules(css_rule);
if (sheet.CssRules()) {
EXPECT_EQ(1u, sheet.CssRules()->length());
EXPECT_EQ(String(css_rule), sheet.CssRules()->item(0)->cssText());
EXPECT_EQ(CSSRule::kPageRule, sheet.CssRules()->item(0)->type());
if (CSSPageRule* page_rule = ToCSSPageRule(sheet.CssRules()->item(0)))
EXPECT_EQ(":left", page_rule->selectorText());
}
}
TEST(CSSPageRule, selectorText) {
CSSTestHelper helper;
TestStyleSheet sheet;
const char* css_rule = "@page :left { size: auto; }";
helper.AddCSSRules(css_rule);
DCHECK(helper.CssRules());
EXPECT_EQ(1u, helper.CssRules()->length());
sheet.AddCSSRules(css_rule);
DCHECK(sheet.CssRules());
EXPECT_EQ(1u, sheet.CssRules()->length());
CSSPageRule* page_rule = ToCSSPageRule(helper.CssRules()->item(0));
CSSPageRule* page_rule = ToCSSPageRule(sheet.CssRules()->item(0));
EXPECT_EQ(":left", page_rule->selectorText());
// set invalid page selector.
page_rule->setSelectorText(&helper.GetDocument(), ":hover");
page_rule->setSelectorText(&sheet.GetDocument(), ":hover");
EXPECT_EQ(":left", page_rule->selectorText());
// set invalid page selector.
page_rule->setSelectorText(&helper.GetDocument(), "right { bla");
page_rule->setSelectorText(&sheet.GetDocument(), "right { bla");
EXPECT_EQ(":left", page_rule->selectorText());
// set page pseudo class selector.
page_rule->setSelectorText(&helper.GetDocument(), ":right");
page_rule->setSelectorText(&sheet.GetDocument(), ":right");
EXPECT_EQ(":right", page_rule->selectorText());
// set page type selector.
page_rule->setSelectorText(&helper.GetDocument(), "namedpage");
page_rule->setSelectorText(&sheet.GetDocument(), "namedpage");
EXPECT_EQ("namedpage", page_rule->selectorText());
}
......
......@@ -2,15 +2,17 @@
// 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_test_helper.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/css/rule_set.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
using namespace css_test_helpers;
TEST(CSSSelector, Representations) {
CSSTestHelper helper;
TestStyleSheet sheet;
const char* css_rules =
"summary::-webkit-details-marker { }"
......@@ -46,11 +48,11 @@ TEST(CSSSelector, Representations) {
".a.b .c {}";
helper.AddCSSRules(css_rules);
sheet.AddCSSRules(css_rules);
EXPECT_EQ(30u,
helper.GetRuleSet().RuleCount()); // .a, .b counts as two rules.
sheet.GetRuleSet().RuleCount()); // .a, .b counts as two rules.
#ifndef NDEBUG
helper.GetRuleSet().Show();
sheet.GetRuleSet().Show();
#endif
}
......
......@@ -6,20 +6,22 @@
#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_helper.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
using namespace css_test_helpers;
TEST(CSSStyleDeclarationTest, getPropertyShorthand) {
CSSTestHelper helper;
TestStyleSheet sheet;
helper.AddCSSRules("div { padding: var(--p); }");
ASSERT_TRUE(helper.CssRules());
ASSERT_EQ(1u, helper.CssRules()->length());
ASSERT_EQ(CSSRule::kStyleRule, helper.CssRules()->item(0)->type());
CSSStyleRule* style_rule = ToCSSStyleRule(helper.CssRules()->item(0));
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 = ToCSSStyleRule(sheet.CssRules()->item(0));
CSSStyleDeclaration* style = style_rule->style();
ASSERT_TRUE(style);
EXPECT_EQ(AtomicString(), style->GetPropertyShorthand("padding"));
......
/*
* Copyright (c) 2014, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Opera Software ASA nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPER_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/css/rule_set.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
class Document;
class CSSStyleSheet;
// A helper class for writing tests of CSS rules. Example usage:
//
// CSSTestHelper helper;
// helper.addCSSRule("body { color: red} #a { position: absolute }");
// RuleSet& ruleSet = helper.ruleSet();
// ... examine RuleSet to find the rule and test properties on it.
class CSSTestHelper {
STACK_ALLOCATED();
public:
CSSTestHelper();
~CSSTestHelper();
const Document& GetDocument() { return *document_; };
void AddCSSRules(const char* rule_text, bool is_empty_sheet = false);
RuleSet& GetRuleSet();
CSSRuleList* CssRules();
private:
Persistent<Document> document_;
Persistent<CSSStyleSheet> style_sheet_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPER_H_
/*
* Copyright (c) 2014, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Opera Software ASA nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// 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_test_helper.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_style_sheet.h"
#include "third_party/blink/renderer/core/css/property_descriptor.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/rule_set.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
namespace blink {
namespace css_test_helpers {
CSSTestHelper::~CSSTestHelper() = default;
TestStyleSheet::~TestStyleSheet() = default;
CSSTestHelper::CSSTestHelper() {
TestStyleSheet::TestStyleSheet() {
document_ = Document::CreateForTest();
TextPosition position;
style_sheet_ = CSSStyleSheet::CreateInline(*document_, NullURL(), position,
UTF8Encoding());
}
CSSRuleList* CSSTestHelper::CssRules() {
CSSRuleList* TestStyleSheet::CssRules() {
DummyExceptionStateForTesting exception_state;
CSSRuleList* result = style_sheet_->cssRules(exception_state);
EXPECT_FALSE(exception_state.HadException());
return result;
}
RuleSet& CSSTestHelper::GetRuleSet() {
RuleSet& TestStyleSheet::GetRuleSet() {
RuleSet& rule_set = style_sheet_->Contents()->EnsureRuleSet(
MediaQueryEvaluator(), kRuleHasNoSpecialState);
rule_set.CompactRulesIfNeeded();
return rule_set;
}
void CSSTestHelper::AddCSSRules(const char* css_text, bool is_empty_sheet) {
void TestStyleSheet::AddCSSRules(const char* css_text, bool is_empty_sheet) {
TextPosition position;
unsigned sheet_length = style_sheet_->length();
style_sheet_->Contents()->ParseStringAtPosition(css_text, position);
......@@ -73,4 +53,21 @@ void CSSTestHelper::AddCSSRules(const char* css_text, bool is_empty_sheet) {
ASSERT_EQ(style_sheet_->length(), sheet_length);
}
void RegisterProperty(Document& document,
const String& name,
const String& syntax,
const String& initial_value,
bool is_inherited) {
DummyExceptionStateForTesting exception_state;
PropertyDescriptor* property_descriptor = PropertyDescriptor::Create();
property_descriptor->setName(name);
property_descriptor->setSyntax(syntax);
property_descriptor->setInitialValue(initial_value);
property_descriptor->setInherits(is_inherited);
PropertyRegistration::registerProperty(&document, property_descriptor,
exception_state);
ASSERT_FALSE(exception_state.HadException());
}
} // namespace css_test_helpers
} // namespace blink
// 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPERS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPERS_H_
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/css/rule_set.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
class Document;
class CSSStyleSheet;
namespace css_test_helpers {
// Example usage:
//
// css_test_helpers::TestStyleSheet sheet;
// sheet.addCSSRule("body { color: red} #a { position: absolute }");
// RuleSet& ruleSet = sheet.ruleSet();
// ... examine RuleSet to find the rule and test properties on it.
class TestStyleSheet {
STACK_ALLOCATED();
public:
TestStyleSheet();
~TestStyleSheet();
const Document& GetDocument() { return *document_; };
void AddCSSRules(const char* rule_text, bool is_empty_sheet = false);
RuleSet& GetRuleSet();
CSSRuleList* CssRules();
private:
Persistent<Document> document_;
Persistent<CSSStyleSheet> style_sheet_;
};
void RegisterProperty(Document& document,
const String& name,
const String& syntax,
const String& initial_value,
bool is_inherited);
} // namespace css_test_helpers
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_TEST_HELPERS_H_
......@@ -5,32 +5,16 @@
#include "third_party/blink/renderer/core/css/properties/css_property_ref.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_property_name.h"
#include "third_party/blink/renderer/core/css/property_descriptor.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
namespace blink {
using namespace css_test_helpers;
namespace {
class CSSPropertyRefTest : public PageTestBase {
public:
void RegisterProperty(const String& name,
const String& syntax,
const String& initial_value,
bool is_inherited) {
DummyExceptionStateForTesting exception_state;
PropertyDescriptor* property_descriptor = PropertyDescriptor::Create();
property_descriptor->setName(name);
property_descriptor->setSyntax(syntax);
property_descriptor->setInitialValue(initial_value);
property_descriptor->setInherits(is_inherited);
PropertyRegistration::registerProperty(&GetDocument(), property_descriptor,
exception_state);
EXPECT_FALSE(exception_state.HadException());
}
};
class CSSPropertyRefTest : public PageTestBase {};
} // namespace
......@@ -41,7 +25,7 @@ TEST_F(CSSPropertyRefTest, LookupUnregistred) {
}
TEST_F(CSSPropertyRefTest, LookupRegistered) {
RegisterProperty("--x", "<length>", "42px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "42px", false);
CSSPropertyRef ref("--x", GetDocument());
EXPECT_TRUE(ref.IsValid());
EXPECT_EQ(CSSPropertyVariable, ref.GetProperty().PropertyID());
......@@ -102,7 +86,7 @@ TEST_F(CSSPropertyRefTest, GetResolvedPropertyAlias) {
}
TEST_F(CSSPropertyRefTest, FromCSSPropertyNameCustom) {
RegisterProperty("--x", "<length>", "42px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "42px", false);
CSSPropertyRef ref(CSSPropertyName("--x"), GetDocument());
EXPECT_EQ(CSSPropertyVariable, ref.GetProperty().PropertyID());
}
......
......@@ -6,34 +6,19 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/core/css/property_descriptor.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
namespace blink {
using namespace css_test_helpers;
namespace {
class CustomPropertyTest : public PageTestBase {
public:
void RegisterProperty(const String& name,
const String& syntax,
const String& initial_value,
bool is_inherited) {
DummyExceptionStateForTesting exception_state;
PropertyDescriptor* property_descriptor = PropertyDescriptor::Create();
property_descriptor->setName(name);
property_descriptor->setSyntax(syntax);
property_descriptor->setInitialValue(initial_value);
property_descriptor->setInherits(is_inherited);
PropertyRegistration::registerProperty(&GetDocument(), property_descriptor,
exception_state);
EXPECT_FALSE(exception_state.HadException());
}
void SetElementWithStyle(const String& value) {
GetDocument().body()->SetInnerHTMLFromString("<div id='target' style='" +
value + "'></div>");
......@@ -56,13 +41,13 @@ TEST_F(CustomPropertyTest, UnregisteredPropertyIsInherited) {
}
TEST_F(CustomPropertyTest, RegisteredNonInheritedPropertyIsNotInherited) {
RegisterProperty("--x", "<length>", "42px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "42px", false);
CustomProperty property("--x", GetDocument());
EXPECT_FALSE(property.IsInherited());
}
TEST_F(CustomPropertyTest, RegisteredInheritedPropertyIsInherited) {
RegisterProperty("--x", "<length>", "42px", true);
RegisterProperty(GetDocument(), "--x", "<length>", "42px", true);
CustomProperty property("--x", GetDocument());
EXPECT_TRUE(property.IsInherited());
}
......@@ -92,7 +77,7 @@ TEST_F(CustomPropertyTest, ComputedCSSValueUnregistered) {
}
TEST_F(CustomPropertyTest, ComputedCSSValueInherited) {
RegisterProperty("--x", "<length>", "0px", true);
RegisterProperty(GetDocument(), "--x", "<length>", "0px", true);
CustomProperty property("--x", GetDocument());
SetElementWithStyle("--x:100px");
const CSSValue* value = GetComputedValue(property);
......@@ -102,7 +87,7 @@ TEST_F(CustomPropertyTest, ComputedCSSValueInherited) {
}
TEST_F(CustomPropertyTest, ComputedCSSValueNonInherited) {
RegisterProperty("--x", "<length>", "0px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "0px", false);
CustomProperty property("--x", GetDocument());
SetElementWithStyle("--x:100px");
const CSSValue* value = GetComputedValue(property);
......@@ -112,7 +97,7 @@ TEST_F(CustomPropertyTest, ComputedCSSValueNonInherited) {
}
TEST_F(CustomPropertyTest, ComputedCSSValueInitial) {
RegisterProperty("--x", "<length>", "100px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "100px", false);
CustomProperty property("--x", GetDocument());
SetElementWithStyle(""); // Do not apply --x.
const CSSValue* value = GetComputedValue(property);
......@@ -131,7 +116,7 @@ TEST_F(CustomPropertyTest, ComputedCSSValueEmptyInitial) {
TEST_F(CustomPropertyTest, ComputedCSSValueLateRegistration) {
CustomProperty property("--x", GetDocument());
SetElementWithStyle("--x:100px");
RegisterProperty("--x", "<length>", "100px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "100px", false);
// The property was not registered when the style was computed, hence the
// computed value should be what we expect for an unregistered property.
const CSSValue* value = GetComputedValue(property);
......
......@@ -12,10 +12,8 @@
#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_style_sheet.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
#include "third_party/blink/renderer/core/css/property_descriptor.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/first_letter_pseudo_element.h"
......@@ -38,6 +36,8 @@
namespace blink {
using namespace css_test_helpers;
class StyleEngineTest : public testing::Test {
protected:
void SetUp() override;
......@@ -55,10 +55,6 @@ class StyleEngineTest : public testing::Test {
};
RuleSetInvalidation ScheduleInvalidationsForRules(TreeScope&,
const String& css_text);
void RegisterProperty(const String& name,
const String& syntax,
const String& initial_value,
bool inherits);
// A wrapper to add a reason for UpdateAllLifecyclePhases
void UpdateAllLifecyclePhases() {
......@@ -91,21 +87,6 @@ StyleEngineTest::ScheduleInvalidationsForRules(TreeScope& tree_scope,
return kRuleSetInvalidationsScheduled;
}
void StyleEngineTest::RegisterProperty(const String& name,
const String& syntax,
const String& initial_value,
bool inherits) {
DummyExceptionStateForTesting exception_state;
PropertyDescriptor* property_descriptor = PropertyDescriptor::Create();
property_descriptor->setName(name);
property_descriptor->setSyntax(syntax);
property_descriptor->setInitialValue(initial_value);
property_descriptor->setInherits(false);
PropertyRegistration::registerProperty(&GetDocument(), property_descriptor,
exception_state);
ASSERT_FALSE(exception_state.HadException());
}
TEST_F(StyleEngineTest, DocumentDirtyAfterInject) {
StyleSheetContents* parsed_sheet =
StyleSheetContents::Create(CSSParserContext::Create(GetDocument()));
......@@ -1644,7 +1625,7 @@ TEST_F(StyleEngineTest, InitialDataCreation) {
EXPECT_FALSE(GetStyleEngine().MaybeCreateAndGetInitialData());
// After registering, there should be initial data.
RegisterProperty("--x", "<length>", "10px", false);
RegisterProperty(GetDocument(), "--x", "<length>", "10px", false);
auto data1 = GetStyleEngine().MaybeCreateAndGetInitialData();
EXPECT_TRUE(data1);
......@@ -1660,7 +1641,7 @@ TEST_F(StyleEngineTest, InitialDataCreation) {
// After registering a new property, initial data should be invalidated,
// such that the new initial data is different.
RegisterProperty("--y", "<color>", "black", false);
RegisterProperty(GetDocument(), "--y", "<color>", "black", false);
EXPECT_NE(data1, GetStyleEngine().MaybeCreateAndGetInitialData());
}
......
......@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_test_helper.h"
#include "third_party/blink/renderer/core/css/parser/css_parser.h"
namespace blink {
......
......@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/core/frame/use_counter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/use_counter/css_property_id.mojom-blink.h"
#include "third_party/blink/renderer/core/css/css_test_helper.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/html/html_html_element.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment