OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/cssom/FilteredComputedStylePropertyMap.h" |
| 6 |
| 7 #include "core/css/CSSComputedStyleDeclaration.h" |
| 8 #include "core/testing/DummyPageHolder.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class FilteredComputedStylePropertyMapTest : public ::testing::Test { |
| 15 public: |
| 16 FilteredComputedStylePropertyMapTest() |
| 17 : m_page(DummyPageHolder::create()) |
| 18 { |
| 19 m_declaration = CSSComputedStyleDeclaration::create(m_page->document().d
ocumentElement()); |
| 20 } |
| 21 |
| 22 CSSComputedStyleDeclaration* declaration() const { return m_declaration.get(
); } |
| 23 |
| 24 private: |
| 25 OwnPtr<DummyPageHolder> m_page; |
| 26 Persistent<CSSComputedStyleDeclaration> m_declaration; |
| 27 }; |
| 28 |
| 29 TEST_F(FilteredComputedStylePropertyMapTest, GetProperties) |
| 30 { |
| 31 Vector<CSSPropertyID> nativeProperties({CSSPropertyColor, CSSPropertyAlignIt
ems}); |
| 32 Vector<CSSPropertyID> emptyNativeProperties; |
| 33 Vector<AtomicString> customProperties({"--foo", "--bar"}); |
| 34 Vector<AtomicString> emptyCustomProperties; |
| 35 |
| 36 FilteredComputedStylePropertyMap* map = FilteredComputedStylePropertyMap::cr
eate(declaration(), nativeProperties, customProperties); |
| 37 EXPECT_TRUE(map->getProperties().contains("color")); |
| 38 EXPECT_TRUE(map->getProperties().contains("align-items")); |
| 39 EXPECT_TRUE(map->getProperties().contains("--foo")); |
| 40 EXPECT_TRUE(map->getProperties().contains("--bar")); |
| 41 |
| 42 map = FilteredComputedStylePropertyMap::create(declaration(), nativeProperti
es, emptyCustomProperties); |
| 43 EXPECT_TRUE(map->getProperties().contains("color")); |
| 44 EXPECT_TRUE(map->getProperties().contains("align-items")); |
| 45 |
| 46 map = FilteredComputedStylePropertyMap::create(declaration(), emptyNativePro
perties, customProperties); |
| 47 EXPECT_TRUE(map->getProperties().contains("--foo")); |
| 48 EXPECT_TRUE(map->getProperties().contains("--bar")); |
| 49 } |
| 50 |
| 51 TEST_F(FilteredComputedStylePropertyMapTest, NativePropertyAccessors) |
| 52 { |
| 53 Vector<CSSPropertyID> nativeProperties({CSSPropertyColor, CSSPropertyAlignIt
ems}); |
| 54 Vector<AtomicString> emptyCustomProperties; |
| 55 FilteredComputedStylePropertyMap* map = FilteredComputedStylePropertyMap::cr
eate(declaration(), nativeProperties, emptyCustomProperties); |
| 56 |
| 57 TrackExceptionState exceptionState; |
| 58 |
| 59 map->get("color", exceptionState); |
| 60 EXPECT_FALSE(exceptionState.hadException()); |
| 61 |
| 62 map->has("color", exceptionState); |
| 63 EXPECT_FALSE(exceptionState.hadException()); |
| 64 |
| 65 map->getAll("color", exceptionState); |
| 66 EXPECT_FALSE(exceptionState.hadException()); |
| 67 |
| 68 map->get("align-contents", exceptionState); |
| 69 EXPECT_TRUE(exceptionState.hadException()); |
| 70 exceptionState.clearException(); |
| 71 |
| 72 map->has("align-contents", exceptionState); |
| 73 EXPECT_TRUE(exceptionState.hadException()); |
| 74 exceptionState.clearException(); |
| 75 |
| 76 map->getAll("align-contents", exceptionState); |
| 77 EXPECT_TRUE(exceptionState.hadException()); |
| 78 exceptionState.clearException(); |
| 79 } |
| 80 |
| 81 TEST_F(FilteredComputedStylePropertyMapTest, CustomPropertyAccessors) |
| 82 { |
| 83 Vector<CSSPropertyID> emptyNativeProperties; |
| 84 Vector<AtomicString> customProperties({"--foo", "--bar"}); |
| 85 FilteredComputedStylePropertyMap* map = FilteredComputedStylePropertyMap::cr
eate(declaration(), emptyNativeProperties, customProperties); |
| 86 |
| 87 TrackExceptionState exceptionState; |
| 88 |
| 89 map->get("--foo", exceptionState); |
| 90 EXPECT_FALSE(exceptionState.hadException()); |
| 91 |
| 92 map->has("--foo", exceptionState); |
| 93 EXPECT_FALSE(exceptionState.hadException()); |
| 94 |
| 95 map->getAll("--foo", exceptionState); |
| 96 EXPECT_FALSE(exceptionState.hadException()); |
| 97 |
| 98 map->get("--quix", exceptionState); |
| 99 EXPECT_TRUE(exceptionState.hadException()); |
| 100 exceptionState.clearException(); |
| 101 |
| 102 map->has("--quix", exceptionState); |
| 103 EXPECT_TRUE(exceptionState.hadException()); |
| 104 exceptionState.clearException(); |
| 105 |
| 106 map->getAll("--quix", exceptionState); |
| 107 EXPECT_TRUE(exceptionState.hadException()); |
| 108 exceptionState.clearException(); |
| 109 } |
| 110 |
| 111 } // namespace blink |
OLD | NEW |