| 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 "core/css/StyleSheetContents.h" | 7 #include "core/css/StyleSheetContents.h" |
| 8 #include "core/css/parser/CSSParserContext.h" | 8 #include "core/css/parser/CSSParserContext.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/NodeComputedStyle.h" | 10 #include "core/dom/NodeComputedStyle.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Check that we did not use a cached StyleSheetContents after the garbage | 134 // Check that we did not use a cached StyleSheetContents after the garbage |
| 135 // collection. | 135 // collection. |
| 136 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); | 136 EXPECT_FALSE(sheet1->contents()->isUsedFromTextCache()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors) { | 139 TEST_F(StyleEngineTest, RuleSetInvalidationTypeSelectors) { |
| 140 document().body()->setInnerHTML( | 140 document().body()->setInnerHTML( |
| 141 "<div>" | 141 "<div>" |
| 142 " <span></span>" | 142 " <span></span>" |
| 143 " <div></div>" | 143 " <div></div>" |
| 144 "</div>"); | 144 "</div>" |
| 145 "<b></b><b></b><b></b><b></b>" |
| 146 "<i id=i>" |
| 147 " <i>" |
| 148 " <b></b>" |
| 149 " </i>" |
| 150 "</i>"); |
| 145 | 151 |
| 146 document().view()->updateAllLifecyclePhases(); | 152 document().view()->updateAllLifecyclePhases(); |
| 147 | 153 |
| 148 unsigned beforeCount = styleEngine().styleForElementCount(); | 154 unsigned beforeCount = styleEngine().styleForElementCount(); |
| 149 EXPECT_EQ( | 155 EXPECT_EQ( |
| 150 scheduleInvalidationsForRules(document(), "span { background: green}"), | 156 scheduleInvalidationsForRules(document(), "span { background: green}"), |
| 151 RuleSetInvalidationsScheduled); | 157 RuleSetInvalidationsScheduled); |
| 152 document().view()->updateAllLifecyclePhases(); | 158 document().view()->updateAllLifecyclePhases(); |
| 153 unsigned afterCount = styleEngine().styleForElementCount(); | 159 unsigned afterCount = styleEngine().styleForElementCount(); |
| 154 EXPECT_EQ(1u, afterCount - beforeCount); | 160 EXPECT_EQ(1u, afterCount - beforeCount); |
| 155 | 161 |
| 156 beforeCount = afterCount; | 162 beforeCount = afterCount; |
| 157 EXPECT_EQ(scheduleInvalidationsForRules(document(), | 163 EXPECT_EQ(scheduleInvalidationsForRules(document(), |
| 158 "body div { background: green}"), | 164 "body div { background: green}"), |
| 159 RuleSetInvalidationsScheduled); | 165 RuleSetInvalidationsScheduled); |
| 160 document().view()->updateAllLifecyclePhases(); | 166 document().view()->updateAllLifecyclePhases(); |
| 161 afterCount = styleEngine().styleForElementCount(); | 167 afterCount = styleEngine().styleForElementCount(); |
| 162 EXPECT_EQ(2u, afterCount - beforeCount); | 168 EXPECT_EQ(2u, afterCount - beforeCount); |
| 163 | 169 |
| 164 EXPECT_EQ( | 170 EXPECT_EQ( |
| 165 scheduleInvalidationsForRules(document(), "div * { background: green}"), | 171 scheduleInvalidationsForRules(document(), "div * { background: green}"), |
| 166 RuleSetInvalidationFullRecalc); | 172 RuleSetInvalidationFullRecalc); |
| 173 document().view()->updateAllLifecyclePhases(); |
| 174 |
| 175 beforeCount = styleEngine().styleForElementCount(); |
| 176 EXPECT_EQ( |
| 177 scheduleInvalidationsForRules(document(), "#i b { background: green}"), |
| 178 RuleSetInvalidationsScheduled); |
| 179 document().view()->updateAllLifecyclePhases(); |
| 180 afterCount = styleEngine().styleForElementCount(); |
| 181 EXPECT_EQ(1u, afterCount - beforeCount); |
| 182 } |
| 183 |
| 184 TEST_F(StyleEngineTest, RuleSetInvalidationClass) { |
| 185 document().body()->setInnerHTML( |
| 186 "<div class='container'>" |
| 187 " <div class='x'></div>" |
| 188 "</div>" |
| 189 "<div class='x'></div>" |
| 190 "<div class='x'></div>" |
| 191 "<div class='x'></div>"); |
| 192 |
| 193 document().view()->updateAllLifecyclePhases(); |
| 194 |
| 195 unsigned beforeCount = styleEngine().styleForElementCount(); |
| 196 EXPECT_EQ( |
| 197 scheduleInvalidationsForRules(document(), ".x { background: green }"), |
| 198 RuleSetInvalidationsScheduled); |
| 199 document().view()->updateAllLifecyclePhases(); |
| 200 unsigned afterCount = styleEngine().styleForElementCount(); |
| 201 EXPECT_EQ(4u, afterCount - beforeCount); |
| 202 |
| 203 beforeCount = afterCount; |
| 204 EXPECT_EQ(scheduleInvalidationsForRules( |
| 205 document(), ".container .x { background: green }"), |
| 206 RuleSetInvalidationsScheduled); |
| 207 document().view()->updateAllLifecyclePhases(); |
| 208 afterCount = styleEngine().styleForElementCount(); |
| 209 EXPECT_EQ(1u, afterCount - beforeCount); |
| 167 } | 210 } |
| 168 | 211 |
| 169 TEST_F(StyleEngineTest, RuleSetInvalidationHost) { | 212 TEST_F(StyleEngineTest, RuleSetInvalidationHost) { |
| 170 document().body()->setInnerHTML("<div id=nohost></div><div id=host></div>"); | 213 document().body()->setInnerHTML("<div id=nohost></div><div id=host></div>"); |
| 171 Element* host = document().getElementById("host"); | 214 Element* host = document().getElementById("host"); |
| 172 ASSERT_TRUE(host); | 215 ASSERT_TRUE(host); |
| 173 | 216 |
| 174 ShadowRootInit init; | 217 ShadowRootInit init; |
| 175 init.setMode("open"); | 218 init.setMode("open"); |
| 176 ShadowRoot* shadowRoot = host->attachShadow( | 219 ShadowRoot* shadowRoot = host->attachShadow( |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 410 |
| 368 unsigned afterCount = styleEngine().styleForElementCount(); | 411 unsigned afterCount = styleEngine().styleForElementCount(); |
| 369 EXPECT_EQ(0u, afterCount - beforeCount); | 412 EXPECT_EQ(0u, afterCount - beforeCount); |
| 370 | 413 |
| 371 ASSERT_TRUE(t1->computedStyle()); | 414 ASSERT_TRUE(t1->computedStyle()); |
| 372 EXPECT_EQ(makeRGB(0, 128, 0), | 415 EXPECT_EQ(makeRGB(0, 128, 0), |
| 373 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); | 416 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 374 } | 417 } |
| 375 | 418 |
| 376 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |