OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/StyleEngine.h" | 5 #include "core/dom/StyleEngine.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
9 #include "core/css/CSSRuleList.h" | 9 #include "core/css/CSSRuleList.h" |
10 #include "core/css/CSSStyleRule.h" | 10 #include "core/css/CSSStyleRule.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 GetDocument().body()->setInnerHTML( | 80 GetDocument().body()->setInnerHTML( |
81 "<style>div { color: red }</style><div id='t1'>Green</div><div></div>"); | 81 "<style>div { color: red }</style><div id='t1'>Green</div><div></div>"); |
82 GetDocument().View()->UpdateAllLifecyclePhases(); | 82 GetDocument().View()->UpdateAllLifecyclePhases(); |
83 | 83 |
84 Element* t1 = GetDocument().getElementById("t1"); | 84 Element* t1 = GetDocument().getElementById("t1"); |
85 ASSERT_TRUE(t1); | 85 ASSERT_TRUE(t1); |
86 ASSERT_TRUE(t1->GetComputedStyle()); | 86 ASSERT_TRUE(t1->GetComputedStyle()); |
87 EXPECT_EQ(MakeRGB(255, 0, 0), | 87 EXPECT_EQ(MakeRGB(255, 0, 0), |
88 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); | 88 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
89 | 89 |
90 unsigned before_count = GetStyleEngine().StyleForElementCount(); | 90 const unsigned initial_count = GetStyleEngine().StyleForElementCount(); |
91 | 91 |
92 StyleSheetContents* parsed_sheet = | 92 StyleSheetContents* green_parsed_sheet = |
93 StyleSheetContents::Create(CSSParserContext::Create(GetDocument())); | 93 StyleSheetContents::Create(CSSParserContext::Create(GetDocument())); |
94 parsed_sheet->ParseString("#t1 { color: green }"); | 94 green_parsed_sheet->ParseString("#t1 { color: green }"); |
95 GetStyleEngine().InjectAuthorSheet(parsed_sheet); | 95 int green_css_id = GetStyleEngine().InjectAuthorSheet(green_parsed_sheet); |
| 96 EXPECT_EQ(1, green_css_id); |
| 97 EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
96 GetDocument().View()->UpdateAllLifecyclePhases(); | 98 GetDocument().View()->UpdateAllLifecyclePhases(); |
97 | 99 |
98 unsigned after_count = GetStyleEngine().StyleForElementCount(); | 100 EXPECT_EQ(1u, GetStyleEngine().StyleForElementCount() - initial_count); |
99 EXPECT_EQ(1u, after_count - before_count); | |
100 | 101 |
101 ASSERT_TRUE(t1->GetComputedStyle()); | 102 ASSERT_TRUE(t1->GetComputedStyle()); |
102 EXPECT_EQ(MakeRGB(0, 128, 0), | 103 EXPECT_EQ(MakeRGB(0, 128, 0), |
103 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); | 104 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 105 |
| 106 StyleSheetContents* blue_parsed_sheet = |
| 107 StyleSheetContents::Create(CSSParserContext::Create(GetDocument())); |
| 108 blue_parsed_sheet->ParseString("#t1 { color: blue }"); |
| 109 int blue_css_id = GetStyleEngine().InjectAuthorSheet(blue_parsed_sheet); |
| 110 EXPECT_EQ(2, blue_css_id); |
| 111 EXPECT_EQ(2u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 112 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 113 |
| 114 EXPECT_EQ(2u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 115 |
| 116 ASSERT_TRUE(t1->GetComputedStyle()); |
| 117 EXPECT_EQ(MakeRGB(0, 0, 255), |
| 118 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 119 |
| 120 EXPECT_TRUE(GetStyleEngine().RemoveInjectedAuthorSheet(green_css_id)); |
| 121 EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 122 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 123 EXPECT_EQ(3u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 124 ASSERT_TRUE(t1->GetComputedStyle()); |
| 125 EXPECT_EQ(MakeRGB(0, 0, 255), |
| 126 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 127 |
| 128 EXPECT_TRUE(GetStyleEngine().RemoveInjectedAuthorSheet(blue_css_id)); |
| 129 EXPECT_EQ(0u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 130 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 131 EXPECT_EQ(4u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 132 ASSERT_TRUE(t1->GetComputedStyle()); |
| 133 EXPECT_EQ(MakeRGB(255, 0, 0), |
| 134 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
104 } | 135 } |
105 | 136 |
106 TEST_F(StyleEngineTest, TextToSheetCache) { | 137 TEST_F(StyleEngineTest, TextToSheetCache) { |
107 HTMLStyleElement* element = HTMLStyleElement::Create(GetDocument(), false); | 138 HTMLStyleElement* element = HTMLStyleElement::Create(GetDocument(), false); |
108 | 139 |
109 String sheet_text("div {}"); | 140 String sheet_text("div {}"); |
110 TextPosition min_pos = TextPosition::MinimumPosition(); | 141 TextPosition min_pos = TextPosition::MinimumPosition(); |
111 StyleEngineContext context; | 142 StyleEngineContext context; |
112 | 143 |
113 CSSStyleSheet* sheet1 = | 144 CSSStyleSheet* sheet1 = |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 "</style>" | 582 "</style>" |
552 "<div id='t1'></div>" | 583 "<div id='t1'></div>" |
553 "<span></span>"); | 584 "<span></span>"); |
554 | 585 |
555 GetStyleEngine().UpdateActiveStyle(); | 586 GetStyleEngine().UpdateActiveStyle(); |
556 EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation()); | 587 EXPECT_FALSE(GetDocument().ChildNeedsStyleInvalidation()); |
557 EXPECT_FALSE(GetDocument().NeedsStyleInvalidation()); | 588 EXPECT_FALSE(GetDocument().NeedsStyleInvalidation()); |
558 } | 589 } |
559 | 590 |
560 } // namespace blink | 591 } // namespace blink |
OLD | NEW |