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

Side by Side Diff: Source/web/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, 4 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
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | public/web/WebView.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 using WebCore::DocumentMarker; 89 using WebCore::DocumentMarker;
90 using WebCore::Element; 90 using WebCore::Element;
91 using WebCore::FloatRect; 91 using WebCore::FloatRect;
92 using WebCore::HitTestRequest; 92 using WebCore::HitTestRequest;
93 using WebCore::Range; 93 using WebCore::Range;
94 using WebKit::URLTestHelpers::toKURL; 94 using WebKit::URLTestHelpers::toKURL;
95 using WebKit::FrameTestHelpers::runPendingTasks; 95 using WebKit::FrameTestHelpers::runPendingTasks;
96 96
97 namespace { 97 namespace {
98 98
99 const int touchPointPadding = 32;
100
99 #define EXPECT_EQ_RECT(a, b) \ 101 #define EXPECT_EQ_RECT(a, b) \
100 EXPECT_EQ(a.x(), b.x()); \ 102 EXPECT_EQ(a.x(), b.x()); \
101 EXPECT_EQ(a.y(), b.y()); \ 103 EXPECT_EQ(a.y(), b.y()); \
102 EXPECT_EQ(a.width(), b.width()); \ 104 EXPECT_EQ(a.width(), b.width()); \
103 EXPECT_EQ(a.height(), b.height()); 105 EXPECT_EQ(a.height(), b.height());
104 106
105 class FakeWebFrameClient : public WebFrameClient { 107 class FakeWebFrameClient : public WebFrameClient {
106 // To make the destructor public. 108 // To make the destructor public.
107 }; 109 };
108 110
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_auto_zoom_into_div_test.html"); // 1165 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_auto_zoom_into_div_test.html"); //
1164 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1166 m_webView->setDeviceScaleFactor(deviceScaleFactor);
1165 m_webView->setPageScaleFactorLimits(0.01f, 4); 1167 m_webView->setPageScaleFactorLimits(0.01f, 4);
1166 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); 1168 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0));
1167 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1169 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1168 m_webView->enableFixedLayoutMode(true); 1170 m_webView->enableFixedLayoutMode(true);
1169 m_webView->layout(); 1171 m_webView->layout();
1170 1172
1171 WebRect wideDiv(200, 100, 400, 150); 1173 WebRect wideDiv(200, 100, 400, 150);
1172 WebRect tallDiv(200, 300, 400, 800); 1174 WebRect tallDiv(200, 300, 400, 800);
1173 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, 0, 0); 1175 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding , touchPointPadding);
1174 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, 0, 0); 1176 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding , touchPointPadding);
1177 WebRect wideBlockBounds;
1178 WebRect tallBlockBounds;
1175 float scale; 1179 float scale;
1176 WebPoint scroll; 1180 WebPoint scroll;
1177 bool isAnchor; 1181 bool doubleTapShouldZoomOut;
1178 1182
1179 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 1183 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1180 // Test double-tap zooming into wide div. 1184 // Test double-tap zooming into wide div.
1181 webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl ::DoubleTap, scale, scroll, isAnchor); 1185 wideBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointWide, false) ;
1186 webViewImpl->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPointPa dding, scale, scroll, doubleTapShouldZoomOut);
1182 // The div should horizontally fill the screen (modulo margins), and 1187 // The div should horizontally fill the screen (modulo margins), and
1183 // vertically centered (modulo integer rounding). 1188 // vertically centered (modulo integer rounding).
1184 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); 1189 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
1185 EXPECT_NEAR(wideDiv.x, scroll.x, 20); 1190 EXPECT_NEAR(wideDiv.x, scroll.x, 20);
1186 EXPECT_EQ(0, scroll.y); 1191 EXPECT_EQ(0, scroll.y);
1187 EXPECT_FALSE(isAnchor); 1192 EXPECT_FALSE(doubleTapShouldZoomOut);
1188 1193
1189 setScaleAndScrollAndLayout(webViewImpl, scroll, scale); 1194 setScaleAndScrollAndLayout(webViewImpl, scroll, scale);
1190 1195
1191 // Test zoom out back to minimum scale. 1196 // Test zoom out back to minimum scale.
1192 webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl ::DoubleTap, scale, scroll, isAnchor); 1197 wideBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointWide, false) ;
1193 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale); 1198 webViewImpl->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPointPa dding, scale, scroll, doubleTapShouldZoomOut);
1194 EXPECT_TRUE(isAnchor); 1199 EXPECT_TRUE(doubleTapShouldZoomOut);
1195 1200
1201 scale = webViewImpl->minimumPageScaleFactor();
1196 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), scale); 1202 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), scale);
1197 1203
1198 // Test double-tap zooming into tall div. 1204 // Test double-tap zooming into tall div.
1199 webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointTall, WebViewImpl ::DoubleTap, scale, scroll, isAnchor); 1205 tallBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointTall, false) ;
1206 webViewImpl->computeScaleAndScrollForBlockRect(tallBlockBounds, touchPointPa dding, scale, scroll, doubleTapShouldZoomOut);
1200 // The div should start at the top left of the viewport. 1207 // The div should start at the top left of the viewport.
1201 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1); 1208 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1);
1202 EXPECT_NEAR(tallDiv.x, scroll.x, 20); 1209 EXPECT_NEAR(tallDiv.x, scroll.x, 20);
1203 EXPECT_NEAR(tallDiv.y, scroll.y, 20); 1210 EXPECT_NEAR(tallDiv.y, scroll.y, 20);
1204 EXPECT_FALSE(isAnchor); 1211 EXPECT_FALSE(doubleTapShouldZoomOut);
1205 1212
1206 // Test for Non-doubletap scaling 1213 // Test for Non-doubletap scaling
1207 // Test zooming into div. 1214 // Test zooming into div.
1208 webViewImpl->computeScaleAndScrollForHitRect(WebRect(250, 250, 10, 10), WebV iewImpl::FindInPage, scale, scroll, isAnchor); 1215 webViewImpl->computeScaleAndScrollForBlockRect(webViewImpl->computeBlockBoun ds(WebRect(250, 250, 10, 10), true), 0, scale, scroll, doubleTapShouldZoomOut);
1209 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); 1216 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
1210 } 1217 }
1211 1218
1219 void simulatePageScale(WebViewImpl* webViewImpl, float& scale)
1220 {
1221 WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPosi tionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
1222 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / webViewImpl->pageScaleFactor();
1223 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta);
1224 scale = webViewImpl->pageScaleFactor();
1225 }
1226
1227 void simulateMultiTargetZoom(WebViewImpl* webViewImpl, const WebRect& rect, floa t& scale)
1228 {
1229 if (webViewImpl->zoomToMultipleTargetsRect(rect))
1230 simulatePageScale(webViewImpl, scale);
1231 }
1232
1212 void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale) 1233 void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
1213 { 1234 {
1214 webViewImpl->animateZoomAroundPoint(point, WebViewImpl::DoubleTap); 1235 webViewImpl->animateDoubleTapZoom(point);
1215 EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting()); 1236 EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
1216 WebCore::IntSize scrollDelta = webViewImpl->fakeDoubleTapTargetPositionForTe sting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition(); 1237 simulatePageScale(webViewImpl, scale);
1217 float scaleDelta = webViewImpl->fakeDoubleTapPageScaleFactorForTesting() / w ebViewImpl->pageScaleFactor();
1218 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta);
1219 scale = webViewImpl->pageScaleFactor();
1220 } 1238 }
1221 1239
1222 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest) 1240 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
1223 { 1241 {
1224 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); 1242 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
1225 1243
1226 const float deviceScaleFactor = 2.0f; 1244 const float deviceScaleFactor = 2.0f;
1227 int viewportWidth = 640 / deviceScaleFactor; 1245 int viewportWidth = 640 / deviceScaleFactor;
1228 int viewportHeight = 1280 / deviceScaleFactor; 1246 int viewportHeight = 1280 / deviceScaleFactor;
1229 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1247 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1230 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple _divs_for_auto_zoom_test.html"); 1248 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple _divs_for_auto_zoom_test.html");
1231 m_webView->enableFixedLayoutMode(true); 1249 m_webView->enableFixedLayoutMode(true);
1232 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1250 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1233 m_webView->setPageScaleFactorLimits(0.5f, 4); 1251 m_webView->setPageScaleFactorLimits(0.5f, 4);
1234 m_webView->setDeviceScaleFactor(deviceScaleFactor); 1252 m_webView->setDeviceScaleFactor(deviceScaleFactor);
1235 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); 1253 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0));
1236 m_webView->layout(); 1254 m_webView->layout();
1237 1255
1238 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 1256 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1239 webViewImpl->enableFakeDoubleTapAnimationForTesting(true); 1257 webViewImpl->enableFakePageScaleAnimationForTesting(true);
1240 1258
1241 WebRect topDiv(200, 100, 200, 150); 1259 WebRect topDiv(200, 100, 200, 150);
1242 WebRect bottomDiv(200, 300, 200, 150); 1260 WebRect bottomDiv(200, 300, 200, 150);
1243 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50); 1261 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50);
1244 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50); 1262 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50);
1245 float scale; 1263 float scale;
1246 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1264 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
1247 1265
1248 // Test double tap on two different divs 1266 // Test double tap on two different divs
1249 // After first zoom, we should go back to minimum page scale with a second d ouble tap. 1267 // After first zoom, we should go back to minimum page scale with a second d ouble tap.
1250 simulateDoubleTap(webViewImpl, topPoint, scale); 1268 simulateDoubleTap(webViewImpl, topPoint, scale);
1251 EXPECT_FLOAT_EQ(1, scale); 1269 EXPECT_FLOAT_EQ(1, scale);
1252 simulateDoubleTap(webViewImpl, bottomPoint, scale); 1270 simulateDoubleTap(webViewImpl, bottomPoint, scale);
1253 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale); 1271 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
1254 1272
1255 // If the user pinch zooms after double tap, a second double tap should zoom back to the div. 1273 // If the user pinch zooms after double tap, a second double tap should zoom back to the div.
1256 simulateDoubleTap(webViewImpl, topPoint, scale); 1274 simulateDoubleTap(webViewImpl, topPoint, scale);
1257 EXPECT_FLOAT_EQ(1, scale); 1275 EXPECT_FLOAT_EQ(1, scale);
1258 webViewImpl->applyScrollAndScale(WebSize(), 0.6f); 1276 webViewImpl->applyScrollAndScale(WebSize(), 0.6f);
1259 simulateDoubleTap(webViewImpl, bottomPoint, scale); 1277 simulateDoubleTap(webViewImpl, bottomPoint, scale);
1260 EXPECT_FLOAT_EQ(1, scale); 1278 EXPECT_FLOAT_EQ(1, scale);
1261 simulateDoubleTap(webViewImpl, bottomPoint, scale); 1279 simulateDoubleTap(webViewImpl, bottomPoint, scale);
1262 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale); 1280 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
1263 1281
1264 // If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale. 1282 // If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale.
1265 webViewImpl->applyScrollAndScale(WebSize(), 1.1f); 1283 webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
1266 webViewImpl->animateZoomAroundPoint(topPoint, WebViewImpl::DoubleTap); 1284 webViewImpl->animateDoubleTapZoom(topPoint);
1267 EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting()); 1285 EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
1268 simulateDoubleTap(webViewImpl, bottomPoint, scale); 1286 simulateDoubleTap(webViewImpl, bottomPoint, scale);
1269 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale); 1287 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
1270 } 1288 }
1271 1289
1272 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest) 1290 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest)
1273 { 1291 {
1274 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); 1292 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html");
1275 1293
1276 int viewportWidth = 320; 1294 int viewportWidth = 320;
1277 int viewportHeight = 480; 1295 int viewportHeight = 480;
1278 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1296 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1279 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html"); 1297 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html");
1280 m_webView->enableFixedLayoutMode(true); 1298 m_webView->enableFixedLayoutMode(true);
1281 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1299 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1282 m_webView->setDeviceScaleFactor(1.5f); 1300 m_webView->setDeviceScaleFactor(1.5f);
1283 m_webView->layout(); 1301 m_webView->layout();
1284 1302
1285 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 1303 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1286 webViewImpl->enableFakeDoubleTapAnimationForTesting(true); 1304 webViewImpl->enableFakePageScaleAnimationForTesting(true);
1287 1305
1288 WebRect div(200, 100, 200, 150); 1306 WebRect div(200, 100, 200, 150);
1289 WebPoint doubleTapPoint(div.x + 50, div.y + 50); 1307 WebPoint doubleTapPoint(div.x + 50, div.y + 50);
1290 float scale; 1308 float scale;
1291 1309
1292 // Test double tap scale bounds. 1310 // Test double tap scale bounds.
1293 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 1311 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1
1294 m_webView->setPageScaleFactorLimits(0.5f, 4); 1312 m_webView->setPageScaleFactorLimits(0.5f, 4);
1295 m_webView->layout(); 1313 m_webView->layout();
1296 float doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor () * doubleTapZoomAlreadyLegibleRatio; 1314 float doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor () * doubleTapZoomAlreadyLegibleRatio;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 int viewportWidth = 320; 1356 int viewportWidth = 320;
1339 int viewportHeight = 480; 1357 int viewportHeight = 480;
1340 float doubleTapZoomAlreadyLegibleRatio = 1.2f; 1358 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1341 float textAutosizingFontScaleFactor = 1.13f; 1359 float textAutosizingFontScaleFactor = 1.13f;
1342 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html"); 1360 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo unds_check_for_auto_zoom_test.html");
1343 m_webView->enableFixedLayoutMode(true); 1361 m_webView->enableFixedLayoutMode(true);
1344 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1362 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1345 m_webView->layout(); 1363 m_webView->layout();
1346 1364
1347 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 1365 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1348 webViewImpl->enableFakeDoubleTapAnimationForTesting(true); 1366 webViewImpl->enableFakePageScaleAnimationForTesting(true);
1349 webViewImpl->page()->settings()->setTextAutosizingFontScaleFactor(textAutosi zingFontScaleFactor); 1367 webViewImpl->page()->settings()->setTextAutosizingFontScaleFactor(textAutosi zingFontScaleFactor);
1350 1368
1351 WebRect div(200, 100, 200, 150); 1369 WebRect div(200, 100, 200, 150);
1352 WebPoint doubleTapPoint(div.x + 50, div.y + 50); 1370 WebPoint doubleTapPoint(div.x + 50, div.y + 50);
1353 float scale; 1371 float scale;
1354 1372
1355 // Test double tap scale bounds. 1373 // Test double tap scale bounds.
1356 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF ontScaleFactor 1374 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF ontScaleFactor
1357 float legibleScale = textAutosizingFontScaleFactor; 1375 float legibleScale = textAutosizingFontScaleFactor;
1358 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1376 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * d oubleTapZoomAlreadyLegibleRatio; 1420 doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * d oubleTapZoomAlreadyLegibleRatio;
1403 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); 1421 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
1404 simulateDoubleTap(webViewImpl, doubleTapPoint, scale); 1422 simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
1405 EXPECT_FLOAT_EQ(legibleScale, scale); 1423 EXPECT_FLOAT_EQ(legibleScale, scale);
1406 simulateDoubleTap(webViewImpl, doubleTapPoint, scale); 1424 simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
1407 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale); 1425 EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
1408 simulateDoubleTap(webViewImpl, doubleTapPoint, scale); 1426 simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
1409 EXPECT_FLOAT_EQ(legibleScale, scale); 1427 EXPECT_FLOAT_EQ(legibleScale, scale);
1410 } 1428 }
1411 1429
1430 TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest)
1431 {
1432 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
1433
1434 const float deviceScaleFactor = 2.0f;
1435 int viewportWidth = 640 / deviceScaleFactor;
1436 int viewportHeight = 1280 / deviceScaleFactor;
1437 float doubleTapZoomAlreadyLegibleRatio = 1.2f;
1438 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple _divs_for_auto_zoom_test.html");
1439 m_webView->enableFixedLayoutMode(true);
1440 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1441 m_webView->setPageScaleFactorLimits(0.5f, 4);
1442 m_webView->setDeviceScaleFactor(deviceScaleFactor);
1443 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0));
1444 m_webView->layout();
1445
1446 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1447 webViewImpl->enableFakePageScaleAnimationForTesting(true);
1448
1449 WebRect viewportRect(0, 0, viewportWidth, viewportHeight);
1450 WebRect topDiv(200, 100, 200, 150);
1451 WebRect bottomDiv(200, 300, 200, 150);
1452 float scale;
1453 setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimu mPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
1454
1455 simulateMultiTargetZoom(webViewImpl, topDiv, scale);
1456 EXPECT_FLOAT_EQ(1, scale);
1457 simulateMultiTargetZoom(webViewImpl, bottomDiv, scale);
1458 EXPECT_FLOAT_EQ(1, scale);
1459 simulateMultiTargetZoom(webViewImpl, viewportRect, scale);
1460 EXPECT_FLOAT_EQ(1, scale);
1461 webViewImpl->setPageScaleFactor(webViewImpl->minimumPageScaleFactor(), WebPo int(0, 0));
1462 simulateMultiTargetZoom(webViewImpl, topDiv, scale);
1463 EXPECT_FLOAT_EQ(1, scale);
1464 }
1465
1412 TEST_F(WebFrameTest, DivScrollIntoEditableTest) 1466 TEST_F(WebFrameTest, DivScrollIntoEditableTest)
1413 { 1467 {
1414 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); 1468 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html");
1415 1469
1416 int viewportWidth = 450; 1470 int viewportWidth = 450;
1417 int viewportHeight = 300; 1471 int viewportHeight = 300;
1418 float leftBoxRatio = 0.3f; 1472 float leftBoxRatio = 0.3f;
1419 int caretPadding = 10; 1473 int caretPadding = 10;
1420 float minReadableCaretHeight = 18.0f; 1474 float minReadableCaretHeight = 18.0f;
1421 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_zoom_into_editable_test.html"); 1475 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo r_zoom_into_editable_test.html");
1422 m_webView->enableFixedLayoutMode(true); 1476 m_webView->enableFixedLayoutMode(true);
1423 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 1477 m_webView->resize(WebSize(viewportWidth, viewportHeight));
1424 m_webView->setPageScaleFactorLimits(1, 4); 1478 m_webView->setPageScaleFactorLimits(1, 4);
1425 m_webView->layout(); 1479 m_webView->layout();
1426 m_webView->setDeviceScaleFactor(1.5f); 1480 m_webView->setDeviceScaleFactor(1.5f);
1427 m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true); 1481 m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true);
1428 1482
1429 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 1483 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
1430 webViewImpl->enableFakeDoubleTapAnimationForTesting(true); 1484 webViewImpl->enableFakePageScaleAnimationForTesting(true);
1431 1485
1432 WebRect editBoxWithText(200, 200, 250, 20); 1486 WebRect editBoxWithText(200, 200, 250, 20);
1433 WebRect editBoxWithNoText(200, 250, 250, 20); 1487 WebRect editBoxWithNoText(200, 250, 250, 20);
1434 1488
1435 // Test scrolling the focused node 1489 // Test scrolling the focused node
1436 // The edit box is shorter and narrower than the viewport when legible. 1490 // The edit box is shorter and narrower than the viewport when legible.
1437 m_webView->advanceFocus(false); 1491 m_webView->advanceFocus(false);
1438 // Set the caret to the end of the input box. 1492 // Set the caret to the end of the input box.
1439 m_webView->mainFrame()->document().getElementById("EditBoxWithText").to<WebI nputElement>().setSelectionRange(1000, 1000); 1493 m_webView->mainFrame()->document().getElementById("EditBoxWithText").to<WebI nputElement>().setSelectionRange(1000, 1000);
1440 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); 1494 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1);
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 EXPECT_EQ(image.size().width, 10); 3540 EXPECT_EQ(image.size().width, 10);
3487 EXPECT_EQ(image.size().height, 10); 3541 EXPECT_EQ(image.size().height, 10);
3488 // FIXME: The rest of this test is disabled since the ImageDecodeCache state may be inconsistent when this test runs. 3542 // FIXME: The rest of this test is disabled since the ImageDecodeCache state may be inconsistent when this test runs.
3489 // crbug.com/266088 3543 // crbug.com/266088
3490 // SkBitmap bitmap = image.getSkBitmap(); 3544 // SkBitmap bitmap = image.getSkBitmap();
3491 // SkAutoLockPixels locker(bitmap); 3545 // SkAutoLockPixels locker(bitmap);
3492 // EXPECT_EQ(bitmap.getColor(0, 0), SK_ColorBLUE); 3546 // EXPECT_EQ(bitmap.getColor(0, 0), SK_ColorBLUE);
3493 } 3547 }
3494 3548
3495 } // namespace 3549 } // namespace
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | public/web/WebView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698