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

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: Refactoring. 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 "ScrollbarTheme.h" 45 #include "ScrollbarTheme.h"
45 #include "Settings.h" 46 #include "Settings.h"
46 #include "SkBitmap.h" 47 #include "SkBitmap.h"
47 #include "SkCanvas.h" 48 #include "SkCanvas.h"
48 #include "URLTestHelpers.h" 49 #include "URLTestHelpers.h"
49 #include "WebDataSource.h" 50 #include "WebDataSource.h"
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 649
649 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f); 650 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web View->fixedLayoutSize().width, 1.0f);
650 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f); 651 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we bView->fixedLayoutSize().height, 1.0f);
651 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f); 652 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag eScaleFactor(), 0.01f);
652 653
653 m_webView->close(); 654 m_webView->close();
654 m_webView = 0; 655 m_webView = 0;
655 } 656 }
656 } 657 }
657 658
659 class WebFrameResizeTest : public WebFrameTest {
660 protected:
661
662 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs oluteOffset, const WebCore::LayoutRect& rect)
663 {
664 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location();
665 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
666 return relativeOffset;
667 }
668
669 void TestResizeYieldsCorrectScrollAndScale(const char* url,
670 const float initialPageScaleFacto r,
671 const WebSize scrollOffset,
672 const WebSize viewportSize,
673 const bool useFixedLayout,
aelias_OOO_until_Jul13 2013/04/15 18:25:39 Delete this
jdduke (slow) 2013/04/16 15:40:26 Done.
674 const bool shouldScaleRelativeToV iewportWidth) {
675 registerMockedHttpURLLoad(url);
676
677 const float aspectRatio = (float)viewportSize.width / viewportSize.heigh t;
aelias_OOO_until_Jul13 2013/04/15 18:25:39 Nit: static_cast<float>
jdduke (slow) 2013/04/16 15:40:26 Done.
678
679 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true );
680 m_webView->settings()->setViewportEnabled(true);
681 m_webView->enableFixedLayoutMode(useFixedLayout);
aelias_OOO_until_Jul13 2013/04/15 18:25:39 This setting is always true on the Android platfor
jdduke (slow) 2013/04/16 15:40:26 Done.
682 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
683
684 // Origin scrollOffsets preserved under resize.
685 {
686 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
687 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
688 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
689 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal eRelativeToViewportWidth ? 1 / aspectRatio : 1);
690 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
691 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset());
692 }
693
694 // Resizing just the height should not affect pageScaleFactor.
695 {
696 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
697 m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint());
698 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * 1.25f));
699 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
700 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * .8f));
701 EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor());
702 }
703
704 // Generic resize preserves scrollOffset relative to anchor node located
705 // the top center of the screen.
706 {
707 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
708 float pageScaleFactor = webViewImpl->pageScaleFactor();
709 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height) );
710 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati veToViewportWidth ? aspectRatio : 1);
711 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
712 webViewImpl->mainFrame()->setScrollOffset(scrollOffset);
713
714 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We bCore::IntPoint(viewportSize.width / 2, 0);
715 RefPtr<WebCore::Node> anchorNode = webViewImpl->mainFrameImpl()->fra me()->eventHandler()->hitTestResultAtPoint(anchorPoint).innerNode();
716 ASSERT(anchorNode);
717
718 pageScaleFactor = webViewImpl->pageScaleFactor();
719 const WebCore::FloatSize preResizeRelativeOffset
720 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox());
721 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width) );
722 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->ma inFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0);
723 const WebCore::FloatSize postResizeRelativeOffset
724 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox( ));
725 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse t.width(), 0.1f);
726 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi ewportWidth ? 1 / aspectRatio : 1);
727 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f);
728 }
729 }
730 };
731
732 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice Width)
733 {
734 // With width=device-width, pageScaleFactor is preserved across resizes as
735 // long as the content adjusts according to the device-width.
736 const char* url = "resize_scroll_mobile.html";
737 const float initialPageScaleFactor = 1;
738 const WebSize scrollOffset = WebSize(0, 200);
739 const WebSize viewportSize = WebSize(240, 320);
740 const bool useFixedLayout = false;
741 const bool shouldScaleRelativeToViewportWidth = false;
742
743 TestResizeYieldsCorrectScrollAndScale(
744 url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth);
745 }
746
747 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedWidth)
748 {
749 // With a fixed width, pageScaleFactor scales by the relative change in view port width.
750 const char* url = "resize_scroll_fixed_width.html";
751 const float initialPageScaleFactor = 2;
752 const WebSize scrollOffset = WebSize(200, 400);
753 const WebSize viewportSize = WebSize(320, 240);
754 const bool useFixedLayout = false;
755 const bool shouldScaleRelativeToViewportWidth = true;
756
757 TestResizeYieldsCorrectScrollAndScale(
758 url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth);
759 }
760
761 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedLayout)
762 {
763 // With a fixed layout, pageScaleFactor scales by the relative change in vie wport width.
764 const char* url = "resize_scroll_fixed_layout.html";
765 const float initialPageScaleFactor = 2;
766 const WebSize scrollOffset = WebSize(200, 400);
767 const WebSize viewportSize = WebSize(320, 240);
768 const bool useFixedLayout = true;
769 const bool shouldScaleRelativeToViewportWidth = true;
770
771 TestResizeYieldsCorrectScrollAndScale(
772 url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth);
773 }
774
658 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) 775 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
659 { 776 {
660 registerMockedHttpURLLoad("fixed_layout.html"); 777 registerMockedHttpURLLoad("fixed_layout.html");
661 778
662 FixedLayoutTestWebViewClient client; 779 FixedLayoutTestWebViewClient client;
663 client.m_screenInfo.deviceScaleFactor = 1; 780 client.m_screenInfo.deviceScaleFactor = 1;
664 int viewportWidth = 50; 781 int viewportWidth = 50;
665 int viewportHeight = 50; 782 int viewportHeight = 50;
666 783
667 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client); 784 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout .html", true, 0, &client);
(...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 EXPECT_FALSE(client.wasProgrammaticScroll()); 2775 EXPECT_FALSE(client.wasProgrammaticScroll());
2659 EXPECT_TRUE(client.wasUserScroll()); 2776 EXPECT_TRUE(client.wasUserScroll());
2660 client.reset(); 2777 client.reset();
2661 2778
2662 m_webView->close(); 2779 m_webView->close();
2663 m_webView = 0; 2780 m_webView = 0;
2664 } 2781 }
2665 2782
2666 2783
2667 } // namespace 2784 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698