Commit e8bfb9e9 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Helper method for attaching shadow roots in tests.

Change-Id: I761e0bdd668bfcc99d03aab75cb148b83ffd4ba9
Reviewed-on: https://chromium-review.googlesource.com/965065Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543680}
parent 8d15c06e
...@@ -46,6 +46,8 @@ class StyleEngineTest : public ::testing::Test { ...@@ -46,6 +46,8 @@ 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_;
}; };
...@@ -72,6 +74,14 @@ StyleEngineTest::ScheduleInvalidationsForRules(TreeScope& tree_scope, ...@@ -72,6 +74,14 @@ 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()));
...@@ -713,11 +723,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) { ...@@ -713,11 +723,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString("<div></div><div></div><div></div>"); shadow_root->SetInnerHTMLFromString("<div></div><div></div><div></div>");
...@@ -763,11 +769,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) { ...@@ -763,11 +769,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationSlotted) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString("<slot name=other></slot><slot></slot>"); shadow_root->SetInnerHTMLFromString("<slot name=other></slot><slot></slot>");
...@@ -795,11 +797,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) { ...@@ -795,11 +797,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHostContext) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString( shadow_root->SetInnerHTMLFromString(
...@@ -828,11 +826,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) { ...@@ -828,11 +826,7 @@ TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) {
Element* host = GetDocument().getElementById("host"); Element* host = GetDocument().getElementById("host");
ASSERT_TRUE(host); ASSERT_TRUE(host);
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString( shadow_root->SetInnerHTMLFromString(
...@@ -1049,11 +1043,7 @@ TEST_F(StyleEngineTest, NoScheduledRuleSetInvalidationsOnNewShadow) { ...@@ -1049,11 +1043,7 @@ TEST_F(StyleEngineTest, NoScheduledRuleSetInvalidationsOnNewShadow) {
ASSERT_TRUE(host); ASSERT_TRUE(host);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString(R"HTML( shadow_root->SetInnerHTMLFromString(R"HTML(
...@@ -1118,11 +1108,7 @@ TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) { ...@@ -1118,11 +1108,7 @@ TEST_F(StyleEngineTest, StyleSheetsForStyleSheetList_ShadowRoot) {
ASSERT_TRUE(host); ASSERT_TRUE(host);
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
ShadowRootInit init; ShadowRoot* shadow_root = AttachShadowTo(*host);
init.setMode("open");
ShadowRoot* shadow_root =
host->attachShadow(ToScriptStateForMainWorld(GetDocument().GetFrame()),
init, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(shadow_root); ASSERT_TRUE(shadow_root);
shadow_root->SetInnerHTMLFromString("<style>span { color: green }</style>"); shadow_root->SetInnerHTMLFromString("<style>span { color: green }</style>");
......
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