Commit e8c01db4 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make StyleEngineTest to use Element::AttachShadowRootInternal()

This patch changes |StyleEngineTest| to use |AttachShadowRootInternal()| instead
of |Element::attachShadow()| to avoid using script only functions for improving
code health.

Change-Id: I29bb95e0e70015aaca4ed35a5ed440fd9ec7d9e3
Reviewed-on: https://chromium-review.googlesource.com/1068574Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560976}
parent c8f7539d
...@@ -48,8 +48,6 @@ class StyleEngineTest : public testing::Test { ...@@ -48,8 +48,6 @@ class StyleEngineTest : public testing::Test {
RuleSetInvalidation ScheduleInvalidationsForRules(TreeScope&, RuleSetInvalidation ScheduleInvalidationsForRules(TreeScope&,
const String& css_text); const String& css_text);
ShadowRoot* AttachShadowTo(Element&);
private: private:
std::unique_ptr<DummyPageHolder> dummy_page_holder_; std::unique_ptr<DummyPageHolder> dummy_page_holder_;
}; };
...@@ -76,14 +74,6 @@ StyleEngineTest::ScheduleInvalidationsForRules(TreeScope& tree_scope, ...@@ -76,14 +74,6 @@ StyleEngineTest::ScheduleInvalidationsForRules(TreeScope& tree_scope,
return kRuleSetInvalidationsScheduled; return kRuleSetInvalidationsScheduled;
} }
ShadowRoot* StyleEngineTest::AttachShadowTo(Element& element) {
ShadowRootInit init;
init.setMode("open");
return element.attachShadow(
ToScriptStateForMainWorld(GetDocument().GetFrame()), init,
ASSERT_NO_EXCEPTION);
}
TEST_F(StyleEngineTest, DocumentDirtyAfterInject) { TEST_F(StyleEngineTest, DocumentDirtyAfterInject) {
StyleSheetContents* parsed_sheet = StyleSheetContents* parsed_sheet =
StyleSheetContents::Create(CSSParserContext::Create(GetDocument())); StyleSheetContents::Create(CSSParserContext::Create(GetDocument()));
...@@ -725,36 +715,36 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) { ...@@ -725,36 +715,36 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString("<div></div><div></div><div></div>"); shadow_root.SetInnerHTMLFromString("<div></div><div></div><div></div>");
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned before_count = GetStyleEngine().StyleForElementCount(); unsigned before_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, ":host(#nohost), #nohost { background: green}"), shadow_root, ":host(#nohost), #nohost { background: green}"),
kRuleSetInvalidationsScheduled); kRuleSetInvalidationsScheduled);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned after_count = GetStyleEngine().StyleForElementCount(); unsigned after_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(0u, after_count - before_count); EXPECT_EQ(0u, after_count - before_count);
before_count = after_count; before_count = after_count;
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root, EXPECT_EQ(ScheduleInvalidationsForRules(shadow_root,
":host(#host) { background: green}"), ":host(#host) { background: green}"),
kRuleSetInvalidationsScheduled); kRuleSetInvalidationsScheduled);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
after_count = GetStyleEngine().StyleForElementCount(); after_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(1u, after_count - before_count); EXPECT_EQ(1u, after_count - before_count);
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root, EXPECT_EQ(ScheduleInvalidationsForRules(shadow_root,
":host(div) { background: green}"), ":host(div) { background: green}"),
kRuleSetInvalidationsScheduled); kRuleSetInvalidationsScheduled);
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root, EXPECT_EQ(ScheduleInvalidationsForRules(shadow_root,
":host(*) { background: green}"), ":host(*) { background: green}"),
kRuleSetInvalidationFullRecalc); kRuleSetInvalidationFullRecalc);
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, ":host(*) :hover { background: green}"), shadow_root, ":host(*) :hover { background: green}"),
kRuleSetInvalidationFullRecalc); kRuleSetInvalidationFullRecalc);
} }
...@@ -771,22 +761,22 @@ TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) { ...@@ -771,22 +761,22 @@ TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString("<slot name=other></slot><slot></slot>"); shadow_root.SetInnerHTMLFromString("<slot name=other></slot><slot></slot>");
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned before_count = GetStyleEngine().StyleForElementCount(); unsigned before_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, "::slotted(.s1) { background: green}"), shadow_root, "::slotted(.s1) { background: green}"),
kRuleSetInvalidationsScheduled); kRuleSetInvalidationsScheduled);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned after_count = GetStyleEngine().StyleForElementCount(); unsigned after_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(4u, after_count - before_count); EXPECT_EQ(4u, after_count - before_count);
before_count = after_count; before_count = after_count;
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root, EXPECT_EQ(ScheduleInvalidationsForRules(shadow_root,
"::slotted(*) { background: green}"), "::slotted(*) { background: green}"),
kRuleSetInvalidationsScheduled); kRuleSetInvalidationsScheduled);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
...@@ -799,27 +789,26 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) { ...@@ -799,27 +789,26 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString( shadow_root.SetInnerHTMLFromString(
"<div></div><div class=a></div><div></div>"); "<div></div><div class=a></div><div></div>");
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned before_count = GetStyleEngine().StyleForElementCount(); unsigned before_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ( EXPECT_EQ(ScheduleInvalidationsForRules(
ScheduleInvalidationsForRules( shadow_root, ":host-context(.nomatch) .a { background: green}"),
*shadow_root, ":host-context(.nomatch) .a { background: green}"), kRuleSetInvalidationsScheduled);
kRuleSetInvalidationsScheduled);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
unsigned after_count = GetStyleEngine().StyleForElementCount(); unsigned after_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(1u, after_count - before_count); EXPECT_EQ(1u, after_count - before_count);
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, ":host-context(:hover) { background: green}"), shadow_root, ":host-context(:hover) { background: green}"),
kRuleSetInvalidationFullRecalc); kRuleSetInvalidationFullRecalc);
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, ":host-context(#host) { background: green}"), shadow_root, ":host-context(#host) { background: green}"),
kRuleSetInvalidationFullRecalc); kRuleSetInvalidationFullRecalc);
} }
...@@ -828,15 +817,15 @@ TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) { ...@@ -828,15 +817,15 @@ TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString( shadow_root.SetInnerHTMLFromString(
"<div></div><div class=a></div><div></div>"); "<div></div><div class=a></div><div></div>");
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_EQ(ScheduleInvalidationsForRules( EXPECT_EQ(ScheduleInvalidationsForRules(
*shadow_root, ".a ::content span { background: green}"), shadow_root, ".a ::content span { background: green}"),
kRuleSetInvalidationFullRecalc); kRuleSetInvalidationFullRecalc);
} }
...@@ -1045,10 +1034,10 @@ TEST_F(StyleEngineTest, NoScheduledRuleSetInvalidationsOnNewShadow) { ...@@ -1045,10 +1034,10 @@ TEST_F(StyleEngineTest, NoScheduledRuleSetInvalidationsOnNewShadow) {
ASSERT_TRUE(host); ASSERT_TRUE(host);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString(R"HTML( shadow_root.SetInnerHTMLFromString(R"HTML(
<style> <style>
span { color: green } span { color: green }
t1 { color: green } t1 { color: green }
...@@ -1110,28 +1099,28 @@ TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) { ...@@ -1110,28 +1099,28 @@ TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) {
ASSERT_TRUE(host); ASSERT_TRUE(host);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
ShadowRoot* shadow_root = AttachShadowTo(*host); ShadowRoot& shadow_root =
ASSERT_TRUE(shadow_root); host->AttachShadowRootInternal(ShadowRootType::kOpen);
shadow_root->SetInnerHTMLFromString("<style>span { color: green }</style>"); shadow_root.SetInnerHTMLFromString("<style>span { color: green }</style>");
EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate());
const auto& sheet_list = const auto& sheet_list =
GetStyleEngine().StyleSheetsForStyleSheetList(*shadow_root); GetStyleEngine().StyleSheetsForStyleSheetList(shadow_root);
EXPECT_EQ(1u, sheet_list.size()); EXPECT_EQ(1u, sheet_list.size());
EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate());
shadow_root->SetInnerHTMLFromString( shadow_root.SetInnerHTMLFromString(
"<style>span { color: green }</style><style>div { color: pink }</style>"); "<style>span { color: green }</style><style>div { color: pink }</style>");
EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate());
const auto& second_sheet_list = const auto& second_sheet_list =
GetStyleEngine().StyleSheetsForStyleSheetList(*shadow_root); GetStyleEngine().StyleSheetsForStyleSheetList(shadow_root);
EXPECT_EQ(2u, second_sheet_list.size()); EXPECT_EQ(2u, second_sheet_list.size());
EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate());
GetStyleEngine().MarkAllTreeScopesDirty(); GetStyleEngine().MarkAllTreeScopesDirty();
GetStyleEngine().StyleSheetsForStyleSheetList(*shadow_root); GetStyleEngine().StyleSheetsForStyleSheetList(shadow_root);
EXPECT_FALSE(GetStyleEngine().NeedsActiveStyleUpdate()); EXPECT_FALSE(GetStyleEngine().NeedsActiveStyleUpdate());
} }
......
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