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

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

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 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/BrowserControls.h" 8 #include "core/frame/BrowserControls.h"
9 #include "core/frame/FrameHost.h" 9 #include "core/frame/FrameHost.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 EXPECT_SIZE_EQ(ScrollOffset(0, 0), 893 EXPECT_SIZE_EQ(ScrollOffset(0, 0),
894 toLocalFrame(webViewImpl()->page()->mainFrame()) 894 toLocalFrame(webViewImpl()->page()->mainFrame())
895 ->loader() 895 ->loader()
896 .currentItem() 896 .currentItem()
897 ->visualViewportScrollOffset()); 897 ->visualViewportScrollOffset());
898 898
899 VisualViewport& visualViewport = 899 VisualViewport& visualViewport =
900 frame()->page()->frameHost().visualViewport(); 900 frame()->page()->frameHost().visualViewport();
901 visualViewport.setScale(2); 901 visualViewport.setScale(2);
902 902
903 EXPECT_EQ(2, toLocalFrame(webViewImpl()->page()->mainFrame()) 903 EXPECT_EQ(2,
904 ->loader() 904 toLocalFrame(webViewImpl()->page()->mainFrame())
905 .currentItem() 905 ->loader()
906 ->pageScaleFactor()); 906 .currentItem()
907 ->pageScaleFactor());
907 908
908 visualViewport.setLocation(FloatPoint(10, 20)); 909 visualViewport.setLocation(FloatPoint(10, 20));
909 910
910 EXPECT_SIZE_EQ(ScrollOffset(10, 20), 911 EXPECT_SIZE_EQ(ScrollOffset(10, 20),
911 toLocalFrame(webViewImpl()->page()->mainFrame()) 912 toLocalFrame(webViewImpl()->page()->mainFrame())
912 ->loader() 913 ->loader()
913 .currentItem() 914 .currentItem()
914 ->visualViewportScrollOffset()); 915 ->visualViewportScrollOffset());
915 } 916 }
916 917
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 mouseDownEvent.globalY = 210; 1158 mouseDownEvent.globalY = 210;
1158 mouseDownEvent.clickCount = 1; 1159 mouseDownEvent.clickCount = 1;
1159 mouseDownEvent.button = WebMouseEvent::Button::Right; 1160 mouseDownEvent.button = WebMouseEvent::Button::Right;
1160 1161
1161 // Corresponding release event (Windows shows context menu on release). 1162 // Corresponding release event (Windows shows context menu on release).
1162 WebMouseEvent mouseUpEvent(mouseDownEvent); 1163 WebMouseEvent mouseUpEvent(mouseDownEvent);
1163 mouseUpEvent.setType(WebInputEvent::MouseUp); 1164 mouseUpEvent.setType(WebInputEvent::MouseUp);
1164 1165
1165 WebFrameClient* oldClient = webViewImpl()->mainFrameImpl()->client(); 1166 WebFrameClient* oldClient = webViewImpl()->mainFrameImpl()->client();
1166 MockWebFrameClient mockWebFrameClient; 1167 MockWebFrameClient mockWebFrameClient;
1167 EXPECT_CALL(mockWebFrameClient, showContextMenu(ContextMenuAtLocation( 1168 EXPECT_CALL(mockWebFrameClient,
1168 mouseDownEvent.x, mouseDownEvent.y))); 1169 showContextMenu(
1170 ContextMenuAtLocation(mouseDownEvent.x, mouseDownEvent.y)));
1169 1171
1170 // Do a sanity check with no scale applied. 1172 // Do a sanity check with no scale applied.
1171 webViewImpl()->mainFrameImpl()->setClient(&mockWebFrameClient); 1173 webViewImpl()->mainFrameImpl()->setClient(&mockWebFrameClient);
1172 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); 1174 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent));
1173 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); 1175 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseUpEvent));
1174 1176
1175 Mock::VerifyAndClearExpectations(&mockWebFrameClient); 1177 Mock::VerifyAndClearExpectations(&mockWebFrameClient);
1176 mouseDownEvent.button = WebMouseEvent::Button::Left; 1178 mouseDownEvent.button = WebMouseEvent::Button::Left;
1177 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); 1179 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent));
1178 1180
1179 // Now pinch zoom into the page and move the visual viewport. The context menu 1181 // Now pinch zoom into the page and move the visual viewport. The context menu
1180 // should still appear at the location of the event, relative to the WebView. 1182 // should still appear at the location of the event, relative to the WebView.
1181 VisualViewport& visualViewport = 1183 VisualViewport& visualViewport =
1182 frame()->page()->frameHost().visualViewport(); 1184 frame()->page()->frameHost().visualViewport();
1183 webViewImpl()->setPageScaleFactor(2); 1185 webViewImpl()->setPageScaleFactor(2);
1184 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_)); 1186 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_));
1185 visualViewport.setLocation(FloatPoint(60, 80)); 1187 visualViewport.setLocation(FloatPoint(60, 80));
1186 EXPECT_CALL(mockWebFrameClient, showContextMenu(ContextMenuAtLocation( 1188 EXPECT_CALL(mockWebFrameClient,
1187 mouseDownEvent.x, mouseDownEvent.y))); 1189 showContextMenu(
1190 ContextMenuAtLocation(mouseDownEvent.x, mouseDownEvent.y)));
1188 1191
1189 mouseDownEvent.button = WebMouseEvent::Button::Right; 1192 mouseDownEvent.button = WebMouseEvent::Button::Right;
1190 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); 1193 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseDownEvent));
1191 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); 1194 webViewImpl()->handleInputEvent(WebCoalescedInputEvent(mouseUpEvent));
1192 1195
1193 // Reset the old client so destruction can occur naturally. 1196 // Reset the old client so destruction can occur naturally.
1194 webViewImpl()->mainFrameImpl()->setClient(oldClient); 1197 webViewImpl()->mainFrameImpl()->setClient(oldClient);
1195 } 1198 }
1196 1199
1197 // Test that the client is notified if page scroll events. 1200 // Test that the client is notified if page scroll events.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 navigateTo(m_baseURL + "content-width-1000.html"); 1455 navigateTo(m_baseURL + "content-width-1000.html");
1453 1456
1454 VisualViewport& visualViewport = 1457 VisualViewport& visualViewport =
1455 frame()->page()->frameHost().visualViewport(); 1458 frame()->page()->frameHost().visualViewport();
1456 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); 1459 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView();
1457 1460
1458 visualViewport.setScale(pageScale); 1461 visualViewport.setScale(pageScale);
1459 EXPECT_SIZE_EQ( 1462 EXPECT_SIZE_EQ(
1460 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), 1463 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale),
1461 visualViewport.visibleRect().size()); 1464 visualViewport.visibleRect().size());
1462 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - 1465 EXPECT_SIZE_EQ(
1463 browserControlsHeight / minPageScale), 1466 IntSize(1000,
1464 frameView.frameRect().size()); 1467 layoutViewportHeight - browserControlsHeight / minPageScale),
1468 frameView.frameRect().size());
1465 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), 1469 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight),
1466 visualViewport.size()); 1470 visualViewport.size());
1467 1471
1468 // Scroll all the way to the bottom, hiding the browser controls in the 1472 // Scroll all the way to the bottom, hiding the browser controls in the
1469 // process. 1473 // process.
1470 visualViewport.move(ScrollOffset(10000, 10000)); 1474 visualViewport.move(ScrollOffset(10000, 10000));
1471 frameView.layoutViewportScrollableArea()->scrollBy(ScrollOffset(10000, 10000), 1475 frameView.layoutViewportScrollableArea()->scrollBy(ScrollOffset(10000, 10000),
1472 UserScroll); 1476 UserScroll);
1473 webViewImpl()->browserControls().setShownRatio(0); 1477 webViewImpl()->browserControls().setShownRatio(0);
1474 1478
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 webViewImpl()->browserControls().setShownRatio(1); 1545 webViewImpl()->browserControls().setShownRatio(1);
1542 visualViewport.move(ScrollOffset(10000, 10000)); 1546 visualViewport.move(ScrollOffset(10000, 10000));
1543 frameView.layoutViewportScrollableArea()->scrollBy(ScrollOffset(10000, 10000), 1547 frameView.layoutViewportScrollableArea()->scrollBy(ScrollOffset(10000, 10000),
1544 UserScroll); 1548 UserScroll);
1545 1549
1546 EXPECT_SIZE_EQ( 1550 EXPECT_SIZE_EQ(
1547 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), 1551 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale),
1548 visualViewport.visibleRect().size()); 1552 visualViewport.visibleRect().size());
1549 1553
1550 ScrollOffset frameViewExpected( 1554 ScrollOffset frameViewExpected(
1551 0, contentHeight - 1555 0,
1552 (layoutViewportHeight - browserControlsHeight / minPageScale)); 1556 contentHeight -
1557 (layoutViewportHeight - browserControlsHeight / minPageScale));
1553 ScrollOffset visualViewportExpected = ScrollOffset( 1558 ScrollOffset visualViewportExpected = ScrollOffset(
1554 750, (layoutViewportHeight - browserControlsHeight / minPageScale - 1559 750,
1555 visualViewport.visibleRect().height())); 1560 (layoutViewportHeight - browserControlsHeight / minPageScale -
1561 visualViewport.visibleRect().height()));
1556 1562
1557 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.getScrollOffset()); 1563 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.getScrollOffset());
1558 EXPECT_SIZE_EQ(frameViewExpected, 1564 EXPECT_SIZE_EQ(frameViewExpected,
1559 frameView.layoutViewportScrollableArea()->getScrollOffset()); 1565 frameView.layoutViewportScrollableArea()->getScrollOffset());
1560 1566
1561 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; 1567 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected;
1562 1568
1563 // Resize the widget to match the browser controls adjustment. Ensure that the 1569 // Resize the widget to match the browser controls adjustment. Ensure that the
1564 // total offset (i.e. what the user sees) doesn't change because of clamping 1570 // total offset (i.e. what the user sees) doesn't change because of clamping
1565 // the offsets to valid values. 1571 // the offsets to valid values.
1566 webViewImpl()->resizeWithBrowserControls( 1572 webViewImpl()->resizeWithBrowserControls(
1567 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true); 1573 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true);
1568 1574
1569 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), 1575 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight),
1570 visualViewport.size()); 1576 visualViewport.size());
1571 EXPECT_SIZE_EQ( 1577 EXPECT_SIZE_EQ(
1572 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), 1578 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale),
1573 visualViewport.visibleRect().size()); 1579 visualViewport.visibleRect().size());
1574 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - 1580 EXPECT_SIZE_EQ(
1575 browserControlsHeight / minPageScale), 1581 IntSize(1000,
1576 frameView.frameRect().size()); 1582 layoutViewportHeight - browserControlsHeight / minPageScale),
1583 frameView.frameRect().size());
1577 EXPECT_SIZE_EQ( 1584 EXPECT_SIZE_EQ(
1578 totalExpected, 1585 totalExpected,
1579 visualViewport.getScrollOffset() + 1586 visualViewport.getScrollOffset() +
1580 frameView.layoutViewportScrollableArea()->getScrollOffset()); 1587 frameView.layoutViewportScrollableArea()->getScrollOffset());
1581 } 1588 }
1582 1589
1583 // Tests that a resize due to browser controls hiding doesn't incorrectly clamp 1590 // Tests that a resize due to browser controls hiding doesn't incorrectly clamp
1584 // the main frame's scroll offset. crbug.com/428193. 1591 // the main frame's scroll offset. crbug.com/428193.
1585 TEST_P(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { 1592 TEST_P(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) {
1586 initializeWithAndroidSettings(); 1593 initializeWithAndroidSettings();
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 visualViewport.setScale(1); 1942 visualViewport.setScale(1);
1936 EXPECT_FLOAT_POINT_EQ( 1943 EXPECT_FLOAT_POINT_EQ(
1937 FloatPoint(314, 273), 1944 FloatPoint(314, 273),
1938 visualViewport.viewportToRootFrame(FloatPoint(314, 273))); 1945 visualViewport.viewportToRootFrame(FloatPoint(314, 273)));
1939 EXPECT_FLOAT_POINT_EQ( 1946 EXPECT_FLOAT_POINT_EQ(
1940 FloatPoint(314, 273), 1947 FloatPoint(314, 273),
1941 visualViewport.rootFrameToViewport(FloatPoint(314, 273))); 1948 visualViewport.rootFrameToViewport(FloatPoint(314, 273)));
1942 1949
1943 // At scale = 2. 1950 // At scale = 2.
1944 visualViewport.setScale(2); 1951 visualViewport.setScale(2);
1945 EXPECT_FLOAT_POINT_EQ(FloatPoint(55, 75), visualViewport.viewportToRootFrame( 1952 EXPECT_FLOAT_POINT_EQ(
1946 FloatPoint(110, 150))); 1953 FloatPoint(55, 75),
1954 visualViewport.viewportToRootFrame(FloatPoint(110, 150)));
1947 EXPECT_FLOAT_POINT_EQ(FloatPoint(110, 150), 1955 EXPECT_FLOAT_POINT_EQ(FloatPoint(110, 150),
1948 visualViewport.rootFrameToViewport(FloatPoint(55, 75))); 1956 visualViewport.rootFrameToViewport(FloatPoint(55, 75)));
1949 1957
1950 // At scale = 2 and with the visual viewport offset. 1958 // At scale = 2 and with the visual viewport offset.
1951 visualViewport.setLocation(FloatPoint(10, 12)); 1959 visualViewport.setLocation(FloatPoint(10, 12));
1952 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame( 1960 EXPECT_FLOAT_POINT_EQ(
1953 FloatPoint(80, 100))); 1961 FloatPoint(50, 62),
1962 visualViewport.viewportToRootFrame(FloatPoint(80, 100)));
1954 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), 1963 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100),
1955 visualViewport.rootFrameToViewport(FloatPoint(50, 62))); 1964 visualViewport.rootFrameToViewport(FloatPoint(50, 62)));
1956 1965
1957 // Test points that will cause non-integer values. 1966 // Test points that will cause non-integer values.
1958 EXPECT_FLOAT_POINT_EQ( 1967 EXPECT_FLOAT_POINT_EQ(
1959 FloatPoint(50.5, 62.4), 1968 FloatPoint(50.5, 62.4),
1960 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8))); 1969 visualViewport.viewportToRootFrame(FloatPoint(81, 100.8)));
1961 EXPECT_FLOAT_POINT_EQ( 1970 EXPECT_FLOAT_POINT_EQ(
1962 FloatPoint(81, 100.8), 1971 FloatPoint(81, 100.8),
1963 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4))); 1972 visualViewport.rootFrameToViewport(FloatPoint(50.5, 62.4)));
1964 1973
1965 // Scrolling the main frame should have no effect. 1974 // Scrolling the main frame should have no effect.
1966 frameView.layoutViewportScrollableArea()->setScrollOffset( 1975 frameView.layoutViewportScrollableArea()->setScrollOffset(
1967 ScrollOffset(100, 120), ProgrammaticScroll); 1976 ScrollOffset(100, 120), ProgrammaticScroll);
1968 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.viewportToRootFrame( 1977 EXPECT_FLOAT_POINT_EQ(
1969 FloatPoint(80, 100))); 1978 FloatPoint(50, 62),
1979 visualViewport.viewportToRootFrame(FloatPoint(80, 100)));
1970 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), 1980 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100),
1971 visualViewport.rootFrameToViewport(FloatPoint(50, 62))); 1981 visualViewport.rootFrameToViewport(FloatPoint(50, 62)));
1972 } 1982 }
1973 1983
1974 // Tests that the window dimensions are available before a full layout occurs. 1984 // Tests that the window dimensions are available before a full layout occurs.
1975 // More specifically, it checks that the innerWidth and innerHeight window 1985 // More specifically, it checks that the innerWidth and innerHeight window
1976 // properties will trigger a layout which will cause an update to viewport 1986 // properties will trigger a layout which will cause an update to viewport
1977 // constraints and a refreshed initial scale. crbug.com/466718 1987 // constraints and a refreshed initial scale. crbug.com/466718
1978 TEST_P(VisualViewportTest, WindowDimensionsOnLoad) { 1988 TEST_P(VisualViewportTest, WindowDimensionsOnLoad) {
1979 initializeWithAndroidSettings(); 1989 initializeWithAndroidSettings();
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 " body {" 2482 " body {"
2473 " margin: 0px;" 2483 " margin: 0px;"
2474 " }" 2484 " }"
2475 " div { height:110vh; width: 110vw; }" 2485 " div { height:110vh; width: 110vw; }"
2476 "</style>" 2486 "</style>"
2477 "<div></div>", 2487 "<div></div>",
2478 baseURL); 2488 baseURL);
2479 } 2489 }
2480 2490
2481 } // namespace 2491 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698