| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/resolver/SharedStyleFinder.h" | 5 #include "core/css/resolver/SharedStyleFinder.h" |
| 6 | 6 |
| 7 #include "core/css/RuleFeature.h" | 7 #include "core/css/RuleFeature.h" |
| 8 #include "core/css/RuleSet.h" | 8 #include "core/css/RuleSet.h" |
| 9 #include "core/css/parser/CSSParser.h" | 9 #include "core/css/parser/CSSParser.h" |
| 10 #include "core/css/parser/CSSParserContext.h" | 10 #include "core/css/parser/CSSParserContext.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/shadow/ShadowRoot.h" |
| 13 #include "core/dom/shadow/ShadowRootInit.h" |
| 12 #include "core/frame/FrameView.h" | 14 #include "core/frame/FrameView.h" |
| 13 #include "core/html/HTMLElement.h" | 15 #include "core/html/HTMLElement.h" |
| 14 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <memory> | 18 #include <memory> |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 class SharedStyleFinderTest : public ::testing::Test { | 22 class SharedStyleFinderTest : public ::testing::Test { |
| 21 protected: | 23 protected: |
| 22 SharedStyleFinderTest() = default; | 24 SharedStyleFinderTest() = default; |
| 23 ~SharedStyleFinderTest() override = default; | 25 ~SharedStyleFinderTest() override = default; |
| 24 | 26 |
| 25 Document& document() { return m_dummyPageHolder->document(); } | 27 Document& document() { return m_dummyPageHolder->document(); } |
| 26 | 28 |
| 27 void setBodyContent(const String& html) { | 29 void setBodyContent(const String& html) { |
| 28 document().body()->setInnerHTML(html); | 30 document().body()->setInnerHTML(html); |
| 29 document().view()->updateAllLifecyclePhases(); | 31 document().view()->updateAllLifecyclePhases(); |
| 30 } | 32 } |
| 31 | 33 |
| 34 ShadowRoot& attachShadow(Element& host) { |
| 35 ShadowRootInit init; |
| 36 init.setMode("open"); |
| 37 ShadowRoot* shadowRoot = |
| 38 host.attachShadow(ScriptState::forMainWorld(document().frame()), init, |
| 39 ASSERT_NO_EXCEPTION); |
| 40 EXPECT_TRUE(shadowRoot); |
| 41 return *shadowRoot; |
| 42 } |
| 43 |
| 32 void addSelector(const String& selector) { | 44 void addSelector(const String& selector) { |
| 33 StyleRuleBase* newRule = | 45 StyleRuleBase* newRule = |
| 34 CSSParser::parseRule(CSSParserContext(HTMLStandardMode, nullptr), | 46 CSSParser::parseRule(CSSParserContext(HTMLStandardMode, nullptr), |
| 35 nullptr, selector + "{color:pink}"); | 47 nullptr, selector + "{color:pink}"); |
| 36 m_ruleSet->addStyleRule(static_cast<StyleRule*>(newRule), | 48 m_ruleSet->addStyleRule(static_cast<StyleRule*>(newRule), |
| 37 RuleHasNoSpecialState); | 49 RuleHasNoSpecialState); |
| 38 } | 50 } |
| 39 | 51 |
| 40 void finishAddingSelectors() { | 52 void finishAddingSelectors() { |
| 41 m_siblingRuleSet = makeRuleSet(m_ruleSet->features().siblingRules()); | 53 m_siblingRuleSet = makeRuleSet(m_ruleSet->features().siblingRules()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 ASSERT_TRUE(a); | 187 ASSERT_TRUE(a); |
| 176 ASSERT_TRUE(b); | 188 ASSERT_TRUE(b); |
| 177 | 189 |
| 178 EXPECT_FALSE(a->isDragged()); | 190 EXPECT_FALSE(a->isDragged()); |
| 179 EXPECT_FALSE(b->isDragged()); | 191 EXPECT_FALSE(b->isDragged()); |
| 180 | 192 |
| 181 EXPECT_TRUE(matchesUncommonAttributeRuleSet(*a)); | 193 EXPECT_TRUE(matchesUncommonAttributeRuleSet(*a)); |
| 182 EXPECT_FALSE(matchesUncommonAttributeRuleSet(*b)); | 194 EXPECT_FALSE(matchesUncommonAttributeRuleSet(*b)); |
| 183 } | 195 } |
| 184 | 196 |
| 197 TEST_F(SharedStyleFinderTest, SlottedPseudoWithAttribute) { |
| 198 setBodyContent("<div id=host><div id=a></div><div id=b attr></div></div>"); |
| 199 Element* host = document().getElementById("host"); |
| 200 ShadowRoot& root = attachShadow(*host); |
| 201 root.setInnerHTML("<slot></slot>"); |
| 202 document().updateDistribution(); |
| 203 |
| 204 addSelector("::slotted([attr])"); |
| 205 finishAddingSelectors(); |
| 206 |
| 207 Element* a = document().getElementById("a"); |
| 208 Element* b = document().getElementById("b"); |
| 209 |
| 210 EXPECT_TRUE(a->assignedSlot()); |
| 211 EXPECT_TRUE(b->assignedSlot()); |
| 212 |
| 213 EXPECT_FALSE(matchesUncommonAttributeRuleSet(*a)); |
| 214 EXPECT_TRUE(matchesUncommonAttributeRuleSet(*b)); |
| 215 } |
| 216 |
| 185 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |