| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/BrowserControls.h" | 10 #include "core/frame/BrowserControls.h" |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // Test that the HistoryItem for the page stores the visual viewport's offset | 872 // Test that the HistoryItem for the page stores the visual viewport's offset |
| 873 // and scale. | 873 // and scale. |
| 874 TEST_P(VisualViewportTest, TestSavedToHistoryItem) { | 874 TEST_P(VisualViewportTest, TestSavedToHistoryItem) { |
| 875 InitializeWithDesktopSettings(); | 875 InitializeWithDesktopSettings(); |
| 876 WebViewImpl()->Resize(IntSize(200, 300)); | 876 WebViewImpl()->Resize(IntSize(200, 300)); |
| 877 WebViewImpl()->UpdateAllLifecyclePhases(); | 877 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 878 | 878 |
| 879 RegisterMockedHttpURLLoad("200-by-300.html"); | 879 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 880 NavigateTo(base_url_ + "200-by-300.html"); | 880 NavigateTo(base_url_ + "200-by-300.html"); |
| 881 | 881 |
| 882 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 882 EXPECT_EQ(nullptr, ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 883 ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) | 883 ->Loader() |
| 884 ->Loader() | 884 .GetDocumentLoader() |
| 885 .GetDocumentLoader() | 885 ->GetHistoryItem() |
| 886 ->GetHistoryItem() | 886 ->GetViewState()); |
| 887 ->VisualViewportScrollOffset()); | |
| 888 | 887 |
| 889 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); | 888 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 890 visual_viewport.SetScale(2); | 889 visual_viewport.SetScale(2); |
| 891 | 890 |
| 892 EXPECT_EQ(2, ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) | 891 EXPECT_EQ(2, ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 893 ->Loader() | 892 ->Loader() |
| 894 .GetDocumentLoader() | 893 .GetDocumentLoader() |
| 895 ->GetHistoryItem() | 894 ->GetHistoryItem() |
| 896 ->PageScaleFactor()); | 895 ->GetViewState() |
| 896 ->page_scale_factor_); |
| 897 | 897 |
| 898 visual_viewport.SetLocation(FloatPoint(10, 20)); | 898 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 899 | 899 |
| 900 EXPECT_SIZE_EQ(ScrollOffset(10, 20), | 900 EXPECT_SIZE_EQ(ScrollOffset(10, 20), |
| 901 ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) | 901 ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 902 ->Loader() | 902 ->Loader() |
| 903 .GetDocumentLoader() | 903 .GetDocumentLoader() |
| 904 ->GetHistoryItem() | 904 ->GetHistoryItem() |
| 905 ->VisualViewportScrollOffset()); | 905 ->GetViewState() |
| 906 ->visual_viewport_scroll_offset_); |
| 906 } | 907 } |
| 907 | 908 |
| 908 // Test restoring a HistoryItem properly restores the visual viewport's state. | 909 // Test restoring a HistoryItem properly restores the visual viewport's state. |
| 909 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { | 910 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { |
| 910 InitializeWithDesktopSettings(); | 911 InitializeWithDesktopSettings(); |
| 911 WebViewImpl()->Resize(IntSize(200, 300)); | 912 WebViewImpl()->Resize(IntSize(200, 300)); |
| 912 | 913 |
| 913 RegisterMockedHttpURLLoad("200-by-300.html"); | 914 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 914 | 915 |
| 915 WebHistoryItem item; | 916 WebHistoryItem item; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); | 984 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 984 visual_viewport.SetScale(2); | 985 visual_viewport.SetScale(2); |
| 985 visual_viewport.SetLocation(FloatPoint(350, 350)); | 986 visual_viewport.SetLocation(FloatPoint(350, 350)); |
| 986 | 987 |
| 987 Persistent<HistoryItem> firstItem = WebViewImpl() | 988 Persistent<HistoryItem> firstItem = WebViewImpl() |
| 988 ->MainFrameImpl() | 989 ->MainFrameImpl() |
| 989 ->GetFrame() | 990 ->GetFrame() |
| 990 ->Loader() | 991 ->Loader() |
| 991 .GetDocumentLoader() | 992 .GetDocumentLoader() |
| 992 ->GetHistoryItem(); | 993 ->GetHistoryItem(); |
| 993 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); | 994 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), |
| 995 firstItem->GetViewState()->scroll_offset_); |
| 994 | 996 |
| 995 // Now navigate to a page which causes a smaller frame_view. Make sure that | 997 // Now navigate to a page which causes a smaller frame_view. Make sure that |
| 996 // navigating doesn't cause the history item to set a new scroll offset | 998 // navigating doesn't cause the history item to set a new scroll offset |
| 997 // before the item was replaced. | 999 // before the item was replaced. |
| 998 NavigateTo("about:blank"); | 1000 NavigateTo("about:blank"); |
| 999 frame_view = WebViewImpl()->MainFrameImpl()->GetFrameView(); | 1001 frame_view = WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1000 | 1002 |
| 1001 EXPECT_NE(firstItem, WebViewImpl() | 1003 EXPECT_NE(firstItem, WebViewImpl() |
| 1002 ->MainFrameImpl() | 1004 ->MainFrameImpl() |
| 1003 ->GetFrame() | 1005 ->GetFrame() |
| 1004 ->Loader() | 1006 ->Loader() |
| 1005 .GetDocumentLoader() | 1007 .GetDocumentLoader() |
| 1006 ->GetHistoryItem()); | 1008 ->GetHistoryItem()); |
| 1007 EXPECT_LT(frame_view->FrameRect().Size().Width(), 1000); | 1009 EXPECT_LT(frame_view->FrameRect().Size().Width(), 1000); |
| 1008 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); | 1010 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), |
| 1011 firstItem->GetViewState()->scroll_offset_); |
| 1009 } | 1012 } |
| 1010 | 1013 |
| 1011 // Test that the coordinates sent into moveRangeSelection are offset by the | 1014 // Test that the coordinates sent into moveRangeSelection are offset by the |
| 1012 // visual viewport's location. | 1015 // visual viewport's location. |
| 1013 TEST_P(VisualViewportTest, | 1016 TEST_P(VisualViewportTest, |
| 1014 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { | 1017 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { |
| 1015 InitializeWithDesktopSettings(); | 1018 InitializeWithDesktopSettings(); |
| 1016 WebViewImpl()->GetSettings()->SetDefaultFontSize(12); | 1019 WebViewImpl()->GetSettings()->SetDefaultFontSize(12); |
| 1017 WebViewImpl()->Resize(WebSize(640, 480)); | 1020 WebViewImpl()->Resize(WebSize(640, 480)); |
| 1018 RegisterMockedHttpURLLoad("move_range.html"); | 1021 RegisterMockedHttpURLLoad("move_range.html"); |
| (...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 " margin: 0px;" | 2435 " margin: 0px;" |
| 2433 " }" | 2436 " }" |
| 2434 " div { height:110vh; width: 110vw; }" | 2437 " div { height:110vh; width: 110vw; }" |
| 2435 "</style>" | 2438 "</style>" |
| 2436 "<div></div>", | 2439 "<div></div>", |
| 2437 base_url); | 2440 base_url); |
| 2438 } | 2441 } |
| 2439 | 2442 |
| 2440 } // namespace | 2443 } // namespace |
| 2441 } // namespace blink | 2444 } // namespace blink |
| OLD | NEW |