TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) { registerMockedHttpURLLoad("long_scroll.html"); FrameTestHelpers::WebViewHelper webViewHelper; WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, 0, 0); webView->resize(WebSize(1000, 1000)); webView->updateAllLifecyclePhases(); WebViewImpl* webViewImpl = toWebViewImpl(webView); FrameLoader& loader = webViewImpl->mainFrameImpl()->frame()->loader(); loader.setLoadType(FrameLoadTypeBackForward); webViewImpl->setPageScaleFactor(3.0f); webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 500)); loader.documentLoader()->initialScrollState().wasScrolledByUser = false; loader.currentItem()->setPageScaleFactor(0); loader.currentItem()->setScrollPoint(WebPoint(0, 400)); // FrameLoader::restoreScrollPositionAndViewState flows differently if scale is zero. loader.restoreScrollPositionAndViewState(); // Expect that only the scroll position was restored. EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor()); EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height); }
TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale) { registerMockedHttpURLLoad("long_scroll.html"); FrameTestHelpers::WebViewHelper webViewHelper; WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, 0, 0); webView->resize(WebSize(1000, 1000)); webView->updateAllLifecyclePhases(); WebViewImpl* webViewImpl = toWebViewImpl(webView); FrameLoader& loader = webViewImpl->mainFrameImpl()->frame()->loader(); loader.setLoadType(FrameLoadTypeBackForward); webViewImpl->setPageScaleFactor(3.0f); webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 500)); loader.documentLoader()->initialScrollState().wasScrolledByUser = false; loader.currentItem()->setPageScaleFactor(2); loader.currentItem()->setScrollPoint(WebPoint(0, 200)); // Flip back the wasScrolledByUser flag which was set to true by setPageScaleFactor // because otherwise FrameLoader::restoreScrollPositionAndViewState does nothing. loader.documentLoader()->initialScrollState().wasScrolledByUser = false; loader.restoreScrollPositionAndViewState(); // Expect that both scroll and scale were restored. EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height); }
TEST_F(WebFrameTest, DivAutoZoomParamsTest) { registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html"); WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_for_auto_zoom_into_div_test.html", true)); int pageWidth = 640; int pageHeight = 480; int divPosX = 200; int divPosY = 200; int divWidth = 200; int divHeight = 150; WebRect doubleTapPoint(250, 250, 0, 0); webViewImpl->resize(WebSize(pageWidth, pageHeight)); float scale; WebPoint scroll; // Test for Doubletap scaling // Tests for zooming in and out without clamping. // Set device scale and scale limits so we dont get clamped. webViewImpl->setDeviceScaleFactor(4); webViewImpl->setPageScaleFactorLimits(0, 4 / webViewImpl->deviceScaleFactor()); // Test zooming into div. webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll); float scaledDivWidth = divWidth * scale; float scaledDivHeight = divHeight * scale; int hScroll = ((divPosX * scale) - ((pageWidth - scaledDivWidth) / 2)) / scale; int vScroll = ((divPosY * scale) - ((pageHeight - scaledDivHeight) / 2)) / scale; EXPECT_NEAR(pageWidth / divWidth, scale, 0.1); EXPECT_EQ(hScroll, scroll.x); EXPECT_EQ(vScroll, scroll.y); // Test zoom out to overview scale. webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor()); webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll); EXPECT_FLOAT_EQ(1, scale); EXPECT_EQ(WebPoint(0, 0), scroll); // Tests for clamped scaling. // Test clamp to device scale: webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor()); webViewImpl->setDeviceScaleFactor(2.5); webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll); EXPECT_FLOAT_EQ(2.5, scale); // Test clamp to minimum scale: webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor()); webViewImpl->setPageScaleFactorLimits(1.5 / webViewImpl->deviceScaleFactor(), 4 / webViewImpl->deviceScaleFactor()); webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll); EXPECT_FLOAT_EQ(1.5, scale); EXPECT_EQ(WebPoint(0, 0), scroll); // Test clamp to maximum scale: webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor()); webViewImpl->setDeviceScaleFactor(4); webViewImpl->setPageScaleFactorLimits(0, 3 / webViewImpl->deviceScaleFactor()); webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll); EXPECT_FLOAT_EQ(3, scale); // Test for Non-doubletap scaling webViewImpl->setPageScaleFactor(1, WebPoint(0, 0)); webViewImpl->setDeviceScaleFactor(4); webViewImpl->setPageScaleFactorLimits(0, 4 / webViewImpl->deviceScaleFactor()); // Test zooming into div. webViewImpl->computeScaleAndScrollForHitRect(WebRect(250, 250, 10, 10), WebViewImpl::FindInPage, scale, scroll); EXPECT_NEAR(pageWidth / divWidth, scale, 0.1); // Drop any pending fake mouse events from zooming before leaving the test. webViewImpl->page()->mainFrame()->eventHandler()->clear(); }