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..d375746539938786bbbc420bb0c3bd6f9a130f86 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 }"); |
+ unsigned 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 }"); |
+ unsigned 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) { |