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/CSSRuleList.h" |
| 8 #include "core/css/CSSStyleRule.h" |
| 9 #include "core/css/CSSStyleSheet.h" |
7 #include "core/css/StyleSheetContents.h" | 10 #include "core/css/StyleSheetContents.h" |
8 #include "core/css/parser/CSSParserContext.h" | 11 #include "core/css/parser/CSSParserContext.h" |
9 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
10 #include "core/dom/NodeComputedStyle.h" | 13 #include "core/dom/NodeComputedStyle.h" |
11 #include "core/dom/shadow/ShadowRootInit.h" | 14 #include "core/dom/shadow/ShadowRootInit.h" |
12 #include "core/frame/FrameView.h" | 15 #include "core/frame/FrameView.h" |
13 #include "core/html/HTMLElement.h" | 16 #include "core/html/HTMLElement.h" |
14 #include "core/html/HTMLStyleElement.h" | 17 #include "core/html/HTMLStyleElement.h" |
15 #include "core/testing/DummyPageHolder.h" | 18 #include "core/testing/DummyPageHolder.h" |
16 #include "platform/heap/Heap.h" | 19 #include "platform/heap/Heap.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 document().view()->updateAllLifecyclePhases(); | 369 document().view()->updateAllLifecyclePhases(); |
367 | 370 |
368 unsigned afterCount = styleEngine().styleForElementCount(); | 371 unsigned afterCount = styleEngine().styleForElementCount(); |
369 EXPECT_EQ(0u, afterCount - beforeCount); | 372 EXPECT_EQ(0u, afterCount - beforeCount); |
370 | 373 |
371 ASSERT_TRUE(t1->computedStyle()); | 374 ASSERT_TRUE(t1->computedStyle()); |
372 EXPECT_EQ(makeRGB(0, 128, 0), | 375 EXPECT_EQ(makeRGB(0, 128, 0), |
373 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); | 376 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
374 } | 377 } |
375 | 378 |
| 379 TEST_F(StyleEngineTest, ModifyStyleRuleMatchedPropertiesCache) { |
| 380 // Test that the MatchedPropertiesCache is cleared when a StyleRule is |
| 381 // modified. The MatchedPropertiesCache caches results based on |
| 382 // StylePropertySet pointers. When a mutable StylePropertySet is modified, |
| 383 // the pointer doesn't change, yet the declarations do. |
| 384 |
| 385 document().body()->setInnerHTML( |
| 386 "<style id='s1'>#t1 { color: blue }</style>" |
| 387 "<div id='t1'>Green</div>"); |
| 388 document().view()->updateAllLifecyclePhases(); |
| 389 |
| 390 Element* t1 = document().getElementById("t1"); |
| 391 ASSERT_TRUE(t1); |
| 392 ASSERT_TRUE(t1->computedStyle()); |
| 393 EXPECT_EQ(makeRGB(0, 0, 255), |
| 394 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 395 |
| 396 CSSStyleSheet* sheet = toCSSStyleSheet(document().styleSheets().item(0)); |
| 397 ASSERT_TRUE(sheet); |
| 398 ASSERT_TRUE(sheet->cssRules()); |
| 399 CSSStyleRule* styleRule = toCSSStyleRule(sheet->cssRules()->item(0)); |
| 400 ASSERT_TRUE(styleRule); |
| 401 ASSERT_TRUE(styleRule->style()); |
| 402 |
| 403 // Modify the StylePropertySet once to make it a mutable set. Subsequent |
| 404 // modifications will not change the StylePropertySet pointer and cache hash |
| 405 // value will be the same. |
| 406 styleRule->style()->setProperty("color", "red", "", ASSERT_NO_EXCEPTION); |
| 407 document().view()->updateAllLifecyclePhases(); |
| 408 |
| 409 ASSERT_TRUE(t1->computedStyle()); |
| 410 EXPECT_EQ(makeRGB(255, 0, 0), |
| 411 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 412 |
| 413 styleRule->style()->setProperty("color", "green", "", ASSERT_NO_EXCEPTION); |
| 414 document().view()->updateAllLifecyclePhases(); |
| 415 |
| 416 ASSERT_TRUE(t1->computedStyle()); |
| 417 EXPECT_EQ(makeRGB(0, 128, 0), |
| 418 t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); |
| 419 } |
| 420 |
376 } // namespace blink | 421 } // namespace blink |
OLD | NEW |