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

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: Fixing rebase and nits 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,
abarth-chromium 2013/04/18 05:33:04 TestResizeYieldsCorrectScrollAndScale -> testResiz
jdduke (slow) 2013/04/18 16:20:07 Done.
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(0, 200);
708 const WebSize viewportSize(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(0, 200);
721 const WebSize viewportSize(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(200, 400);
734 const WebSize viewportSize(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 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 EXPECT_FALSE(client.wasProgrammaticScroll()); 2715 EXPECT_FALSE(client.wasProgrammaticScroll());
2602 EXPECT_TRUE(client.wasUserScroll()); 2716 EXPECT_TRUE(client.wasUserScroll());
2603 client.reset(); 2717 client.reset();
2604 2718
2605 m_webView->close(); 2719 m_webView->close();
2606 m_webView = 0; 2720 m_webView = 0;
2607 } 2721 }
2608 2722
2609 2723
2610 } // namespace 2724 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698