| Index: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| index a8a958d6d005bb7e696cfcfbd98ec3aa5e4b7786..5df254c8e4fd91310f39ee1e5f4c7f4c45c73ed8 100644
|
| --- a/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/StyleEngineTest.cpp
|
| @@ -5,12 +5,17 @@
|
| #include "core/dom/StyleEngine.h"
|
|
|
| #include "core/css/StyleSheetContents.h"
|
| +#include "core/css/StyleSheetList.h"
|
| #include "core/dom/Document.h"
|
| #include "core/dom/NodeComputedStyle.h"
|
| #include "core/dom/shadow/ShadowRootInit.h"
|
| +#include "core/frame/FrameHost.h"
|
| #include "core/frame/FrameView.h"
|
| +#include "core/frame/PageScaleConstraintsSet.h"
|
| +#include "core/frame/Settings.h"
|
| #include "core/html/HTMLElement.h"
|
| #include "core/html/HTMLStyleElement.h"
|
| +#include "core/loader/EmptyClients.h"
|
| #include "core/testing/DummyPageHolder.h"
|
| #include "platform/heap/Heap.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -37,7 +42,6 @@ class StyleEngineTest : public ::testing::Test {
|
| RuleSetInvalidation scheduleInvalidationsForRules(TreeScope&,
|
| const String& cssText);
|
|
|
| - private:
|
| std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
|
| };
|
|
|
| @@ -305,4 +309,68 @@ TEST_F(StyleEngineTest, RuleSetInvalidationV0BoundaryCrossing) {
|
| RuleSetInvalidationFullRecalc);
|
| }
|
|
|
| +class ViewportChromeClient : public EmptyChromeClient {
|
| + public:
|
| + void dispatchViewportPropertiesDidChange(
|
| + const ViewportDescription& description) const override {
|
| + if (!m_view)
|
| + return;
|
| + PageScaleConstraintsSet& constraints =
|
| + m_view->frame().host()->pageScaleConstraintsSet();
|
| + constraints.didChangeInitialContainingBlockSize(IntSize(800, 600));
|
| + constraints.updatePageDefinedConstraints(description, Length(800, Fixed));
|
| + constraints.computeFinalConstraints();
|
| + m_view->setLayoutSize(flooredIntSize(constraints.layoutSize()));
|
| + }
|
| + void setFrameView(FrameView* frameView) { m_view = frameView; }
|
| +
|
| + private:
|
| + UntracedMember<FrameView> m_view;
|
| +};
|
| +
|
| +class StyleEngineViewportTest : public StyleEngineTest {
|
| + protected:
|
| + void SetUp() override;
|
| +};
|
| +
|
| +void StyleEngineViewportTest::SetUp() {
|
| + Page::PageClients clients;
|
| + fillWithEmptyClients(clients);
|
| + ViewportChromeClient* client = new ViewportChromeClient;
|
| + clients.chromeClient = client;
|
| + m_dummyPageHolder = DummyPageHolder::create(
|
| + IntSize(800, 600), &clients, nullptr, [](Settings& settings) {
|
| + settings.setViewportEnabled(true);
|
| + settings.setViewportMetaEnabled(true);
|
| + settings.setMainFrameResizesAreOrientationChanges(true);
|
| + });
|
| + m_dummyPageHolder->frameView().setLayoutSizeFixedToFrameSize(false);
|
| + client->setFrameView(&m_dummyPageHolder->frameView());
|
| +}
|
| +
|
| +TEST_F(StyleEngineViewportTest, AtViewportUpdatesViewportForAtMedia) {
|
| + document().body()->setInnerHTML(
|
| + "<style>"
|
| + " @viewport {"
|
| + " width: 200px"
|
| + " }"
|
| + " @media (max-width: 200px) {"
|
| + " div { color: green }"
|
| + " }"
|
| + "</style>",
|
| + ASSERT_NO_EXCEPTION);
|
| +
|
| + document().styleEngine().ensureResolver(); // Update active stylesheets.
|
| + ASSERT_EQ(1u, document().styleSheets().length());
|
| +
|
| + StyleSheet* sheet = document().styleSheets().item(0);
|
| + ASSERT_TRUE(sheet);
|
| +
|
| + CSSStyleSheet& cssSheet = toCSSStyleSheet(*sheet);
|
| + ASSERT_TRUE(cssSheet.contents());
|
| +
|
| + cssSheet.contents()->ruleSet().compactRulesIfNeeded();
|
| + EXPECT_TRUE(cssSheet.contents()->ruleSet().tagRules("div"));
|
| +}
|
| +
|
| } // namespace blink
|
|
|