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

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

Issue 2835183002: Provide a method to remove inserted style sheet (Closed)
Patch Set: initial for review 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
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 da6ca9d5d107a85ed355a43256baf4db658dd210..e5691d68ab4681869f48ab948d753154c3432ba0 100644
--- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
+++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
@@ -87,20 +87,51 @@ 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 }");
+ int green_css_id = GetStyleEngine().InjectAuthorSheet(green_parsed_sheet);
+ EXPECT_EQ(1, green_css_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 }");
+ int blue_css_id = GetStyleEngine().InjectAuthorSheet(blue_parsed_sheet);
+ EXPECT_EQ(2, blue_css_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));
+
+ EXPECT_TRUE(GetStyleEngine().RemoveInjectedAuthorSheet(green_css_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));
+
+ EXPECT_TRUE(GetStyleEngine().RemoveInjectedAuthorSheet(blue_css_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) {

Powered by Google App Engine
This is Rietveld 408576698