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

Unified Diff: Source/WebKit/chromium/tests/WebFrameTest.cpp

Issue 19281007: Allow zoom-in to a target rect when tapping multiple targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/web/WebViewImpl.h » ('j') | Source/web/WebViewImpl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebKit/chromium/tests/WebFrameTest.cpp
diff --git a/Source/WebKit/chromium/tests/WebFrameTest.cpp b/Source/WebKit/chromium/tests/WebFrameTest.cpp
index ac3158719c1ed8d1d615e058ac22feeb6a5ca04e..ba7cc31a6c38d0ab31f4e412e81e8f66af63af45 100644
--- a/Source/WebKit/chromium/tests/WebFrameTest.cpp
+++ b/Source/WebKit/chromium/tests/WebFrameTest.cpp
@@ -92,6 +92,8 @@ using WebCore::Range;
using WebKit::URLTestHelpers::toKURL;
using WebKit::FrameTestHelpers::runPendingTasks;
+static const int touchPointPadding = 32;
jochen (gone - plz use gerrit) 2013/07/30 06:41:11 nit you can just move this into the anonymous name
+
namespace {
#define EXPECT_EQ_RECT(a, b) \
@@ -1168,55 +1170,91 @@ TEST_F(WebFrameTest, DivAutoZoomParamsTest)
WebRect wideDiv(200, 100, 400, 150);
WebRect tallDiv(200, 300, 400, 800);
- WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, 0, 0);
- WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, 0, 0);
+ WebRect doubleTapPointWide(
+ wideDiv.x + 50, wideDiv.y + 50, touchPointPadding, touchPointPadding);
+ WebRect doubleTapPointTall(
+ tallDiv.x + 50, tallDiv.y + 50, touchPointPadding, touchPointPadding);
+ WebRect wideBlockBounds;
+ WebRect tallBlockBounds;
float scale;
WebPoint scroll;
- bool isAnchor;
+ bool doubleTapShouldZoomOut;
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
// Test double-tap zooming into wide div.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
+ wideBlockBounds =
+ webViewImpl->computeBlockBounds(doubleTapPointWide, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(
+ wideBlockBounds, touchPointPadding, scale, scroll,
+ doubleTapShouldZoomOut);
// The div should horizontally fill the screen (modulo margins), and
// vertically centered (modulo integer rounding).
EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
EXPECT_NEAR(wideDiv.x, scroll.x, 20);
EXPECT_EQ(0, scroll.y);
- EXPECT_FALSE(isAnchor);
+ EXPECT_FALSE(doubleTapShouldZoomOut);
setScaleAndScrollAndLayout(webViewImpl, scroll, scale);
// Test zoom out back to minimum scale.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
- EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
- EXPECT_TRUE(isAnchor);
-
+ wideBlockBounds =
+ webViewImpl->computeBlockBounds(doubleTapPointWide, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(
+ wideBlockBounds, touchPointPadding, scale, scroll,
+ doubleTapShouldZoomOut);
+ EXPECT_TRUE(doubleTapShouldZoomOut);
+
+ scale = webViewImpl->minimumPageScaleFactor();
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), scale);
// Test double-tap zooming into tall div.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointTall, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
+ tallBlockBounds =
+ webViewImpl->computeBlockBounds(doubleTapPointTall, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(
+ tallBlockBounds, touchPointPadding, scale, scroll,
+ doubleTapShouldZoomOut);
// The div should start at the top left of the viewport.
EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1);
EXPECT_NEAR(tallDiv.x, scroll.x, 20);
EXPECT_NEAR(tallDiv.y, scroll.y, 20);
- EXPECT_FALSE(isAnchor);
+ EXPECT_FALSE(doubleTapShouldZoomOut);
// Test for Non-doubletap scaling
// Test zooming into div.
- webViewImpl->computeScaleAndScrollForHitRect(WebRect(250, 250, 10, 10), WebViewImpl::FindInPage, scale, scroll, isAnchor);
+ webViewImpl->computeScaleAndScrollForBlockRect(
+ webViewImpl->computeBlockBounds(WebRect(250, 250, 10, 10), true),
+ 0, scale, scroll, doubleTapShouldZoomOut);
EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
}
-void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
+void simulatePageScale(WebViewImpl* webViewImpl, float& scale)
{
- webViewImpl->animateZoomAroundPoint(point, WebViewImpl::DoubleTap);
- EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
- WebCore::IntSize scrollDelta = webViewImpl->fakeDoubleTapTargetPositionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
- float scaleDelta = webViewImpl->fakeDoubleTapPageScaleFactorForTesting() / webViewImpl->pageScaleFactor();
+ WebCore::IntSize scrollDelta =
+ webViewImpl->fakePageScaleAnimationTargetPositionForTesting()
+ - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
+ float scaleDelta =
+ webViewImpl->fakePageScaleAnimationPageScaleForTesting()
+ / webViewImpl->pageScaleFactor();
webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta);
scale = webViewImpl->pageScaleFactor();
}
+void simulateMultiTargetZoom(
+ WebViewImpl* webViewImpl,
jochen (gone - plz use gerrit) 2013/07/30 06:41:11 put all parameters in one line (no character limit
+ const WebRect& rect,
+ float& scale)
+{
+ if (webViewImpl->zoomToMultipleTargetsRect(rect))
+ simulatePageScale(webViewImpl, scale);
+}
+
+void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
+{
+ webViewImpl->animateDoubleTapZoom(point);
+ EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
+ simulatePageScale(webViewImpl, scale);
+}
+
TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
{
registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
@@ -1234,7 +1272,7 @@ TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect topDiv(200, 100, 200, 150);
WebRect bottomDiv(200, 300, 200, 150);
@@ -1261,7 +1299,7 @@ TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
// If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale.
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
- webViewImpl->animateZoomAroundPoint(topPoint, WebViewImpl::DoubleTap);
+ webViewImpl->animateDoubleTapZoom(topPoint);
EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
simulateDoubleTap(webViewImpl, bottomPoint, scale);
EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
@@ -1281,7 +1319,7 @@ TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect div(200, 100, 200, 150);
WebPoint doubleTapPoint(div.x + 50, div.y + 50);
@@ -1343,7 +1381,7 @@ TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
webViewImpl->page()->settings()->setTextAutosizingFontScaleFactor(textAutosizingFontScaleFactor);
WebRect div(200, 100, 200, 150);
@@ -1407,6 +1445,46 @@ TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest)
EXPECT_FLOAT_EQ(legibleScale, scale);
}
+TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest)
+{
+ registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
+
+ const float deviceScaleFactor = 2.0f;
+ int viewportWidth = 640 / deviceScaleFactor;
+ int viewportHeight = 1280 / deviceScaleFactor;
+ float doubleTapZoomAlreadyLegibleRatio = 1.2f;
+ m_webView = FrameTestHelpers::createWebViewAndLoad(
+ m_baseURL + "get_multiple_divs_for_auto_zoom_test.html");
+ m_webView->enableFixedLayoutMode(true);
+ m_webView->resize(WebSize(viewportWidth, viewportHeight));
+ m_webView->setPageScaleFactorLimits(0.5f, 4);
+ m_webView->setDeviceScaleFactor(deviceScaleFactor);
+ m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0));
+ m_webView->layout();
+
+ WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
+
+ WebRect viewportRect(0, 0, viewportWidth, viewportHeight);
+ WebRect topDiv(200, 100, 200, 150);
+ WebRect bottomDiv(200, 300, 200, 150);
+ float scale;
+ setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0),
+ (webViewImpl->minimumPageScaleFactor())
+ * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
+
+ simulateMultiTargetZoom(webViewImpl, topDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ simulateMultiTargetZoom(webViewImpl, bottomDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ simulateMultiTargetZoom(webViewImpl, viewportRect, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ webViewImpl->setPageScaleFactor(
+ webViewImpl->minimumPageScaleFactor(), WebPoint(0, 0));
+ simulateMultiTargetZoom(webViewImpl, topDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+}
+
TEST_F(WebFrameTest, DivScrollIntoEditableTest)
{
registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html");
@@ -1425,7 +1503,7 @@ TEST_F(WebFrameTest, DivScrollIntoEditableTest)
m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true);
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect editBoxWithText(200, 200, 250, 20);
WebRect editBoxWithNoText(200, 250, 250, 20);
« no previous file with comments | « no previous file | Source/web/WebViewImpl.h » ('j') | Source/web/WebViewImpl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698