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

Side by Side Diff: Source/WebKit/chromium/tests/WebFrameTest.cpp

Issue 13704012: Improve mobile device rotation behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: git cl upload with --similarity=70 Created 7 years, 8 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "WebFrame.h" 33 #include "WebFrame.h"
34 34
35 #include "DocumentMarkerController.h" 35 #include "DocumentMarkerController.h"
36 #include "EventHandler.h"
36 #include "FloatRect.h" 37 #include "FloatRect.h"
37 #include "Frame.h" 38 #include "Frame.h"
38 #include "FrameSelection.h" 39 #include "FrameSelection.h"
39 #include "FrameTestHelpers.h" 40 #include "FrameTestHelpers.h"
40 #include "FrameView.h" 41 #include "FrameView.h"
42 #include "HitTestResult.h"
41 #include "PlatformContextSkia.h" 43 #include "PlatformContextSkia.h"
42 #include "Range.h" 44 #include "Range.h"
43 #include "RenderView.h" 45 #include "RenderView.h"
44 #include "ResourceError.h" 46 #include "ResourceError.h"
45 #include "ScrollbarTheme.h" 47 #include "ScrollbarTheme.h"
46 #include "Settings.h" 48 #include "Settings.h"
47 #include "SkBitmap.h" 49 #include "SkBitmap.h"
48 #include "SkCanvas.h" 50 #include "SkCanvas.h"
49 #include "URLTestHelpers.h" 51 #include "URLTestHelpers.h"
50 #include "WebDataSource.h" 52 #include "WebDataSource.h"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 749
748 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f); 750 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f);
749 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f); 751 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f);
750 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f); 752 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f);
751 753
752 m_webView->close(); 754 m_webView->close();
753 m_webView = 0; 755 m_webView = 0;
754 } 756 }
755 } 757 }
756 758
759 class WebFrameResizeTest : public WebFrameTest {
760 protected:
761
762 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs oluteOffset, const WebCore::LayoutRect& rect)
763 {
764 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location();
765 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
766 return relativeOffset;
767 }
768
769 void testResizeYieldsCorrectScrollAndScale(const char* url,
770 const float initialPageScaleFacto r,
771 const WebSize scrollOffset,
772 const WebSize viewportSize,
773 const bool shouldScaleRelativeToV iewportWidth) {
774 registerMockedHttpURLLoad(url);
775
776 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp ortSize.height;
777
778 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true );
779 m_webView->settings()->setViewportEnabled(true);
780 m_webView->enableFixedLayoutMode(true);
781 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
782
783 // Origin scrollOffsets preserved under resize.
784 {
785 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
786 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
787 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
788 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal eRelativeToViewportWidth ? 1 / aspectRatio : 1);
789 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
790 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset());
791 }
792
793 // Resizing just the height should not affect pageScaleFactor.
794 {
795 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
796 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
797 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 10));
798 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * 1.25f));
799 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
800 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * .8f));
801 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
802 }
803
804 // Generic resize preserves scrollOffset relative to anchor node located
805 // the top center of the screen.
806 {
807 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
808 float pageScaleFactor = webViewImpl->pageScaleFactor();
809 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
810 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati veToViewportWidth ? aspectRatio : 1);
811 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
812 webViewImpl->mainFrame()->setScrollOffset(scrollOffset);
813
814 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We bCore::IntPoint(viewportSize.width / 2, 0);
815 RefPtr<WebCore::Node> anchorNode = webViewImpl->mainFrameImpl()->fra me()->eventHandler()->hitTestResultAtPoint(anchorPoint).innerNode();
816 ASSERT(anchorNode);
817
818 pageScaleFactor = webViewImpl->pageScaleFactor();
819 const WebCore::FloatSize preResizeRelativeOffset
820 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox());
821 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
822 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->ma inFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0);
823 const WebCore::FloatSize postResizeRelativeOffset
824 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox( ));
825 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse t.width(), 0.15f);
826 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi ewportWidth ? 1 / aspectRatio : 1);
827 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
828 }
829 }
830 };
831
832 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice Width)
833 {
834 // With width=device-width, pageScaleFactor is preserved across resizes as
835 // long as the content adjusts according to the device-width.
836 const char* url = "resize_scroll_mobile.html";
837 const float initialPageScaleFactor = 1;
838 const WebSize scrollOffset(0, 200);
839 const WebSize viewportSize(120, 160);
840 const bool shouldScaleRelativeToViewportWidth = true;
841
842 testResizeYieldsCorrectScrollAndScale(
843 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
844 }
845
846 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedWidth)
847 {
848 // With a fixed width, pageScaleFactor scales by the relative change in view port width.
849 const char* url = "resize_scroll_fixed_width.html";
850 const float initialPageScaleFactor = 2;
851 const WebSize scrollOffset(0, 200);
852 const WebSize viewportSize(240, 320);
853 const bool shouldScaleRelativeToViewportWidth = true;
854
855 testResizeYieldsCorrectScrollAndScale(
856 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
857 }
858
859 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedLayout)
860 {
861 // With a fixed layout, pageScaleFactor scales by the relative change in vie wport width.
862 const char* url = "resize_scroll_fixed_layout.html";
863 const float initialPageScaleFactor = 2;
864 const WebSize scrollOffset(200, 400);
865 const WebSize viewportSize(320, 240);
866 const bool shouldScaleRelativeToViewportWidth = true;
867
868 testResizeYieldsCorrectScrollAndScale(
869 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
870 }
871
757 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) 872 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
758 { 873 {
759 registerMockedHttpURLLoad("fixed_layout.html"); 874 registerMockedHttpURLLoad("fixed_layout.html");
760 875
761 FixedLayoutTestWebViewClient client; 876 FixedLayoutTestWebViewClient client;
762 client.m_screenInfo.deviceScaleFactor = 1; 877 client.m_screenInfo.deviceScaleFactor = 1;
763 int viewportWidth = 50; 878 int viewportWidth = 50;
764 int viewportHeight = 50; 879 int viewportHeight = 50;
765 880
766 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 881 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client);
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 EXPECT_FALSE(client.wasProgrammaticScroll()); 2898 EXPECT_FALSE(client.wasProgrammaticScroll());
2784 EXPECT_TRUE(client.wasUserScroll()); 2899 EXPECT_TRUE(client.wasUserScroll());
2785 client.reset(); 2900 client.reset();
2786 2901
2787 m_webView->close(); 2902 m_webView->close();
2788 m_webView = 0; 2903 m_webView = 0;
2789 } 2904 }
2790 2905
2791 2906
2792 } // namespace 2907 } // namespace
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebViewImpl.cpp ('k') | Source/WebKit/chromium/tests/data/resize_scroll_fixed_layout.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698