Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Unified Diff: third_party/WebKit/Source/core/dom/StyleEngineTest.cpp

Issue 2405143003: Separate @viewport from other RuleSet construction. (Closed)
Patch Set: Missing resolve() Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.cpp ('k') | third_party/WebKit/Source/core/frame/FrameView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698