Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp

Issue 2835183002: Provide a method to remove inserted style sheet (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.cpp ('k') | third_party/WebKit/Source/web/WebDocument.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d6979b2c8da494b263afc2928dbcbfbce2a69cec..4e3fcb4833c19c45a63ae025227bce4a0f7f71b4 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
@@ -87,20 +87,53 @@ TEST_F(StyleEngineTest, AnalyzedInject) {
EXPECT_EQ(MakeRGB(255, 0, 0),
t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor));
- unsigned before_count = GetStyleEngine().StyleForElementCount();
+ const unsigned initial_count = GetStyleEngine().StyleForElementCount();
- StyleSheetContents* parsed_sheet =
+ StyleSheetContents* green_parsed_sheet =
StyleSheetContents::Create(CSSParserContext::Create(GetDocument()));
- parsed_sheet->ParseString("#t1 { color: green }");
- GetStyleEngine().InjectAuthorSheet(parsed_sheet);
+ green_parsed_sheet->ParseString("#t1 { color: green }");
+ WebStyleSheetId green_id =
+ GetStyleEngine().InjectAuthorSheet(green_parsed_sheet);
+ EXPECT_EQ(1u, green_id);
+ EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size());
GetDocument().View()->UpdateAllLifecyclePhases();
- unsigned after_count = GetStyleEngine().StyleForElementCount();
- EXPECT_EQ(1u, after_count - before_count);
+ EXPECT_EQ(1u, GetStyleEngine().StyleForElementCount() - initial_count);
ASSERT_TRUE(t1->GetComputedStyle());
EXPECT_EQ(MakeRGB(0, 128, 0),
t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor));
+
+ StyleSheetContents* blue_parsed_sheet =
+ StyleSheetContents::Create(CSSParserContext::Create(GetDocument()));
+ blue_parsed_sheet->ParseString("#t1 { color: blue }");
+ WebStyleSheetId blue_id =
+ GetStyleEngine().InjectAuthorSheet(blue_parsed_sheet);
+ EXPECT_EQ(2u, blue_id);
+ EXPECT_EQ(2u, GetStyleEngine().InjectedAuthorStyleSheets().size());
+ GetDocument().View()->UpdateAllLifecyclePhases();
+
+ EXPECT_EQ(2u, GetStyleEngine().StyleForElementCount() - initial_count);
+
+ ASSERT_TRUE(t1->GetComputedStyle());
+ EXPECT_EQ(MakeRGB(0, 0, 255),
+ t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor));
+
+ GetStyleEngine().RemoveInjectedAuthorSheet(green_id);
+ EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size());
+ GetDocument().View()->UpdateAllLifecyclePhases();
+ EXPECT_EQ(3u, GetStyleEngine().StyleForElementCount() - initial_count);
+ ASSERT_TRUE(t1->GetComputedStyle());
+ EXPECT_EQ(MakeRGB(0, 0, 255),
+ t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor));
+
+ GetStyleEngine().RemoveInjectedAuthorSheet(blue_id);
+ EXPECT_EQ(0u, GetStyleEngine().InjectedAuthorStyleSheets().size());
+ GetDocument().View()->UpdateAllLifecyclePhases();
+ EXPECT_EQ(4u, GetStyleEngine().StyleForElementCount() - initial_count);
+ ASSERT_TRUE(t1->GetComputedStyle());
+ EXPECT_EQ(MakeRGB(255, 0, 0),
+ t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor));
}
TEST_F(StyleEngineTest, TextToSheetCache) {
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.cpp ('k') | third_party/WebKit/Source/web/WebDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698