| 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 WebStyleSheetId green_id = |
| 96 GetStyleEngine().InjectAuthorSheet(green_parsed_sheet); |
| 97 EXPECT_EQ(1u, green_id); |
| 98 EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 96 GetDocument().View()->UpdateAllLifecyclePhases(); | 99 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 97 | 100 |
| 98 unsigned after_count = GetStyleEngine().StyleForElementCount(); | 101 EXPECT_EQ(1u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 99 EXPECT_EQ(1u, after_count - before_count); | |
| 100 | 102 |
| 101 ASSERT_TRUE(t1->GetComputedStyle()); | 103 ASSERT_TRUE(t1->GetComputedStyle()); |
| 102 EXPECT_EQ(MakeRGB(0, 128, 0), | 104 EXPECT_EQ(MakeRGB(0, 128, 0), |
| 103 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); | 105 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 106 |
| 107 StyleSheetContents* blue_parsed_sheet = |
| 108 StyleSheetContents::Create(CSSParserContext::Create(GetDocument())); |
| 109 blue_parsed_sheet->ParseString("#t1 { color: blue }"); |
| 110 WebStyleSheetId blue_id = |
| 111 GetStyleEngine().InjectAuthorSheet(blue_parsed_sheet); |
| 112 EXPECT_EQ(2u, blue_id); |
| 113 EXPECT_EQ(2u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 114 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 115 |
| 116 EXPECT_EQ(2u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 117 |
| 118 ASSERT_TRUE(t1->GetComputedStyle()); |
| 119 EXPECT_EQ(MakeRGB(0, 0, 255), |
| 120 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 121 |
| 122 GetStyleEngine().RemoveInjectedAuthorSheet(green_id); |
| 123 EXPECT_EQ(1u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 124 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 125 EXPECT_EQ(3u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 126 ASSERT_TRUE(t1->GetComputedStyle()); |
| 127 EXPECT_EQ(MakeRGB(0, 0, 255), |
| 128 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 129 |
| 130 GetStyleEngine().RemoveInjectedAuthorSheet(blue_id); |
| 131 EXPECT_EQ(0u, GetStyleEngine().InjectedAuthorStyleSheets().size()); |
| 132 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 133 EXPECT_EQ(4u, GetStyleEngine().StyleForElementCount() - initial_count); |
| 134 ASSERT_TRUE(t1->GetComputedStyle()); |
| 135 EXPECT_EQ(MakeRGB(255, 0, 0), |
| 136 t1->GetComputedStyle()->VisitedDependentColor(CSSPropertyColor)); |
| 104 } | 137 } |
| 105 | 138 |
| 106 TEST_F(StyleEngineTest, TextToSheetCache) { | 139 TEST_F(StyleEngineTest, TextToSheetCache) { |
| 107 HTMLStyleElement* element = HTMLStyleElement::Create(GetDocument(), false); | 140 HTMLStyleElement* element = HTMLStyleElement::Create(GetDocument(), false); |
| 108 | 141 |
| 109 String sheet_text("div {}"); | 142 String sheet_text("div {}"); |
| 110 TextPosition min_pos = TextPosition::MinimumPosition(); | 143 TextPosition min_pos = TextPosition::MinimumPosition(); |
| 111 StyleEngineContext context; | 144 StyleEngineContext context; |
| 112 | 145 |
| 113 CSSStyleSheet* sheet1 = | 146 CSSStyleSheet* sheet1 = |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 ASSERT_TRUE(container); | 601 ASSERT_TRUE(container); |
| 569 container->setInnerHTML("<meta http-equiv='default-style' content=''>"); | 602 container->setInnerHTML("<meta http-equiv='default-style' content=''>"); |
| 570 EXPECT_FALSE(GetStyleEngine().NeedsActiveStyleUpdate()); | 603 EXPECT_FALSE(GetStyleEngine().NeedsActiveStyleUpdate()); |
| 571 | 604 |
| 572 container->setInnerHTML( | 605 container->setInnerHTML( |
| 573 "<meta http-equiv='default-style' content='preferred'>"); | 606 "<meta http-equiv='default-style' content='preferred'>"); |
| 574 EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); | 607 EXPECT_TRUE(GetStyleEngine().NeedsActiveStyleUpdate()); |
| 575 } | 608 } |
| 576 | 609 |
| 577 } // namespace blink | 610 } // namespace blink |
| OLD | NEW |