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/StyleSheetList.h" |
8 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
9 #include "core/dom/NodeComputedStyle.h" | 10 #include "core/dom/NodeComputedStyle.h" |
10 #include "core/dom/shadow/ShadowRootInit.h" | 11 #include "core/dom/shadow/ShadowRootInit.h" |
| 12 #include "core/frame/FrameHost.h" |
11 #include "core/frame/FrameView.h" | 13 #include "core/frame/FrameView.h" |
| 14 #include "core/frame/PageScaleConstraintsSet.h" |
| 15 #include "core/frame/Settings.h" |
12 #include "core/html/HTMLElement.h" | 16 #include "core/html/HTMLElement.h" |
13 #include "core/html/HTMLStyleElement.h" | 17 #include "core/html/HTMLStyleElement.h" |
| 18 #include "core/loader/EmptyClients.h" |
14 #include "core/testing/DummyPageHolder.h" | 19 #include "core/testing/DummyPageHolder.h" |
15 #include "platform/heap/Heap.h" | 20 #include "platform/heap/Heap.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
17 #include <memory> | 22 #include <memory> |
18 | 23 |
19 namespace blink { | 24 namespace blink { |
20 | 25 |
21 class StyleEngineTest : public ::testing::Test { | 26 class StyleEngineTest : public ::testing::Test { |
22 protected: | 27 protected: |
23 void SetUp() override; | 28 void SetUp() override; |
24 | 29 |
25 Document& document() { return m_dummyPageHolder->document(); } | 30 Document& document() { return m_dummyPageHolder->document(); } |
26 StyleEngine& styleEngine() { return document().styleEngine(); } | 31 StyleEngine& styleEngine() { return document().styleEngine(); } |
27 | 32 |
28 bool isDocumentStyleSheetCollectionClean() { | 33 bool isDocumentStyleSheetCollectionClean() { |
29 return !styleEngine().shouldUpdateDocumentStyleSheetCollection( | 34 return !styleEngine().shouldUpdateDocumentStyleSheetCollection( |
30 AnalyzedStyleUpdate); | 35 AnalyzedStyleUpdate); |
31 } | 36 } |
32 | 37 |
33 enum RuleSetInvalidation { | 38 enum RuleSetInvalidation { |
34 RuleSetInvalidationsScheduled, | 39 RuleSetInvalidationsScheduled, |
35 RuleSetInvalidationFullRecalc | 40 RuleSetInvalidationFullRecalc |
36 }; | 41 }; |
37 RuleSetInvalidation scheduleInvalidationsForRules(TreeScope&, | 42 RuleSetInvalidation scheduleInvalidationsForRules(TreeScope&, |
38 const String& cssText); | 43 const String& cssText); |
39 | 44 |
40 private: | |
41 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 45 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
42 }; | 46 }; |
43 | 47 |
44 void StyleEngineTest::SetUp() { | 48 void StyleEngineTest::SetUp() { |
45 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 49 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
46 } | 50 } |
47 | 51 |
48 StyleEngineTest::RuleSetInvalidation | 52 StyleEngineTest::RuleSetInvalidation |
49 StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope, | 53 StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope, |
50 const String& cssText) { | 54 const String& cssText) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 *shadowRoot, ".a ::content span { background: green}"), | 302 *shadowRoot, ".a ::content span { background: green}"), |
299 RuleSetInvalidationFullRecalc); | 303 RuleSetInvalidationFullRecalc); |
300 EXPECT_EQ(scheduleInvalidationsForRules( | 304 EXPECT_EQ(scheduleInvalidationsForRules( |
301 *shadowRoot, ".a /deep/ span { background: green}"), | 305 *shadowRoot, ".a /deep/ span { background: green}"), |
302 RuleSetInvalidationFullRecalc); | 306 RuleSetInvalidationFullRecalc); |
303 EXPECT_EQ(scheduleInvalidationsForRules( | 307 EXPECT_EQ(scheduleInvalidationsForRules( |
304 *shadowRoot, ".a::shadow span { background: green}"), | 308 *shadowRoot, ".a::shadow span { background: green}"), |
305 RuleSetInvalidationFullRecalc); | 309 RuleSetInvalidationFullRecalc); |
306 } | 310 } |
307 | 311 |
| 312 class ViewportChromeClient : public EmptyChromeClient { |
| 313 public: |
| 314 void dispatchViewportPropertiesDidChange( |
| 315 const ViewportDescription& description) const override { |
| 316 if (!m_view) |
| 317 return; |
| 318 PageScaleConstraintsSet& constraints = |
| 319 m_view->frame().host()->pageScaleConstraintsSet(); |
| 320 constraints.didChangeInitialContainingBlockSize(IntSize(800, 600)); |
| 321 constraints.updatePageDefinedConstraints(description, Length(800, Fixed)); |
| 322 constraints.computeFinalConstraints(); |
| 323 m_view->setLayoutSize(flooredIntSize(constraints.layoutSize())); |
| 324 } |
| 325 void setFrameView(FrameView* frameView) { m_view = frameView; } |
| 326 |
| 327 private: |
| 328 UntracedMember<FrameView> m_view; |
| 329 }; |
| 330 |
| 331 class StyleEngineViewportTest : public StyleEngineTest { |
| 332 protected: |
| 333 void SetUp() override; |
| 334 }; |
| 335 |
| 336 void StyleEngineViewportTest::SetUp() { |
| 337 Page::PageClients clients; |
| 338 fillWithEmptyClients(clients); |
| 339 ViewportChromeClient* client = new ViewportChromeClient; |
| 340 clients.chromeClient = client; |
| 341 m_dummyPageHolder = DummyPageHolder::create( |
| 342 IntSize(800, 600), &clients, nullptr, [](Settings& settings) { |
| 343 settings.setViewportEnabled(true); |
| 344 settings.setViewportMetaEnabled(true); |
| 345 settings.setMainFrameResizesAreOrientationChanges(true); |
| 346 }); |
| 347 m_dummyPageHolder->frameView().setLayoutSizeFixedToFrameSize(false); |
| 348 client->setFrameView(&m_dummyPageHolder->frameView()); |
| 349 } |
| 350 |
| 351 TEST_F(StyleEngineViewportTest, AtViewportUpdatesViewportForAtMedia) { |
| 352 document().body()->setInnerHTML( |
| 353 "<style>" |
| 354 " @viewport {" |
| 355 " width: 200px" |
| 356 " }" |
| 357 " @media (max-width: 200px) {" |
| 358 " div { color: green }" |
| 359 " }" |
| 360 "</style>", |
| 361 ASSERT_NO_EXCEPTION); |
| 362 |
| 363 document().styleEngine().ensureResolver(); // Update active stylesheets. |
| 364 ASSERT_EQ(1u, document().styleSheets().length()); |
| 365 |
| 366 StyleSheet* sheet = document().styleSheets().item(0); |
| 367 ASSERT_TRUE(sheet); |
| 368 |
| 369 CSSStyleSheet& cssSheet = toCSSStyleSheet(*sheet); |
| 370 ASSERT_TRUE(cssSheet.contents()); |
| 371 |
| 372 cssSheet.contents()->ruleSet().compactRulesIfNeeded(); |
| 373 EXPECT_TRUE(cssSheet.contents()->ruleSet().tagRules("div")); |
| 374 } |
| 375 |
308 } // namespace blink | 376 } // namespace blink |
OLD | NEW |