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

Side by Side Diff: third_party/WebKit/Source/web/tests/VisualViewportTest.cpp

Issue 1712743002: Revert "Make window.scroll properties relative to the layout viewport by default." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix failing test Created 4 years, 10 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/VisualViewport.h" 5 #include "core/frame/VisualViewport.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/FrameHost.h" 8 #include "core/frame/FrameHost.h"
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 Mock::VerifyAndClearExpectations(&mockWebFrameClient); 1115 Mock::VerifyAndClearExpectations(&mockWebFrameClient);
1116 1116
1117 // Scroll horizontally. 1117 // Scroll horizontally.
1118 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_)); 1118 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_));
1119 visualViewport.setLocation(FloatPoint(70, 90)); 1119 visualViewport.setLocation(FloatPoint(70, 90));
1120 1120
1121 // Reset the old client so destruction can occur naturally. 1121 // Reset the old client so destruction can occur naturally.
1122 webViewImpl()->mainFrameImpl()->setClient(oldClient); 1122 webViewImpl()->mainFrameImpl()->setClient(oldClient);
1123 } 1123 }
1124 1124
1125 // Tests that calling scroll into view on a visible element doesn cause
1126 // a scroll due to a fractional offset. Bug crbug.com/463356.
1127 TEST_P(ParameterizedVisualViewportTest, ScrollIntoViewFractionalOffset)
1128 {
1129 initializeWithAndroidSettings();
1130
1131 webViewImpl()->resize(IntSize(1000, 1000));
1132
1133 registerMockedHttpURLLoad("scroll-into-view.html");
1134 navigateTo(m_baseURL + "scroll-into-view.html");
1135
1136 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1137 ScrollableArea* layoutViewportScrollableArea = frameView.layoutViewportScrol lableArea();
1138 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport ();
1139 Element* inputBox = frame()->document()->getElementById("box");
1140
1141 webViewImpl()->setPageScaleFactor(2);
1142
1143 // The element is already in the view so the scrollIntoView shouldn't move
1144 // the viewport at all.
1145 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f));
1146 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), Prog rammaticScroll);
1147 inputBox->scrollIntoViewIfNeeded(false);
1148
1149 EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scroll PositionDouble());
1150 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location());
1151
1152 // Change the fractional part of the frameview to one that would round down.
1153 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), Pro grammaticScroll);
1154 inputBox->scrollIntoViewIfNeeded(false);
1155
1156 EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrol lPositionDouble());
1157 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location());
1158
1159 // Repeat both tests above with the visual viewport at a high fractional.
1160 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f));
1161 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), Prog rammaticScroll);
1162 inputBox->scrollIntoViewIfNeeded(false);
1163
1164 EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scroll PositionDouble());
1165 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location());
1166
1167 // Change the fractional part of the frameview to one that would round down.
1168 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), Pro grammaticScroll);
1169 inputBox->scrollIntoViewIfNeeded(false);
1170
1171 EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrol lPositionDouble());
1172 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location());
1173
1174 // Both viewports with a 0.5 fraction.
1175 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f));
1176 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), Progr ammaticScroll);
1177 inputBox->scrollIntoViewIfNeeded(false);
1178
1179 EXPECT_POINT_EQ(DoublePoint(0, 900.5), layoutViewportScrollableArea->scrollP ositionDouble());
1180 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location());
1181 }
1182
1125 // Top controls can make an unscrollable page temporarily scrollable, causing 1183 // Top controls can make an unscrollable page temporarily scrollable, causing
1126 // a scroll clamp when the page is resized. Make sure this bug is fixed. 1184 // a scroll clamp when the page is resized. Make sure this bug is fixed.
1127 // crbug.com/437620 1185 // crbug.com/437620
1128 MAYBE_TEST_F(TestResizeDoesntChangeScrollOffset) 1186 MAYBE_TEST_F(TestResizeDoesntChangeScrollOffset)
1129 { 1187 {
1130 initializeWithAndroidSettings(); 1188 initializeWithAndroidSettings();
1131 webViewImpl()->resize(IntSize(980, 650)); 1189 webViewImpl()->resize(IntSize(980, 650));
1132 1190
1133 navigateTo("about:blank"); 1191 navigateTo("about:blank");
1134 1192
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 IntRect expectedBounds = bounds; 1469 IntRect expectedBounds = bounds;
1412 expectedBounds.scale(2.f); 1470 expectedBounds.scale(2.f);
1413 IntPoint expectedScrollDelta = scrollDelta; 1471 IntPoint expectedScrollDelta = scrollDelta;
1414 expectedScrollDelta.scale(2.f, 2.f); 1472 expectedScrollDelta.scale(2.f, 2.f);
1415 1473
1416 EXPECT_POINT_EQ(IntPoint(expectedBounds.location() - expectedScrollDelta), 1474 EXPECT_POINT_EQ(IntPoint(expectedBounds.location() - expectedScrollDelta),
1417 boundsInViewport.location()); 1475 boundsInViewport.location());
1418 EXPECT_SIZE_EQ(expectedBounds.size(), boundsInViewport.size()); 1476 EXPECT_SIZE_EQ(expectedBounds.size(), boundsInViewport.size());
1419 } 1477 }
1420 1478
1479 // Test that the various window.scroll and document.body.scroll properties and
1480 // methods work unchanged from the pre-virtual viewport mode.
1481 TEST_P(ParameterizedVisualViewportTest, bodyAndWindowScrollPropertiesAccountForV iewport)
1482 {
1483 initializeWithAndroidSettings();
1484
1485 webViewImpl()->resize(IntSize(200, 300));
1486
1487 // Load page with no main frame scrolling.
1488 registerMockedHttpURLLoad("200-by-300-viewport.html");
1489 navigateTo(m_baseURL + "200-by-300-viewport.html");
1490
1491 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport ();
1492 visualViewport.setScale(2);
1493
1494 // Chrome's quirky behavior regarding viewport scrolling means we treat the
1495 // body element as the viewport and don't apply scrolling to the HTML
1496 // element.
1497 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false);
1498
1499 LocalDOMWindow* window = webViewImpl()->mainFrameImpl()->frame()->localDOMWi ndow();
1500 window->scrollTo(100, 150);
1501 EXPECT_EQ(100, window->scrollX());
1502 EXPECT_EQ(150, window->scrollY());
1503 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location());
1504
1505 HTMLElement* body = toHTMLBodyElement(window->document()->body());
1506 body->setScrollLeft(50);
1507 body->setScrollTop(130);
1508 EXPECT_EQ(50, body->scrollLeft());
1509 EXPECT_EQ(130, body->scrollTop());
1510 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location());
1511
1512 HTMLElement* documentElement = toHTMLElement(window->document()->documentEle ment());
1513 documentElement->setScrollLeft(40);
1514 documentElement->setScrollTop(50);
1515 EXPECT_EQ(0, documentElement->scrollLeft());
1516 EXPECT_EQ(0, documentElement->scrollTop());
1517 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location());
1518
1519 visualViewport.setLocation(FloatPoint(10, 20));
1520 EXPECT_EQ(10, body->scrollLeft());
1521 EXPECT_EQ(20, body->scrollTop());
1522 EXPECT_EQ(0, documentElement->scrollLeft());
1523 EXPECT_EQ(0, documentElement->scrollTop());
1524 EXPECT_EQ(10, window->scrollX());
1525 EXPECT_EQ(20, window->scrollY());
1526
1527 // Turning on the standards-compliant viewport scrolling impl should make
1528 // the document element the viewport and not body.
1529 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true);
1530
1531 window->scrollTo(100, 150);
1532 EXPECT_EQ(100, window->scrollX());
1533 EXPECT_EQ(150, window->scrollY());
1534 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location());
1535
1536 body->setScrollLeft(50);
1537 body->setScrollTop(130);
1538 EXPECT_EQ(0, body->scrollLeft());
1539 EXPECT_EQ(0, body->scrollTop());
1540 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location());
1541
1542 documentElement->setScrollLeft(40);
1543 documentElement->setScrollTop(50);
1544 EXPECT_EQ(40, documentElement->scrollLeft());
1545 EXPECT_EQ(50, documentElement->scrollTop());
1546 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 50), visualViewport.location());
1547
1548 visualViewport.setLocation(FloatPoint(10, 20));
1549 EXPECT_EQ(0, body->scrollLeft());
1550 EXPECT_EQ(0, body->scrollTop());
1551 EXPECT_EQ(10, documentElement->scrollLeft());
1552 EXPECT_EQ(20, documentElement->scrollTop());
1553 EXPECT_EQ(10, window->scrollX());
1554 EXPECT_EQ(20, window->scrollY());
1555 }
1556
1421 // Tests that when a new frame is created, it is created with the intended 1557 // Tests that when a new frame is created, it is created with the intended
1422 // size (i.e. viewport at minimum scale, 100x200 / 0.5). 1558 // size (i.e. viewport at minimum scale, 100x200 / 0.5).
1423 MAYBE_TEST_P(TestMainFrameInitializationSizing) 1559 MAYBE_TEST_P(TestMainFrameInitializationSizing)
1424 { 1560 {
1425 initializeWithAndroidSettings(); 1561 initializeWithAndroidSettings();
1426 1562
1427 webViewImpl()->resize(IntSize(100, 200)); 1563 webViewImpl()->resize(IntSize(100, 200));
1428 1564
1429 registerMockedHttpURLLoad("content-width-1000-min-scale.html"); 1565 registerMockedHttpURLLoad("content-width-1000-min-scale.html");
1430 navigateTo(m_baseURL + "content-width-1000-min-scale.html"); 1566 navigateTo(m_baseURL + "content-width-1000-min-scale.html");
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 webViewImpl()->handleInputEvent(pinchUpdate); 1751 webViewImpl()->handleInputEvent(pinchUpdate);
1616 1752
1617 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi ewport(); 1753 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi ewport();
1618 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1754 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1619 1755
1620 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); 1756 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location());
1621 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); 1757 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble());
1622 } 1758 }
1623 1759
1624 } // namespace 1760 } // namespace
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebSettingsImpl.cpp ('k') | third_party/WebKit/public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698