| Index: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| index f40e71e9c02545d88505e3122a8c3dc8e1c6da10..6be56f832db9434f75d3aa2a0013f6a80555b14d 100644
|
| --- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| @@ -7,6 +7,7 @@
|
| #include "core/css/StyleSheetContents.h"
|
| #include "core/dom/Document.h"
|
| #include "core/dom/NodeComputedStyle.h"
|
| +#include "core/dom/shadow/ShadowRootInit.h"
|
| #include "core/frame/FrameView.h"
|
| #include "core/html/HTMLElement.h"
|
| #include "core/html/HTMLStyleElement.h"
|
| @@ -26,6 +27,8 @@ protected:
|
|
|
| bool isDocumentStyleSheetCollectionClean() { return !styleEngine().shouldUpdateDocumentStyleSheetCollection(AnalyzedStyleUpdate); }
|
|
|
| + void scheduleInvalidationsForRules(TreeScope&, const String& cssText);
|
| +
|
| private:
|
| std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
|
| };
|
| @@ -35,6 +38,17 @@ void StyleEngineTest::SetUp()
|
| m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
|
| }
|
|
|
| +void StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope, const String& cssText)
|
| +{
|
| + StyleSheetContents* sheet = StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr));
|
| + sheet->parseString(cssText);
|
| + HeapVector<Member<const RuleSet>> ruleSets;
|
| + RuleSet& ruleSet = sheet->ensureRuleSet(MediaQueryEvaluator(), RuleHasDocumentSecurityOrigin);
|
| + ruleSet.compactRulesIfNeeded();
|
| + ruleSets.append(&ruleSet);
|
| + styleEngine().scheduleInvalidationsForRuleSets(treeScope, ruleSets);
|
| +}
|
| +
|
| TEST_F(StyleEngineTest, DocumentDirtyAfterInject)
|
| {
|
| StyleSheetContents* parsedSheet = StyleSheetContents::create(CSSParserContext(document(), nullptr));
|
| @@ -102,4 +116,87 @@ TEST_F(StyleEngineTest, TextToSheetCache)
|
| EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache());
|
| }
|
|
|
| +TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors)
|
| +{
|
| + document().body()->setInnerHTML(
|
| + "<div>"
|
| + " <span></span>"
|
| + " <div></div>"
|
| + "</div>", ASSERT_NO_EXCEPTION);
|
| +
|
| + document().view()->updateAllLifecyclePhases();
|
| +
|
| + unsigned beforeCount = styleEngine().styleForElementCount();
|
| +
|
| + scheduleInvalidationsForRules(document(), "span { background: green}");
|
| + document().view()->updateAllLifecyclePhases();
|
| +
|
| + unsigned afterCount = styleEngine().styleForElementCount();
|
| +
|
| + EXPECT_EQ(1u, afterCount - beforeCount);
|
| +
|
| + beforeCount = afterCount;
|
| + scheduleInvalidationsForRules(document(), "body div { background: green}");
|
| + document().view()->updateAllLifecyclePhases();
|
| +
|
| + afterCount = styleEngine().styleForElementCount();
|
| +
|
| + EXPECT_EQ(2u, afterCount - beforeCount);
|
| +}
|
| +
|
| +TEST_F(StyleEngineTest, RuleSetInvalidationHost)
|
| +{
|
| + document().body()->setInnerHTML("<div id=nohost></div><div id=host></div>", ASSERT_NO_EXCEPTION);
|
| + Element* host = document().getElementById("host");
|
| + ASSERT_TRUE(host);
|
| +
|
| + ShadowRootInit init;
|
| + init.setMode("open");
|
| + ShadowRoot* shadowRoot = host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
|
| + ASSERT_TRUE(shadowRoot);
|
| +
|
| + shadowRoot->setInnerHTML("<div></div><div></div><div></div>", ASSERT_NO_EXCEPTION);
|
| + document().view()->updateAllLifecyclePhases();
|
| +
|
| + unsigned beforeCount = styleEngine().styleForElementCount();
|
| + scheduleInvalidationsForRules(*shadowRoot, ":host(#nohost), #nohost { background: green}");
|
| + document().view()->updateAllLifecyclePhases();
|
| + unsigned afterCount = styleEngine().styleForElementCount();
|
| + EXPECT_EQ(0u, afterCount - beforeCount);
|
| +
|
| + beforeCount = afterCount;
|
| + scheduleInvalidationsForRules(*shadowRoot, ":host(#host) { background: green}");
|
| + document().view()->updateAllLifecyclePhases();
|
| + afterCount = styleEngine().styleForElementCount();
|
| + EXPECT_EQ(1u, afterCount - beforeCount);
|
| +}
|
| +
|
| +TEST_F(StyleEngineTest, RuleSetInvalidationSlotted)
|
| +{
|
| + document().body()->setInnerHTML(
|
| + "<div id=host>"
|
| + " <span slot=other class=s1></span>"
|
| + " <span class=s2></span>"
|
| + " <span class=s1></span>"
|
| + " <span></span>"
|
| + "</div>", ASSERT_NO_EXCEPTION);
|
| +
|
| + Element* host = document().getElementById("host");
|
| + ASSERT_TRUE(host);
|
| +
|
| + ShadowRootInit init;
|
| + init.setMode("open");
|
| + ShadowRoot* shadowRoot = host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSERT_NO_EXCEPTION);
|
| + ASSERT_TRUE(shadowRoot);
|
| +
|
| + shadowRoot->setInnerHTML("<slot name=other></slot><slot></slot>", ASSERT_NO_EXCEPTION);
|
| + document().view()->updateAllLifecyclePhases();
|
| +
|
| + unsigned beforeCount = styleEngine().styleForElementCount();
|
| + scheduleInvalidationsForRules(*shadowRoot, "::slotted(.s1) { background: green}");
|
| + document().view()->updateAllLifecyclePhases();
|
| + unsigned afterCount = styleEngine().styleForElementCount();
|
| + EXPECT_EQ(2u, afterCount - beforeCount);
|
| +}
|
| +
|
| } // namespace blink
|
|
|