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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2390923002: Fix blurry content after disabling dev tools emulation (Closed)
Patch Set: Add function for LayerTreeHostRemote 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 3944 matching lines...) Expand 10 before | Expand all | Expand 10 after
3955 WebViewImpl* webViewImpl = 3955 WebViewImpl* webViewImpl =
3956 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); 3956 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html");
3957 webViewImpl->resize(WebSize(100, 150)); 3957 webViewImpl->resize(WebSize(100, 150));
3958 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); 3958 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150));
3959 VisualViewport* visualViewport = 3959 VisualViewport* visualViewport =
3960 &webViewImpl->page()->frameHost().visualViewport(); 3960 &webViewImpl->page()->frameHost().visualViewport();
3961 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); 3961 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator();
3962 3962
3963 TransformationMatrix expectedMatrix; 3963 TransformationMatrix expectedMatrix;
3964 expectedMatrix.makeIdentity(); 3964 expectedMatrix.makeIdentity();
3965 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 3965 EXPECT_EQ(expectedMatrix,
3966 webViewImpl->getDeviceEmulationTransformForTesting());
3966 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); 3967 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting());
3967 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); 3968 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
3968 3969
3969 // Override applies transform, sets visibleContentRect, and disables 3970 // Override applies transform, sets visibleContentRect, and disables
3970 // visual viewport clipping. 3971 // visual viewport clipping.
3971 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); 3972 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f);
3972 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55); 3973 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55);
3973 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 3974 EXPECT_EQ(expectedMatrix,
3975 webViewImpl->getDeviceEmulationTransformForTesting());
3974 EXPECT_EQ(IntRect(50, 55, 50, 75), 3976 EXPECT_EQ(IntRect(50, 55, 50, 75),
3975 *devToolsEmulator->visibleContentRectForPainting()); 3977 *devToolsEmulator->visibleContentRectForPainting());
3976 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); 3978 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
3977 3979
3978 // Setting new override discards previous one. 3980 // Setting new override discards previous one.
3979 devToolsEmulator->forceViewport(WebFloatPoint(5.4f, 10.5f), 1.5f); 3981 devToolsEmulator->forceViewport(WebFloatPoint(5.4f, 10.5f), 1.5f);
3980 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f); 3982 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f);
3981 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 3983 EXPECT_EQ(expectedMatrix,
3984 webViewImpl->getDeviceEmulationTransformForTesting());
3982 EXPECT_EQ(IntRect(5, 10, 68, 101), 3985 EXPECT_EQ(IntRect(5, 10, 68, 101),
3983 *devToolsEmulator->visibleContentRectForPainting()); 3986 *devToolsEmulator->visibleContentRectForPainting());
3984 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); 3987 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
3985 3988
3986 // Clearing override restores original transform, visibleContentRect and 3989 // Clearing override restores original transform, visibleContentRect and
3987 // visual viewport clipping. 3990 // visual viewport clipping.
3988 devToolsEmulator->resetViewport(); 3991 devToolsEmulator->resetViewport();
3989 expectedMatrix.makeIdentity(); 3992 expectedMatrix.makeIdentity();
3990 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 3993 EXPECT_EQ(expectedMatrix,
3994 webViewImpl->getDeviceEmulationTransformForTesting());
3991 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting()); 3995 EXPECT_FALSE(devToolsEmulator->visibleContentRectForPainting());
3992 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); 3996 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
3993 } 3997 }
3994 3998
3995 TEST_F(WebViewTest, ViewportOverrideIntegratesDeviceMetricsOffsetAndScale) { 3999 TEST_F(WebViewTest, ViewportOverrideIntegratesDeviceMetricsOffsetAndScale) {
3996 URLTestHelpers::registerMockedURLFromBaseURL( 4000 URLTestHelpers::registerMockedURLFromBaseURL(
3997 WebString::fromUTF8(m_baseURL.c_str()), 4001 WebString::fromUTF8(m_baseURL.c_str()),
3998 WebString::fromUTF8("200-by-300.html")); 4002 WebString::fromUTF8("200-by-300.html"));
3999 WebViewImpl* webViewImpl = 4003 WebViewImpl* webViewImpl =
4000 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); 4004 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html");
4001 webViewImpl->resize(WebSize(100, 150)); 4005 webViewImpl->resize(WebSize(100, 150));
4002 4006
4003 TransformationMatrix expectedMatrix; 4007 TransformationMatrix expectedMatrix;
4004 expectedMatrix.makeIdentity(); 4008 expectedMatrix.makeIdentity();
4005 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4009 EXPECT_EQ(expectedMatrix,
4010 webViewImpl->getDeviceEmulationTransformForTesting());
4006 4011
4007 WebDeviceEmulationParams emulationParams; 4012 WebDeviceEmulationParams emulationParams;
4008 emulationParams.offset = WebFloatPoint(50, 50); 4013 emulationParams.offset = WebFloatPoint(50, 50);
4009 emulationParams.scale = 2.f; 4014 emulationParams.scale = 2.f;
4010 webViewImpl->enableDeviceEmulation(emulationParams); 4015 webViewImpl->enableDeviceEmulation(emulationParams);
4011 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f); 4016 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f);
4012 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4017 EXPECT_EQ(expectedMatrix,
4018 webViewImpl->getDeviceEmulationTransformForTesting());
4013 4019
4014 // Device metrics offset and scale are applied before viewport override. 4020 // Device metrics offset and scale are applied before viewport override.
4015 webViewImpl->devToolsEmulator()->forceViewport(WebFloatPoint(5, 10), 1.5f); 4021 webViewImpl->devToolsEmulator()->forceViewport(WebFloatPoint(5, 10), 1.5f);
4016 expectedMatrix.makeIdentity() 4022 expectedMatrix.makeIdentity()
4017 .scale(1.5f) 4023 .scale(1.5f)
4018 .translate(-5, -10) 4024 .translate(-5, -10)
4019 .translate(50, 50) 4025 .translate(50, 50)
4020 .scale(2.f); 4026 .scale(2.f);
4021 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4027 EXPECT_EQ(expectedMatrix,
4028 webViewImpl->getDeviceEmulationTransformForTesting());
4022 } 4029 }
4023 4030
4024 TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) { 4031 TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) {
4025 URLTestHelpers::registerMockedURLFromBaseURL( 4032 URLTestHelpers::registerMockedURLFromBaseURL(
4026 WebString::fromUTF8(m_baseURL.c_str()), 4033 WebString::fromUTF8(m_baseURL.c_str()),
4027 WebString::fromUTF8("200-by-300.html")); 4034 WebString::fromUTF8("200-by-300.html"));
4028 WebViewImpl* webViewImpl = 4035 WebViewImpl* webViewImpl =
4029 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); 4036 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html");
4030 webViewImpl->resize(WebSize(100, 150)); 4037 webViewImpl->resize(WebSize(100, 150));
4031 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150)); 4038 webViewImpl->layerTreeView()->setViewportSize(WebSize(100, 150));
4032 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); 4039 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
4033 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); 4040 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator();
4034 4041
4035 TransformationMatrix expectedMatrix; 4042 TransformationMatrix expectedMatrix;
4036 expectedMatrix.makeIdentity(); 4043 expectedMatrix.makeIdentity();
4037 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4044 EXPECT_EQ(expectedMatrix,
4045 webViewImpl->getDeviceEmulationTransformForTesting());
4038 4046
4039 // Initial transform takes current page scale and scroll position into 4047 // Initial transform takes current page scale and scroll position into
4040 // account. 4048 // account.
4041 webViewImpl->setPageScaleFactor(1.5f); 4049 webViewImpl->setPageScaleFactor(1.5f);
4042 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, 4050 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll,
4043 ScrollBehaviorInstant); 4051 ScrollBehaviorInstant);
4044 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); 4052 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f);
4045 expectedMatrix.makeIdentity() 4053 expectedMatrix.makeIdentity()
4046 .scale(2.f) 4054 .scale(2.f)
4047 .translate(-50, -55) 4055 .translate(-50, -55)
4048 .translate(100, 150) 4056 .translate(100, 150)
4049 .scale(1. / 1.5f); 4057 .scale(1. / 1.5f);
4050 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4058 EXPECT_EQ(expectedMatrix,
4059 webViewImpl->getDeviceEmulationTransformForTesting());
4051 // Page scroll and scale are irrelevant for visibleContentRect. 4060 // Page scroll and scale are irrelevant for visibleContentRect.
4052 EXPECT_EQ(IntRect(50, 55, 50, 75), 4061 EXPECT_EQ(IntRect(50, 55, 50, 75),
4053 *devToolsEmulator->visibleContentRectForPainting()); 4062 *devToolsEmulator->visibleContentRectForPainting());
4054 4063
4055 // Transform adapts to scroll changes. 4064 // Transform adapts to scroll changes.
4056 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, 4065 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll,
4057 ScrollBehaviorInstant); 4066 ScrollBehaviorInstant);
4058 expectedMatrix.makeIdentity() 4067 expectedMatrix.makeIdentity()
4059 .scale(2.f) 4068 .scale(2.f)
4060 .translate(-50, -55) 4069 .translate(-50, -55)
4061 .translate(50, 55) 4070 .translate(50, 55)
4062 .scale(1. / 1.5f); 4071 .scale(1. / 1.5f);
4063 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4072 EXPECT_EQ(expectedMatrix,
4073 webViewImpl->getDeviceEmulationTransformForTesting());
4064 // visibleContentRect doesn't change. 4074 // visibleContentRect doesn't change.
4065 EXPECT_EQ(IntRect(50, 55, 50, 75), 4075 EXPECT_EQ(IntRect(50, 55, 50, 75),
4066 *devToolsEmulator->visibleContentRectForPainting()); 4076 *devToolsEmulator->visibleContentRectForPainting());
4067 4077
4068 // Transform adapts to page scale changes. 4078 // Transform adapts to page scale changes.
4069 webViewImpl->setPageScaleFactor(2.f); 4079 webViewImpl->setPageScaleFactor(2.f);
4070 expectedMatrix.makeIdentity() 4080 expectedMatrix.makeIdentity()
4071 .scale(2.f) 4081 .scale(2.f)
4072 .translate(-50, -55) 4082 .translate(-50, -55)
4073 .translate(50, 55) 4083 .translate(50, 55)
4074 .scale(1. / 2.f); 4084 .scale(1. / 2.f);
4075 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); 4085 EXPECT_EQ(expectedMatrix,
4086 webViewImpl->getDeviceEmulationTransformForTesting());
4076 // visibleContentRect doesn't change. 4087 // visibleContentRect doesn't change.
4077 EXPECT_EQ(IntRect(50, 55, 50, 75), 4088 EXPECT_EQ(IntRect(50, 55, 50, 75),
4078 *devToolsEmulator->visibleContentRectForPainting()); 4089 *devToolsEmulator->visibleContentRectForPainting());
4079 } 4090 }
4080 4091
4081 } // namespace blink 4092 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/public/platform/WebLayerTreeView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698