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

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: Logic cleanup 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 19 matching lines...) Expand all
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 "FloatRect.h" 36 #include "FloatRect.h"
37 #include "Frame.h" 37 #include "Frame.h"
38 #include "FrameTestHelpers.h" 38 #include "FrameTestHelpers.h"
39 #include "FrameView.h" 39 #include "FrameView.h"
40 #include "HitTestResult.h"
40 #include "PlatformContextSkia.h" 41 #include "PlatformContextSkia.h"
41 #include "Range.h" 42 #include "Range.h"
42 #include "RenderView.h" 43 #include "RenderView.h"
43 #include "ResourceError.h" 44 #include "ResourceError.h"
44 #include "Settings.h" 45 #include "Settings.h"
45 #include "SkBitmap.h" 46 #include "SkBitmap.h"
46 #include "SkCanvas.h" 47 #include "SkCanvas.h"
47 #include "URLTestHelpers.h" 48 #include "URLTestHelpers.h"
48 #include "WebDataSource.h" 49 #include "WebDataSource.h"
49 #include "WebDocument.h" 50 #include "WebDocument.h"
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f); 618 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f);
618 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f); 619 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f);
619 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f); 620 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f);
620 621
621 m_webView->close(); 622 m_webView->close();
622 m_webView = 0; 623 m_webView = 0;
623 } 624 }
624 } 625 }
625 #endif 626 #endif
626 627
628 class WebFrameResizeTest : public WebFrameTest {
629 protected:
630
631 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs oluteOffset, const WebCore::LayoutRect& rect)
632 {
633 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location();
634 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
635 return relativeOffset;
636 }
637
638 void TestResizeYieldsCorrectScrollAndScale(const char* url,
639 const float initialPageScaleFacto r,
640 const WebSize scrollOffset,
641 const WebSize viewportSize,
642 const bool shouldScaleRelativeToV iewportWidth) {
643 registerMockedHttpURLLoad(url);
644
645 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp ortSize.height;
646
647 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true );
648 m_webView->settings()->setViewportEnabled(true);
649 m_webView->enableFixedLayoutMode(true);
650 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
651
652 // Origin scrollOffsets preserved under resize.
653 {
654 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
655 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
656 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
657 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal eRelativeToViewportWidth ? 1 / aspectRatio : 1);
658 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
659 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset());
660 }
661
662 // Resizing just the height should not affect pageScaleFactor.
663 {
664 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
665 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
666 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 10));
667 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * 1.25f));
668 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
669 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * .8f));
670 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
671 }
672
673 // Generic resize preserves scrollOffset relative to anchor node located
674 // the top center of the screen.
675 {
676 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
677 float pageScaleFactor = webViewImpl->pageScaleFactor();
678 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
679 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati veToViewportWidth ? aspectRatio : 1);
680 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
681 webViewImpl->mainFrame()->setScrollOffset(scrollOffset);
682
683 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We bCore::IntPoint(viewportSize.width / 2, 0);
684 RefPtr<WebCore::Node> anchorNode = webViewImpl->mainFrameImpl()->fra me()->eventHandler()->hitTestResultAtPoint(anchorPoint).innerNode();
685 ASSERT(anchorNode);
686
687 pageScaleFactor = webViewImpl->pageScaleFactor();
688 const WebCore::FloatSize preResizeRelativeOffset
689 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox());
690 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
691 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->ma inFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0);
692 const WebCore::FloatSize postResizeRelativeOffset
693 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox( ));
694 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse t.width(), 0.15f);
695 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi ewportWidth ? 1 / aspectRatio : 1);
696 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
697 }
698 }
699 };
700
701 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice Width)
702 {
703 // With width=device-width, pageScaleFactor is preserved across resizes as
704 // long as the content adjusts according to the device-width.
705 const char* url = "resize_scroll_mobile.html";
706 const float initialPageScaleFactor = 1;
707 const WebSize scrollOffset = WebSize(0, 200);
aelias_OOO_until_Jul13 2013/04/16 22:24:52 nit: scrollOffset(0, 200). likewise below
jdduke (slow) 2013/04/16 23:40:45 Done.
708 const WebSize viewportSize = WebSize(120, 160);
709 const bool shouldScaleRelativeToViewportWidth = true;
710
711 TestResizeYieldsCorrectScrollAndScale(
712 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
713 }
714
715 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedWidth)
716 {
717 // With a fixed width, pageScaleFactor scales by the relative change in view port width.
718 const char* url = "resize_scroll_fixed_width.html";
719 const float initialPageScaleFactor = 2;
720 const WebSize scrollOffset = WebSize(0, 200);
721 const WebSize viewportSize = WebSize(240, 320);
722 const bool shouldScaleRelativeToViewportWidth = true;
723
724 TestResizeYieldsCorrectScrollAndScale(
725 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
726 }
727
728 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedLayout)
729 {
730 // With a fixed layout, pageScaleFactor scales by the relative change in vie wport width.
731 const char* url = "resize_scroll_fixed_layout.html";
732 const float initialPageScaleFactor = 2;
733 const WebSize scrollOffset = WebSize(200, 400);
734 const WebSize viewportSize = WebSize(320, 240);
735 const bool shouldScaleRelativeToViewportWidth = true;
736
737 TestResizeYieldsCorrectScrollAndScale(
738 url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRela tiveToViewportWidth);
739 }
740
627 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) 741 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
628 { 742 {
629 registerMockedHttpURLLoad("fixed_layout.html"); 743 registerMockedHttpURLLoad("fixed_layout.html");
630 744
631 FixedLayoutTestWebViewClient client; 745 FixedLayoutTestWebViewClient client;
632 client.m_screenInfo.deviceScaleFactor = 1; 746 client.m_screenInfo.deviceScaleFactor = 1;
633 int viewportWidth = 50; 747 int viewportWidth = 50;
634 int viewportHeight = 50; 748 int viewportHeight = 50;
635 749
636 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 750 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client);
(...skipping 21 matching lines...) Expand all
658 WebCore::FrameView* view = static_cast<WebViewImpl*>(m_webView)->mainFrameIm pl()->frameView(); 772 WebCore::FrameView* view = static_cast<WebViewImpl*>(m_webView)->mainFrameIm pl()->frameView();
659 WebCore::IntRect paintRect(0, 0, 200, 200); 773 WebCore::IntRect paintRect(0, 0, 200, 200);
660 view->paint(&context, paintRect); 774 view->paint(&context, paintRect);
661 775
662 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay Scrollbar() ? 0 : 15); 776 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay Scrollbar() ? 0 : 15);
663 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver layScrollbar() ? 0 : 15); 777 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver layScrollbar() ? 0 : 15);
664 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport HeightMinusScrollbar * 2); 778 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport HeightMinusScrollbar * 2);
665 EXPECT_EQ_RECT(clippedRect, platformContext.opaqueRegion().asRect()); 779 EXPECT_EQ_RECT(clippedRect, platformContext.opaqueRegion().asRect());
666 } 780 }
667 781
782 TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars)
783 {
784 registerMockedHttpURLLoad("fixed_layout.html");
785
786 FixedLayoutTestWebViewClient client;
787 client.m_screenInfo.deviceScaleFactor = 1;
788 int viewportWidth = 640;
789 int viewportHeight = 480;
790
791 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client);
792 m_webView->enableFixedLayoutMode(true);
793 m_webView->settings()->setViewportEnabled(true);
794 m_webView->resize(WebSize(viewportWidth, viewportHeight));
795 m_webView->layout();
796
797 WebCore::FrameView* view = static_cast<WebViewImpl*>(m_webView)->mainFrameIm pl()->frameView();
798 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width());
799 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height());
800
801 m_webView->setPageScaleFactor(10, WebPoint());
802
803 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize ().width() - view->visibleContentRect().width());
804 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize() .height() - view->visibleContentRect().height());
805 }
806
668 TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor) 807 TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor)
669 { 808 {
670 registerMockedHttpURLLoad("no_scale_for_you.html"); 809 registerMockedHttpURLLoad("no_scale_for_you.html");
671 810
672 FixedLayoutTestWebViewClient client; 811 FixedLayoutTestWebViewClient client;
673 client.m_screenInfo.deviceScaleFactor = 1; 812 client.m_screenInfo.deviceScaleFactor = 1;
674 int viewportWidth = 640; 813 int viewportWidth = 640;
675 int viewportHeight = 480; 814 int viewportHeight = 480;
676 815
677 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for _you.html", true, 0, &client); 816 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for _you.html", true, 0, &client);
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 EXPECT_FALSE(client.wasProgrammaticScroll()); 2740 EXPECT_FALSE(client.wasProgrammaticScroll());
2602 EXPECT_TRUE(client.wasUserScroll()); 2741 EXPECT_TRUE(client.wasUserScroll());
2603 client.reset(); 2742 client.reset();
2604 2743
2605 m_webView->close(); 2744 m_webView->close();
2606 m_webView = 0; 2745 m_webView = 0;
2607 } 2746 }
2608 2747
2609 2748
2610 } // namespace 2749 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698