blob: 0d04fa0c1932e09e80d61dc6ac694470e1eb16ad [file] [log] [blame]
// 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 "core/css/cssom/FilteredComputedStylePropertyMap.h"
#include <memory>
#include "core/css/CSSComputedStyleDeclaration.h"
#include "core/dom/Element.h"
#include "core/testing/PageTestBase.h"
#include "platform/heap/Handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
class FilteredComputedStylePropertyMapTest : public PageTestBase {
public:
FilteredComputedStylePropertyMapTest() = default;
CSSComputedStyleDeclaration* Declaration() const {
return declaration_.Get();
}
void SetUp() override {
PageTestBase::SetUp(IntSize());
declaration_ =
CSSComputedStyleDeclaration::Create(GetDocument().documentElement());
}
Node* PageNode() { return GetDocument().documentElement(); }
private:
Persistent<CSSComputedStyleDeclaration> declaration_;
};
TEST_F(FilteredComputedStylePropertyMapTest, NativePropertyAccessors) {
Vector<CSSPropertyID> native_properties(
{CSSPropertyColor, CSSPropertyAlignItems});
Vector<AtomicString> empty_custom_properties;
FilteredComputedStylePropertyMap* map =
FilteredComputedStylePropertyMap::Create(PageNode(), native_properties,
empty_custom_properties);
DummyExceptionStateForTesting exception_state;
map->get("color", exception_state);
EXPECT_FALSE(exception_state.HadException());
map->has("color", exception_state);
EXPECT_FALSE(exception_state.HadException());
map->getAll("color", exception_state);
EXPECT_FALSE(exception_state.HadException());
map->get("align-contents", exception_state);
EXPECT_TRUE(exception_state.HadException());
exception_state.ClearException();
map->has("align-contents", exception_state);
EXPECT_TRUE(exception_state.HadException());
exception_state.ClearException();
map->getAll("align-contents", exception_state);
EXPECT_TRUE(exception_state.HadException());
exception_state.ClearException();
}
TEST_F(FilteredComputedStylePropertyMapTest, CustomPropertyAccessors) {
Vector<CSSPropertyID> empty_native_properties;
Vector<AtomicString> custom_properties({"--foo", "--bar"});
FilteredComputedStylePropertyMap* map =
FilteredComputedStylePropertyMap::Create(
PageNode(), empty_native_properties, custom_properties);
DummyExceptionStateForTesting exception_state;
const CSSStyleValue* foo = map->get("--foo", exception_state);
ASSERT_NE(nullptr, foo);
ASSERT_EQ(CSSStyleValue::kUnparsedType, foo->GetType());
EXPECT_FALSE(exception_state.HadException());
EXPECT_EQ(true, map->has("--foo", exception_state));
EXPECT_FALSE(exception_state.HadException());
CSSStyleValueVector fooAll = map->getAll("--foo", exception_state);
EXPECT_EQ(1U, fooAll.size());
ASSERT_NE(nullptr, fooAll[0]);
ASSERT_EQ(CSSStyleValue::kUnparsedType, fooAll[0]->GetType());
EXPECT_FALSE(exception_state.HadException());
EXPECT_EQ(nullptr, map->get("--quix", exception_state));
EXPECT_FALSE(exception_state.HadException());
EXPECT_EQ(false, map->has("--quix", exception_state));
EXPECT_FALSE(exception_state.HadException());
EXPECT_EQ(CSSStyleValueVector(), map->getAll("--quix", exception_state));
EXPECT_FALSE(exception_state.HadException());
}
} // namespace blink