| OLD | NEW |
| 1 #include "config.h" | 1 #include "config.h" |
| 2 | 2 |
| 3 #include <gtest/gtest.h> | 3 #include <gtest/gtest.h> |
| 4 #include "FrameTestHelpers.h" | 4 #include "FrameTestHelpers.h" |
| 5 #include "URLTestHelpers.h" | 5 #include "URLTestHelpers.h" |
| 6 #include "WebFrame.h" | 6 #include "WebFrame.h" |
| 7 #include "WebFrameClient.h" | 7 #include "WebFrameClient.h" |
| 8 #include "WebFrameImpl.h" | 8 #include "WebFrameImpl.h" |
| 9 #include "WebHistoryItem.h" | 9 #include "WebHistoryItem.h" |
| 10 #include "WebInputEvent.h" | 10 #include "WebInputEvent.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 { | 52 { |
| 53 registerMockedHttpURLLoad("long_scroll.html"); | 53 registerMockedHttpURLLoad("long_scroll.html"); |
| 54 | 54 |
| 55 FrameTestHelpers::WebViewHelper webViewHelper; | 55 FrameTestHelpers::WebViewHelper webViewHelper; |
| 56 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.
html", true, 0, 0); | 56 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.
html", true, 0, 0); |
| 57 webView->resize(WebSize(1000, 1000)); | 57 webView->resize(WebSize(1000, 1000)); |
| 58 webView->layout(); | 58 webView->layout(); |
| 59 | 59 |
| 60 WebViewImpl* webViewImpl = toWebViewImpl(webView); | 60 WebViewImpl* webViewImpl = toWebViewImpl(webView); |
| 61 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); | 61 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); |
| 62 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his
tory(); | 62 HistoryController* history = webViewImpl->page()->mainFrame()->loader().hist
ory(); |
| 63 | 63 |
| 64 // Scale and scroll the page and save that state. Then scale and scroll agai
n and restore. | 64 // Scale and scroll the page and save that state. Then scale and scroll agai
n and restore. |
| 65 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 200)); | 65 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 200)); |
| 66 history->saveDocumentAndScrollState(); | 66 history->saveDocumentAndScrollState(); |
| 67 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 300)); | 67 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 300)); |
| 68 // Flip back the wasScrolledByUser flag which was set to true by setPageScal
eFactor | 68 // Flip back the wasScrolledByUser flag which was set to true by setPageScal
eFactor |
| 69 // because otherwise HistoryController::restoreScrollPositionAndViewState do
es nothing. | 69 // because otherwise HistoryController::restoreScrollPositionAndViewState do
es nothing. |
| 70 frameView->setWasScrolledByUser(false); | 70 frameView->setWasScrolledByUser(false); |
| 71 history->restoreScrollPositionAndViewState(); | 71 history->restoreScrollPositionAndViewState(); |
| 72 | 72 |
| 73 // Expect that both scroll and scale were restored, and that it was not a pr
ogrammatic scroll. | 73 // Expect that both scroll and scale were restored, and that it was not a pr
ogrammatic scroll. |
| 74 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 74 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 75 EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height); | 75 EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height); |
| 76 EXPECT_TRUE(frameView->wasScrolledByUser()); | 76 EXPECT_TRUE(frameView->wasScrolledByUser()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) | 79 TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale) |
| 80 { | 80 { |
| 81 registerMockedHttpURLLoad("long_scroll.html"); | 81 registerMockedHttpURLLoad("long_scroll.html"); |
| 82 | 82 |
| 83 FrameTestHelpers::WebViewHelper webViewHelper; | 83 FrameTestHelpers::WebViewHelper webViewHelper; |
| 84 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.
html", true, 0, 0); | 84 WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.
html", true, 0, 0); |
| 85 webView->resize(WebSize(1000, 1000)); | 85 webView->resize(WebSize(1000, 1000)); |
| 86 webView->layout(); | 86 webView->layout(); |
| 87 | 87 |
| 88 WebViewImpl* webViewImpl = toWebViewImpl(webView); | 88 WebViewImpl* webViewImpl = toWebViewImpl(webView); |
| 89 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); | 89 FrameView* frameView = webViewImpl->mainFrameImpl()->frameView(); |
| 90 HistoryController* history = webViewImpl->page()->mainFrame()->loader()->his
tory(); | 90 HistoryController* history = webViewImpl->page()->mainFrame()->loader().hist
ory(); |
| 91 | 91 |
| 92 // Scale and scroll the page and save that state, but then set scale to zero
. Then scale and | 92 // Scale and scroll the page and save that state, but then set scale to zero
. Then scale and |
| 93 // scroll again and restore. | 93 // scroll again and restore. |
| 94 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 400)); | 94 webViewImpl->setPageScaleFactor(2.0f, WebPoint(0, 400)); |
| 95 history->saveDocumentAndScrollState(); | 95 history->saveDocumentAndScrollState(); |
| 96 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 500)); | 96 webViewImpl->setPageScaleFactor(3.0f, WebPoint(0, 500)); |
| 97 // Flip back the wasScrolledByUser flag which was set to true by setPageScal
eFactor | 97 // Flip back the wasScrolledByUser flag which was set to true by setPageScal
eFactor |
| 98 // because otherwise HistoryController::restoreScrollPositionAndViewState do
es nothing. | 98 // because otherwise HistoryController::restoreScrollPositionAndViewState do
es nothing. |
| 99 frameView->setWasScrolledByUser(false); | 99 frameView->setWasScrolledByUser(false); |
| 100 // HistoryController::restoreScrollPositionAndViewState flows differently if
scale is zero. | 100 // HistoryController::restoreScrollPositionAndViewState flows differently if
scale is zero. |
| 101 history->currentItem()->setPageScaleFactor(0.0f); | 101 history->currentItem()->setPageScaleFactor(0.0f); |
| 102 history->restoreScrollPositionAndViewState(); | 102 history->restoreScrollPositionAndViewState(); |
| 103 | 103 |
| 104 // Expect that only the scroll position was restored, and that it was not a
programmatic scroll. | 104 // Expect that only the scroll position was restored, and that it was not a
programmatic scroll. |
| 105 EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor()); | 105 EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor()); |
| 106 EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height); | 106 EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height); |
| 107 EXPECT_TRUE(frameView->wasScrolledByUser()); | 107 EXPECT_TRUE(frameView->wasScrolledByUser()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } | 110 } |
| OLD | NEW |